Skip to content

Commit 9332d27

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: remove WARN and add NLA_STRING upper limits
This WARN can trigger because some of the names fed to the module autoload function can be of arbitrary length. Remove the WARN and add limits for all NLA_STRING attributes. Reported-by: [email protected] Fixes: 452238e ("netfilter: nf_tables: add and use helper for module autoload") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 9ec22d7 commit 9332d27

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <net/net_namespace.h>
2323
#include <net/sock.h>
2424

25+
#define NFT_MODULE_AUTOLOAD_LIMIT (MODULE_NAME_LEN - sizeof("nft-expr-255-"))
26+
2527
static LIST_HEAD(nf_tables_expressions);
2628
static LIST_HEAD(nf_tables_objects);
2729
static LIST_HEAD(nf_tables_flowtables);
@@ -583,7 +585,7 @@ static void nft_request_module(struct net *net, const char *fmt, ...)
583585
va_start(args, fmt);
584586
ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
585587
va_end(args);
586-
if (WARN(ret >= MODULE_NAME_LEN, "truncated: '%s' (len %d)", module_name, ret))
588+
if (ret >= MODULE_NAME_LEN)
587589
return;
588590

589591
mutex_unlock(&net->nft.commit_mutex);
@@ -1242,7 +1244,8 @@ static const struct nla_policy nft_chain_policy[NFTA_CHAIN_MAX + 1] = {
12421244
.len = NFT_CHAIN_MAXNAMELEN - 1 },
12431245
[NFTA_CHAIN_HOOK] = { .type = NLA_NESTED },
12441246
[NFTA_CHAIN_POLICY] = { .type = NLA_U32 },
1245-
[NFTA_CHAIN_TYPE] = { .type = NLA_STRING },
1247+
[NFTA_CHAIN_TYPE] = { .type = NLA_STRING,
1248+
.len = NFT_MODULE_AUTOLOAD_LIMIT },
12461249
[NFTA_CHAIN_COUNTERS] = { .type = NLA_NESTED },
12471250
[NFTA_CHAIN_FLAGS] = { .type = NLA_U32 },
12481251
};
@@ -2356,7 +2359,8 @@ static const struct nft_expr_type *nft_expr_type_get(struct net *net,
23562359
}
23572360

23582361
static const struct nla_policy nft_expr_policy[NFTA_EXPR_MAX + 1] = {
2359-
[NFTA_EXPR_NAME] = { .type = NLA_STRING },
2362+
[NFTA_EXPR_NAME] = { .type = NLA_STRING,
2363+
.len = NFT_MODULE_AUTOLOAD_LIMIT },
23602364
[NFTA_EXPR_DATA] = { .type = NLA_NESTED },
23612365
};
23622366

@@ -4199,7 +4203,8 @@ static const struct nla_policy nft_set_elem_policy[NFTA_SET_ELEM_MAX + 1] = {
41994203
[NFTA_SET_ELEM_USERDATA] = { .type = NLA_BINARY,
42004204
.len = NFT_USERDATA_MAXLEN },
42014205
[NFTA_SET_ELEM_EXPR] = { .type = NLA_NESTED },
4202-
[NFTA_SET_ELEM_OBJREF] = { .type = NLA_STRING },
4206+
[NFTA_SET_ELEM_OBJREF] = { .type = NLA_STRING,
4207+
.len = NFT_OBJ_MAXNAMELEN - 1 },
42034208
};
42044209

42054210
static const struct nla_policy nft_set_elem_list_policy[NFTA_SET_ELEM_LIST_MAX + 1] = {

0 commit comments

Comments
 (0)