netfilter: nf_tables: Kill name length restrictions
Subsystems (3)
Phil Sutter
reviewercover netfilter: nf_tables: Kill name length restrictions
The following series removes the hard-coded restriction on name length of tables, chains, sets and objects.
The first patch introduces nla_strdup() which aids in duplicating a string contained in a netlink attribute. It is used to replace the call to nla_strlcpy() when populating name fields.
I've tested the series manually by creating tables, chains, sets and counter objects with long names and automated by running the py and shell testsuites of nftables repo. Also, kmemleak did not find anything nftables related.
Phil Sutter (5):
networking: Introduce nla_strdup()
netfilter: nf_tables: Unlimit table name length
netfilter: nf_tables: Unlimit chain name length
netfilter: nf_tables: Unlimit set name length
netfilter: nf_tables: Unlimit object name length
include/net/netfilter/nf_tables.h | 10 +-- include/net/netlink.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 4 - lib/nlattr.c | 24 +++++ net/netfilter/nf_tables_api.c | 148 ++++++++++++++++++++----------- net/netfilter/nf_tables_trace.c | 10 ++- net/netfilter/nft_dynset.c | 3 +- net/netfilter/nft_lookup.c | 3 +- net/netfilter/nft_objref.c | 6 +- 9 files changed, 138 insertions(+), 71 deletions(-)
Signature · 1 line
2.13.1
Phil Sutter
reviewerPATCH 1/5 networking: Introduce nla_strdup()
This is similar to strdup() for netlink string attributes.
--- include/net/netlink.h | 1 + lib/nlattr.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+)
include/net/netlink.h +1 -0
@@ -247,6 +247,7 @@ int nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head,int nla_policy_len (const struct nla_policy *,int );struct nlattr *nla_find (const struct nlattr *head,int len,int attrtype);size_t nla_strlcpy (char *dst,const struct nlattr *nla,size_t dstsize); +char *nla_strdup (const struct nlattr *nla,gfp_t flags);int nla_memcpy (void *dest,const struct nlattr *src,int count);int nla_memcmp (const struct nlattr *nla,const void *data,size_t size);int nla_strcmp (const struct nlattr *nla,const char *str);
lib/nlattr.c +24 -0
@@ -272,6 +272,30 @@ size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)EXPORT_SYMBOL (nla_strlcpy);/** +* nla_strdup - Copy string attribute payload into a newly allocated buffer +* @nla: attribute to copy the string from +* @flags: the type of memory to allocate (see kmalloc). +* +* Returns a pointer to the allocated buffer or NULL on error. +*/ +char *nla_strdup (const struct nlattr *nla,gfp_t flags) +{ +size_t srclen =nla_len (nla); +char *src =nla_data (nla), *dst; + +if (srclen >0 && src[srclen -1 ] =='\0' ) + srclen--; + + dst =kmalloc (srclen +1 , flags); +if (dst !=NULL ) { +memcpy (dst, src, srclen); + dst[srclen] ='\0' ; + } +return dst; +} +EXPORT_SYMBOL (nla_strdup); + +/** * nla_memcpy - Copy a netlink attribute into another memory area * @dest: where to copy to memcpy * @src: netlink attribute to copy from
Signature · 1 line
2.13.1
Phil Sutter
reviewerPATCH 2/5 netfilter: nf_tables: Unlimit table name length
In reply to Phil Sutter--- include/net/netfilter/nf_tables.h | 2 +- include/uapi/linux/netfilter/nf_tables.h | 1 - net/netfilter/nf_tables_api.c | 67 ++++++++++++++++++++------------ net/netfilter/nf_tables_trace.c | 4 +- 4 files changed, 46 insertions(+), 28 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -957,7 +957,7 @@ struct nft_table {u32 use; u16 flags:14, genmask:2; -char name[NFT_TABLE_MAXNAMELEN ]; +char *name; };enum nft_af_flags {
include/uapi/linux/netfilter/nf_tables.h +0 -1
@@ -1,7 +1,6 @@#ifndef _LINUX_NF_TABLES_H#define _LINUX_NF_TABLES_H -#define NFT_TABLE_MAXNAMELEN 32#define NFT_CHAIN_MAXNAMELEN 32#define NFT_SET_MAXNAMELEN 32#define NFT_OBJ_MAXNAMELEN 32
net/netfilter/nf_tables_api.c +42 -25
166 lines not on this page · raw message
net/netfilter/nf_tables_trace.c +3 -1
@@ -175,7 +175,6 @@ void nft_trace_notify(struct nft_traceinfo *info)return ; size =nlmsg_total_size (sizeof (struct nfgenmsg )) + -nla_total_size (NFT_TABLE_MAXNAMELEN ) +nla_total_size (NFT_CHAIN_MAXNAMELEN ) +nla_total_size_64bit (sizeof (__be64)) +/* rule handle */ nla_total_size(sizeof(__be32)) + /* trace type */
@@ -194,6 +193,9 @@ void nft_trace_notify(struct nft_traceinfo *info)nla_total_size (sizeof (u32)) +/* nfproto */ nla_total_size (sizeof (u32));/* policy */ +if (info->chain) + size +=nla_total_size (strlen (info->chain->table->name)); + skb =nlmsg_new (size,GFP_ATOMIC );if (!skb)return ;
Signature · 1 line
2.13.1
Phil Sutter
reviewerPATCH 3/5 netfilter: nf_tables: Unlimit chain name length
In reply to Phil Sutter--- include/net/netfilter/nf_tables.h | 4 +-- include/uapi/linux/netfilter/nf_tables.h | 1 - net/netfilter/nf_tables_api.c | 43 +++++++++++++++++++++----------- net/netfilter/nf_tables_trace.c | 8 +++--- 4 files changed, 36 insertions(+), 20 deletions(-)
include/net/netfilter/nf_tables.h +2 -2
@@ -859,7 +859,7 @@ struct nft_chain {u16 level; u8 flags:6, genmask:2; -char name[NFT_CHAIN_MAXNAMELEN ]; +char *name; };enum nft_chain_type {
@@ -1272,7 +1272,7 @@ struct nft_trans_set {struct nft_trans_chain {bool update; -char name[NFT_CHAIN_MAXNAMELEN ]; +char *name;struct nft_stats __percpu *stats;u8 policy; };
include/uapi/linux/netfilter/nf_tables.h +0 -1
@@ -1,7 +1,6 @@#ifndef _LINUX_NF_TABLES_H#define _LINUX_NF_TABLES_H -#define NFT_CHAIN_MAXNAMELEN 32#define NFT_SET_MAXNAMELEN 32#define NFT_OBJ_MAXNAMELEN 32#define NFT_USERDATA_MAXLEN 256
net/netfilter/nf_tables_api.c +29 -14
105 lines not on this page · raw message
net/netfilter/nf_tables_trace.c +5 -3
@@ -175,12 +175,10 @@ void nft_trace_notify(struct nft_traceinfo *info)return ; size =nlmsg_total_size (sizeof (struct nfgenmsg )) + -nla_total_size (NFT_CHAIN_MAXNAMELEN ) +nla_total_size_64bit (sizeof (__be64)) +/* rule handle */ nla_total_size (sizeof (__be32)) +/* trace type */ nla_total_size (0 ) +/* VERDICT, nested */ nla_total_size (sizeof (u32)) +/* verdict code */ -nla_total_size (NFT_CHAIN_MAXNAMELEN ) +/* jump target */ nla_total_size (sizeof (u32)) +/* id */ nla_total_size (NFT_TRACETYPE_LL_HSIZE ) + nla_total_size(NFT_TRACETYPE_NETWORK_HSIZE) +
@@ -194,7 +192,11 @@ void nft_trace_notify(struct nft_traceinfo *info)nla_total_size (sizeof (u32));/* policy */ if (info->chain) - size +=nla_total_size (strlen (info->chain->table->name)); + size +=nla_total_size (strlen (info->chain->table->name)) + +nla_total_size (strlen (info->chain->name)); + +if (info->verdict->chain) + size +=nla_total_size (strlen (info->verdict->chain->name));/* jump target */ skb =nlmsg_new (size,GFP_ATOMIC );if (!skb)
Signature · 1 line
2.13.1
Phil Sutter
reviewerPATCH 4/5 netfilter: nf_tables: Unlimit set name length
In reply to Phil Sutter--- include/net/netfilter/nf_tables.h | 2 +- include/uapi/linux/netfilter/nf_tables.h | 1 - net/netfilter/nf_tables_api.c | 24 ++++++++++++++++-------- net/netfilter/nft_dynset.c | 3 +-- net/netfilter/nft_lookup.c | 3 +-- net/netfilter/nft_objref.c | 3 +-- 6 files changed, 20 insertions(+), 16 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -396,7 +396,7 @@ void nft_unregister_set(struct nft_set_type *type);struct nft_set {struct list_head list;struct list_head bindings; -char name[NFT_SET_MAXNAMELEN ]; +char *name;u32 ktype;u32 dtype;u32 objtype;
include/uapi/linux/netfilter/nf_tables.h +0 -1
@@ -1,7 +1,6 @@#ifndef _LINUX_NF_TABLES_H#define _LINUX_NF_TABLES_H -#define NFT_SET_MAXNAMELEN 32#define NFT_OBJ_MAXNAMELEN 32#define NFT_USERDATA_MAXLEN 256
net/netfilter/nf_tables_api.c +16 -8
@@ -2537,8 +2537,7 @@ nft_select_set_ops(const struct nft_ctx *ctx,static const struct nla_policy nft_set_policy[NFTA_SET_MAX +1 ] = { [NFTA_SET_TABLE ] = { .type =NLA_STRING }, - [NFTA_SET_NAME ] = { .type =NLA_STRING , - .len =NFT_SET_MAXNAMELEN -1 }, + [NFTA_SET_NAME ] = { .type =NLA_STRING }, [NFTA_SET_FLAGS ] = { .type =NLA_U32 }, [NFTA_SET_KEY_TYPE ] = { .type =NLA_U32 }, [NFTA_SET_KEY_LEN ] = { .type =NLA_U32 },
@@ -2649,7 +2648,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,unsigned long *inuse;unsigned int n =0 , min =0 ; - p =strnchr (name,NFT_SET_MAXNAMELEN ,'%' ); + p =strchr (name,'%' );if (p !=NULL ) {if (p[1 ] !='d' ||strchr (p +2 ,'%' ))return -EINVAL ;
@@ -2680,7 +2679,10 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,free_page ((unsigned long )inuse); } -snprintf (set->name,sizeof (set->name), name, min + n); + set->name =kasprintf (GFP_KERNEL , name, min + n); +if (!set->name) +return -ENOMEM ; +list_for_each_entry (i, &ctx->table->sets, list) {if (!nft_is_active_next (ctx->net, i))continue ;
@@ -2957,7 +2959,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,struct nft_table *table;struct nft_set *set;struct nft_ctx ctx; -char name[NFT_SET_MAXNAMELEN ]; +char *name;unsigned int size;bool create;u64 timeout;
@@ -3103,8 +3105,14 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk, goto err1; } -nla_strlcpy (name, nla[NFTA_SET_NAME ],sizeof (set->name)); + name =nla_strdup (nla[NFTA_SET_NAME ],GFP_KERNEL ); +if (!name) { + err = -ENOMEM ; + goto err2; + } + err =nf_tables_set_alloc_name (&ctx, set, name); +kfree (name);if (err <0 ) goto err2;
@@ -3154,6 +3162,7 @@ static void nft_set_destroy(struct nft_set *set) { set->ops->destroy (set);module_put (set->ops->type->owner); +kfree (set->name);kvfree (set); }
@@ -3303,8 +3312,7 @@ static const struct nla_policy nft_set_elem_policy[NFTA_SET_ELEM_MAX + 1] = {static const struct nla_policy nft_set_elem_list_policy[NFTA_SET_ELEM_LIST_MAX +1 ] = { [NFTA_SET_ELEM_LIST_TABLE ] = { .type =NLA_STRING }, - [NFTA_SET_ELEM_LIST_SET ] = { .type =NLA_STRING , - .len =NFT_SET_MAXNAMELEN -1 }, + [NFTA_SET_ELEM_LIST_SET ] = { .type =NLA_STRING }, [NFTA_SET_ELEM_LIST_ELEMENTS ] = { .type =NLA_NESTED }, [NFTA_SET_ELEM_LIST_SET_ID ] = { .type =NLA_U32 }, };
net/netfilter/nft_dynset.c +1 -2
@@ -97,8 +97,7 @@ static void nft_dynset_eval(const struct nft_expr *expr, }static const struct nla_policy nft_dynset_policy[NFTA_DYNSET_MAX +1 ] = { - [NFTA_DYNSET_SET_NAME ] = { .type =NLA_STRING , - .len =NFT_SET_MAXNAMELEN -1 }, + [NFTA_DYNSET_SET_NAME ] = { .type =NLA_STRING }, [NFTA_DYNSET_SET_ID ] = { .type =NLA_U32 }, [NFTA_DYNSET_OP ] = { .type =NLA_U32 }, [NFTA_DYNSET_SREG_KEY ] = { .type =NLA_U32 },
net/netfilter/nft_lookup.c +1 -2
@@ -49,8 +49,7 @@ static void nft_lookup_eval(const struct nft_expr *expr, }static const struct nla_policy nft_lookup_policy[NFTA_LOOKUP_MAX +1 ] = { - [NFTA_LOOKUP_SET ] = { .type =NLA_STRING , - .len =NFT_SET_MAXNAMELEN -1 }, + [NFTA_LOOKUP_SET ] = { .type =NLA_STRING }, [NFTA_LOOKUP_SET_ID ] = { .type =NLA_U32 }, [NFTA_LOOKUP_SREG ] = { .type =NLA_U32 }, [NFTA_LOOKUP_DREG ] = { .type =NLA_U32 },
net/netfilter/nft_objref.c +1 -2
@@ -191,8 +191,7 @@ static const struct nla_policy nft_objref_policy[NFTA_OBJREF_MAX + 1] = { .len = NFT_OBJ_MAXNAMELEN - 1 }, [NFTA_OBJREF_IMM_TYPE] = { .type = NLA_U32 }, [NFTA_OBJREF_SET_SREG] = { .type = NLA_U32 }, - [NFTA_OBJREF_SET_NAME] = { .type = NLA_STRING, - .len = NFT_SET_MAXNAMELEN - 1 }, + [NFTA_OBJREF_SET_NAME] = { .type = NLA_STRING }, [NFTA_OBJREF_SET_ID] = { .type = NLA_U32 }, };
Signature · 1 line
2.13.1
Phil Sutter
reviewerPATCH 5/5 netfilter: nf_tables: Unlimit object name length
In reply to Phil Sutter--- include/net/netfilter/nf_tables.h | 2 +- include/uapi/linux/netfilter/nf_tables.h | 1 - net/netfilter/nf_tables_api.c | 14 ++++++++++---- net/netfilter/nft_objref.c | 3 +-- 4 files changed, 12 insertions(+), 8 deletions(-)
include/net/netfilter/nf_tables.h +1 -1
@@ -1016,7 +1016,7 @@ int nft_verdict_dump(struct sk_buff *skb, int type,*/ struct nft_object {struct list_head list; -char name[NFT_OBJ_MAXNAMELEN ]; +char *name;struct nft_table *table;u32 genmask:2 , use:30 ;
include/uapi/linux/netfilter/nf_tables.h +0 -1
@@ -1,7 +1,6 @@#ifndef _LINUX_NF_TABLES_H#define _LINUX_NF_TABLES_H -#define NFT_OBJ_MAXNAMELEN 32#define NFT_USERDATA_MAXLEN 256/**
net/netfilter/nf_tables_api.c +10 -4
@@ -4254,8 +4254,7 @@ EXPORT_SYMBOL_GPL(nf_tables_obj_lookup);static const struct nla_policy nft_obj_policy[NFTA_OBJ_MAX +1 ] = { [NFTA_OBJ_TABLE ] = { .type =NLA_STRING }, - [NFTA_OBJ_NAME ] = { .type =NLA_STRING , - .len =NFT_OBJ_MAXNAMELEN -1 }, + [NFTA_OBJ_NAME ] = { .type =NLA_STRING }, [NFTA_OBJ_TYPE ] = { .type =NLA_U32 }, [NFTA_OBJ_DATA ] = { .type =NLA_NESTED }, };
@@ -4397,15 +4396,21 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, goto err1; } obj->table = table; -nla_strlcpy (obj->name, nla[NFTA_OBJ_NAME ],NFT_OBJ_MAXNAMELEN ); + obj->name =nla_strdup (nla[NFTA_OBJ_NAME ],GFP_KERNEL ); +if (!obj->name) { + err = -ENOMEM ; + goto err2; + } err =nft_trans_obj_add (&ctx,NFT_MSG_NEWOBJ , obj);if (err <0 ) - goto err2; + goto err3;list_add_tail_rcu (&obj->list, &table->objects); table->use++;return 0 ; +err3: +kfree (obj->name); err2:if (obj->type->destroy) obj->type->destroy (obj);
@@ -4621,6 +4626,7 @@ static void nft_obj_destroy(struct nft_object *obj) obj->type->destroy (obj);module_put (obj->type->owner); +kfree (obj->name);kfree (obj); }
net/netfilter/nft_objref.c +1 -2
@@ -187,8 +187,7 @@ nft_objref_select_ops(const struct nft_ctx *ctx, }static const struct nla_policy nft_objref_policy[NFTA_OBJREF_MAX +1 ] = { - [NFTA_OBJREF_IMM_NAME ] = { .type =NLA_STRING , - .len =NFT_OBJ_MAXNAMELEN -1 }, + [NFTA_OBJREF_IMM_NAME ] = { .type =NLA_STRING }, [NFTA_OBJREF_IMM_TYPE ] = { .type =NLA_U32 }, [NFTA_OBJREF_SET_SREG ] = { .type =NLA_U32 }, [NFTA_OBJREF_SET_NAME ] = { .type =NLA_STRING },
Signature · 1 line
2.13.1
Pablo Neira Ayuso
maintainerHi Phil,
Quoted 11 lines · Phil Sutter
The following series removes the hard-coded restriction on name length of tables, chains, sets and objects.
The first patch introduces
nla_strdup()which aids in duplicating a string contained in a netlink attribute. It is used to replace the call tonla_strlcpy()when populating name fields.I've tested the series manually by creating tables, chains, sets and counter objects with long names and automated by running the py and shell testsuites of nftables repo. Also, kmemleak did not find anything nftables related.
I like this new dynamic name logic via nla_strdup().
I would like we still have a reasonable upper limit on string length. IIRC, Arturo mentioned he wants to use DNS names to identify sets, so we can just use 255 bytes as RFC 1035 indicates.
Thanks!
Phil Sutter
reviewer[nf-next PATCH 6/5] netfilter: nf_tables: Reintroduce name length boundary
In reply to Phil SutterSince all names in nftables are now dynamically allocated, choosing a large hard-coded length limit does not bloat nftables' footprint anymore.
Introduce a common upper limit on all names for sanity reasons - the chosen value of 255 characters allows to use a DNS name as per RFC 1035.
--- include/uapi/linux/netfilter/nf_tables.h | 1 + net/netfilter/nf_tables_api.c | 36 +++++++++++++++++++++----------- net/netfilter/nft_dynset.c | 3 ++- net/netfilter/nft_lookup.c | 3 ++- net/netfilter/nft_objref.c | 6 ++++-- 5 files changed, 33 insertions(+), 16 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +1 -0
@@ -1,6 +1,7 @@#ifndef _LINUX_NF_TABLES_H#define _LINUX_NF_TABLES_H +#define NFT_NAME_MAXLEN 256#define NFT_USERDATA_MAXLEN 256/**
net/netfilter/nf_tables_api.c +24 -12
@@ -427,7 +427,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi, }static const struct nla_policy nft_table_policy[NFTA_TABLE_MAX +1 ] = { - [NFTA_TABLE_NAME ] = { .type =NLA_STRING }, + [NFTA_TABLE_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_TABLE_FLAGS ] = { .type =NLA_U32 }, };
@@ -939,9 +940,11 @@ static struct nft_chain *nf_tables_chain_lookup(const struct nft_table *table, }static const struct nla_policy nft_chain_policy[NFTA_CHAIN_MAX +1 ] = { - [NFTA_CHAIN_TABLE ] = { .type =NLA_STRING }, + [NFTA_CHAIN_TABLE ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_CHAIN_HANDLE ] = { .type =NLA_U64 }, - [NFTA_CHAIN_NAME ] = { .type =NLA_STRING }, + [NFTA_CHAIN_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_CHAIN_HOOK ] = { .type =NLA_NESTED }, [NFTA_CHAIN_POLICY ] = { .type =NLA_U32 }, [NFTA_CHAIN_TYPE ] = { .type =NLA_STRING },
@@ -1886,8 +1889,10 @@ static struct nft_rule *nf_tables_rule_lookup(const struct nft_chain *chain, }static const struct nla_policy nft_rule_policy[NFTA_RULE_MAX +1 ] = { - [NFTA_RULE_TABLE ] = { .type =NLA_STRING }, - [NFTA_RULE_CHAIN ] = { .type =NLA_STRING }, + [NFTA_RULE_TABLE ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, + [NFTA_RULE_CHAIN ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_RULE_HANDLE ] = { .type =NLA_U64 }, [NFTA_RULE_EXPRESSIONS ] = { .type =NLA_NESTED }, [NFTA_RULE_COMPAT ] = { .type =NLA_NESTED },
@@ -2536,8 +2541,10 @@ nft_select_set_ops(const struct nft_ctx *ctx, }static const struct nla_policy nft_set_policy[NFTA_SET_MAX +1 ] = { - [NFTA_SET_TABLE ] = { .type =NLA_STRING }, - [NFTA_SET_NAME ] = { .type =NLA_STRING }, + [NFTA_SET_TABLE ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, + [NFTA_SET_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_SET_FLAGS ] = { .type =NLA_U32 }, [NFTA_SET_KEY_TYPE ] = { .type =NLA_U32 }, [NFTA_SET_KEY_LEN ] = { .type =NLA_U32 },
@@ -3311,8 +3318,10 @@ static const struct nla_policy nft_set_elem_policy[NFTA_SET_ELEM_MAX + 1] = { };static const struct nla_policy nft_set_elem_list_policy[NFTA_SET_ELEM_LIST_MAX +1 ] = { - [NFTA_SET_ELEM_LIST_TABLE ] = { .type =NLA_STRING }, - [NFTA_SET_ELEM_LIST_SET ] = { .type =NLA_STRING }, + [NFTA_SET_ELEM_LIST_TABLE ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, + [NFTA_SET_ELEM_LIST_SET ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_SET_ELEM_LIST_ELEMENTS ] = { .type =NLA_NESTED }, [NFTA_SET_ELEM_LIST_SET_ID ] = { .type =NLA_U32 }, };
@@ -4253,8 +4262,10 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,EXPORT_SYMBOL_GPL (nf_tables_obj_lookup);static const struct nla_policy nft_obj_policy[NFTA_OBJ_MAX +1 ] = { - [NFTA_OBJ_TABLE ] = { .type =NLA_STRING }, - [NFTA_OBJ_NAME ] = { .type =NLA_STRING }, + [NFTA_OBJ_TABLE ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, + [NFTA_OBJ_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_OBJ_TYPE ] = { .type =NLA_U32 }, [NFTA_OBJ_DATA ] = { .type =NLA_NESTED }, };
@@ -5487,7 +5498,8 @@ EXPORT_SYMBOL_GPL(nft_validate_register_store);static const struct nla_policy nft_verdict_policy[NFTA_VERDICT_MAX +1 ] = { [NFTA_VERDICT_CODE ] = { .type =NLA_U32 }, - [NFTA_VERDICT_CHAIN ] = { .type =NLA_STRING }, + [NFTA_VERDICT_CHAIN ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, }; static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
net/netfilter/nft_dynset.c +2 -1
@@ -97,7 +97,8 @@ static void nft_dynset_eval(const struct nft_expr *expr, }static const struct nla_policy nft_dynset_policy[NFTA_DYNSET_MAX +1 ] = { - [NFTA_DYNSET_SET_NAME ] = { .type =NLA_STRING }, + [NFTA_DYNSET_SET_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_DYNSET_SET_ID ] = { .type =NLA_U32 }, [NFTA_DYNSET_OP ] = { .type =NLA_U32 }, [NFTA_DYNSET_SREG_KEY ] = { .type =NLA_U32 },
net/netfilter/nft_lookup.c +2 -1
@@ -49,7 +49,8 @@ static void nft_lookup_eval(const struct nft_expr *expr, }static const struct nla_policy nft_lookup_policy[NFTA_LOOKUP_MAX +1 ] = { - [NFTA_LOOKUP_SET ] = { .type =NLA_STRING }, + [NFTA_LOOKUP_SET ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_LOOKUP_SET_ID ] = { .type =NLA_U32 }, [NFTA_LOOKUP_SREG ] = { .type =NLA_U32 }, [NFTA_LOOKUP_DREG ] = { .type =NLA_U32 },
net/netfilter/nft_objref.c +4 -2
@@ -187,10 +187,12 @@ nft_objref_select_ops(const struct nft_ctx *ctx, }static const struct nla_policy nft_objref_policy[NFTA_OBJREF_MAX +1 ] = { - [NFTA_OBJREF_IMM_NAME ] = { .type =NLA_STRING }, + [NFTA_OBJREF_IMM_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_OBJREF_IMM_TYPE ] = { .type =NLA_U32 }, [NFTA_OBJREF_SET_SREG ] = { .type =NLA_U32 }, - [NFTA_OBJREF_SET_NAME ] = { .type =NLA_STRING }, + [NFTA_OBJREF_SET_NAME ] = { .type =NLA_STRING , + .len =NFT_NAME_MAXLEN -1 }, [NFTA_OBJREF_SET_ID ] = { .type =NLA_U32 }, };
Signature · 1 line
2.13.1
Pablo Neira Ayuso
maintainerRe: [nf-next PATCH 6/5] netfilter: nf_tables: Reintroduce name length boundary
Quoted 6 lines · Phil Sutter
Since all names in nftables are now dynamically allocated, choosing a large hard-coded length limit does not bloat nftables' footprint anymore.
Introduce a common upper limit on all names for sanity reasons - the chosen value of 255 characters allows to use a DNS name as per RFC 1035.
Please, rebase your patcheset including this change and send me a v2.
Thanks!