Skip to content

Commit f1082dd

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nf_tables: Reject tables of unsupported family
An nftables family is merely a hollow container, its family just a number and such not reliant on compile-time options other than nftables support itself. Add an artificial check so attempts at using a family the kernel can't support fail as early as possible. This helps user space detect kernels which lack e.g. NFPROTO_INET. Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent bbfbf7a commit f1082dd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,30 @@ static int nft_objname_hash_cmp(struct rhashtable_compare_arg *arg,
10721072
return strcmp(obj->key.name, k->name);
10731073
}
10741074

1075+
static bool nft_supported_family(u8 family)
1076+
{
1077+
return false
1078+
#ifdef CONFIG_NF_TABLES_INET
1079+
|| family == NFPROTO_INET
1080+
#endif
1081+
#ifdef CONFIG_NF_TABLES_IPV4
1082+
|| family == NFPROTO_IPV4
1083+
#endif
1084+
#ifdef CONFIG_NF_TABLES_ARP
1085+
|| family == NFPROTO_ARP
1086+
#endif
1087+
#ifdef CONFIG_NF_TABLES_NETDEV
1088+
|| family == NFPROTO_NETDEV
1089+
#endif
1090+
#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE)
1091+
|| family == NFPROTO_BRIDGE
1092+
#endif
1093+
#ifdef CONFIG_NF_TABLES_IPV6
1094+
|| family == NFPROTO_IPV6
1095+
#endif
1096+
;
1097+
}
1098+
10751099
static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,
10761100
const struct nlattr * const nla[])
10771101
{
@@ -1086,6 +1110,9 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,
10861110
u32 flags = 0;
10871111
int err;
10881112

1113+
if (!nft_supported_family(family))
1114+
return -EOPNOTSUPP;
1115+
10891116
lockdep_assert_held(&nft_net->commit_mutex);
10901117
attr = nla[NFTA_TABLE_NAME];
10911118
table = nft_table_lookup(net, attr, family, genmask,

0 commit comments

Comments
 (0)