Skip to content

Commit 087d38a

Browse files
Phil Suttergregkh
authored andcommitted
netfilter: nf_tables: Reject tables of unsupported family
commit f1082dd upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 437d889 commit 087d38a

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
@@ -893,6 +893,30 @@ static int nft_chain_hash_cmp(struct rhashtable_compare_arg *arg,
893893
return strcmp(chain->name, name);
894894
}
895895

896+
static bool nft_supported_family(u8 family)
897+
{
898+
return false
899+
#ifdef CONFIG_NF_TABLES_INET
900+
|| family == NFPROTO_INET
901+
#endif
902+
#ifdef CONFIG_NF_TABLES_IPV4
903+
|| family == NFPROTO_IPV4
904+
#endif
905+
#ifdef CONFIG_NF_TABLES_ARP
906+
|| family == NFPROTO_ARP
907+
#endif
908+
#ifdef CONFIG_NF_TABLES_NETDEV
909+
|| family == NFPROTO_NETDEV
910+
#endif
911+
#if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE)
912+
|| family == NFPROTO_BRIDGE
913+
#endif
914+
#ifdef CONFIG_NF_TABLES_IPV6
915+
|| family == NFPROTO_IPV6
916+
#endif
917+
;
918+
}
919+
896920
static int nf_tables_newtable(struct net *net, struct sock *nlsk,
897921
struct sk_buff *skb, const struct nlmsghdr *nlh,
898922
const struct nlattr * const nla[],
@@ -908,6 +932,9 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
908932
struct nft_ctx ctx;
909933
int err;
910934

935+
if (!nft_supported_family(family))
936+
return -EOPNOTSUPP;
937+
911938
lockdep_assert_held(&nft_net->commit_mutex);
912939
attr = nla[NFTA_TABLE_NAME];
913940
table = nft_table_lookup(net, attr, family, genmask);

0 commit comments

Comments
 (0)