Skip to content

Commit b462579

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: restrict anonymous set and map names to 16 bytes
nftables has two types of sets/maps, one where userspace defines the name, and anonymous sets/maps, where userspace defines a template name. For the latter, kernel requires presence of exactly one "%d". nftables uses "__set%d" and "__map%d" for this. The kernel will expand the format specifier and replaces it with the smallest unused number. As-is, userspace could define a template name that allows to move the set name past the 256 bytes upperlimit (post-expansion). I don't see how this could be a problem, but I would prefer if userspace cannot do this, so add a limit of 16 bytes for the '%d' template name. 16 bytes is the old total upper limit for set names that existed when nf_tables was merged initially. Fixes: 3874549 ("netfilter: nf_tables: Allow set names of up to 255 chars") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent c9d9eb9 commit b462579

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <net/sock.h>
2525

2626
#define NFT_MODULE_AUTOLOAD_LIMIT (MODULE_NAME_LEN - sizeof("nft-expr-255-"))
27+
#define NFT_SET_MAX_ANONLEN 16
2728

2829
unsigned int nf_tables_net_id __read_mostly;
2930

@@ -4413,6 +4414,9 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
44134414
if (p[1] != 'd' || strchr(p + 2, '%'))
44144415
return -EINVAL;
44154416

4417+
if (strnlen(name, NFT_SET_MAX_ANONLEN) >= NFT_SET_MAX_ANONLEN)
4418+
return -EINVAL;
4419+
44164420
inuse = (unsigned long *)get_zeroed_page(GFP_KERNEL);
44174421
if (inuse == NULL)
44184422
return -ENOMEM;

0 commit comments

Comments
 (0)