Skip to content

Commit f3f0f95

Browse files
ummakynesgregkh
authored andcommitted
netfilter: nf_tables: report use refcount overflow
commit 1689f25 upstream. Overflow use refcount checks are not complete. Add helper function to deal with object reference counter tracking. Report -EMFILE in case UINT_MAX is reached. nft_use_dec() splats in case that reference counter underflows, which should not ever happen. Add nft_use_inc_restore() and nft_use_dec_restore() which are used to restore reference counter from error and abort paths. Use u32 in nft_flowtable and nft_object since helper functions cannot work on bitfields. Remove the few early incomplete checks now that the helper functions are in place and used to check for refcount overflow. Fixes: 9651851 ("netfilter: add nftables") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c21fddc commit f3f0f95

File tree

5 files changed

+141
-75
lines changed

5 files changed

+141
-75
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,29 @@ int __nft_release_basechain(struct nft_ctx *ctx);
11921192

11931193
unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
11941194

1195+
static inline bool nft_use_inc(u32 *use)
1196+
{
1197+
if (*use == UINT_MAX)
1198+
return false;
1199+
1200+
(*use)++;
1201+
1202+
return true;
1203+
}
1204+
1205+
static inline void nft_use_dec(u32 *use)
1206+
{
1207+
WARN_ON_ONCE((*use)-- == 0);
1208+
}
1209+
1210+
/* For error and abort path: restore use counter to previous state. */
1211+
static inline void nft_use_inc_restore(u32 *use)
1212+
{
1213+
WARN_ON_ONCE(!nft_use_inc(use));
1214+
}
1215+
1216+
#define nft_use_dec_restore nft_use_dec
1217+
11951218
/**
11961219
* struct nft_table - nf_tables table
11971220
*
@@ -1275,8 +1298,8 @@ struct nft_object {
12751298
struct list_head list;
12761299
struct rhlist_head rhlhead;
12771300
struct nft_object_hash_key key;
1278-
u32 genmask:2,
1279-
use:30;
1301+
u32 genmask:2;
1302+
u32 use;
12801303
u64 handle;
12811304
u16 udlen;
12821305
u8 *udata;
@@ -1378,8 +1401,8 @@ struct nft_flowtable {
13781401
char *name;
13791402
int hooknum;
13801403
int ops_len;
1381-
u32 genmask:2,
1382-
use:30;
1404+
u32 genmask:2;
1405+
u32 use;
13831406
u64 handle;
13841407
/* runtime data below here */
13851408
struct list_head hook_list ____cacheline_aligned;

0 commit comments

Comments
 (0)