Skip to content

Commit 3874549

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Allow set names of up to 255 chars
Same conversion as for table names, use NFT_NAME_MAXLEN as upper boundary as well. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent b7263e0 commit 3874549

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ void nft_unregister_set(struct nft_set_type *type);
396396
struct nft_set {
397397
struct list_head list;
398398
struct list_head bindings;
399-
char name[NFT_SET_MAXNAMELEN];
399+
char *name;
400400
u32 ktype;
401401
u32 dtype;
402402
u32 objtype;

include/uapi/linux/netfilter/nf_tables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define NFT_NAME_MAXLEN 256
55
#define NFT_TABLE_MAXNAMELEN NFT_NAME_MAXLEN
66
#define NFT_CHAIN_MAXNAMELEN NFT_NAME_MAXLEN
7-
#define NFT_SET_MAXNAMELEN 32
7+
#define NFT_SET_MAXNAMELEN NFT_NAME_MAXLEN
88
#define NFT_OBJ_MAXNAMELEN 32
99
#define NFT_USERDATA_MAXLEN 256
1010

net/netfilter/nf_tables_api.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
26502650
unsigned long *inuse;
26512651
unsigned int n = 0, min = 0;
26522652

2653-
p = strnchr(name, NFT_SET_MAXNAMELEN, '%');
2653+
p = strchr(name, '%');
26542654
if (p != NULL) {
26552655
if (p[1] != 'd' || strchr(p + 2, '%'))
26562656
return -EINVAL;
@@ -2681,7 +2681,10 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
26812681
free_page((unsigned long)inuse);
26822682
}
26832683

2684-
snprintf(set->name, sizeof(set->name), name, min + n);
2684+
set->name = kasprintf(GFP_KERNEL, name, min + n);
2685+
if (!set->name)
2686+
return -ENOMEM;
2687+
26852688
list_for_each_entry(i, &ctx->table->sets, list) {
26862689
if (!nft_is_active_next(ctx->net, i))
26872690
continue;
@@ -2958,7 +2961,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
29582961
struct nft_table *table;
29592962
struct nft_set *set;
29602963
struct nft_ctx ctx;
2961-
char name[NFT_SET_MAXNAMELEN];
2964+
char *name;
29622965
unsigned int size;
29632966
bool create;
29642967
u64 timeout;
@@ -3104,8 +3107,14 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
31043107
goto err1;
31053108
}
31063109

3107-
nla_strlcpy(name, nla[NFTA_SET_NAME], sizeof(set->name));
3110+
name = nla_strdup(nla[NFTA_SET_NAME], GFP_KERNEL);
3111+
if (!name) {
3112+
err = -ENOMEM;
3113+
goto err2;
3114+
}
3115+
31083116
err = nf_tables_set_alloc_name(&ctx, set, name);
3117+
kfree(name);
31093118
if (err < 0)
31103119
goto err2;
31113120

@@ -3155,6 +3164,7 @@ static void nft_set_destroy(struct nft_set *set)
31553164
{
31563165
set->ops->destroy(set);
31573166
module_put(set->ops->type->owner);
3167+
kfree(set->name);
31583168
kvfree(set);
31593169
}
31603170

0 commit comments

Comments
 (0)