netfilter: nf_tables: Reject tables of unsupported family
Subsystems (2)
Phil Sutter
reviewerPATCH 1/1 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.
--- net/netfilter/nf_tables_api.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
net/netfilter/nf_tables_api.c +30 -0
@@ -1072,6 +1072,33 @@ static int nft_objname_hash_cmp(struct rhashtable_compare_arg *arg,return strcmp (obj->key.name, k->name); } +static bool nft_supported_family (int family) +{ +switch (family) { +#ifdef CONFIG_NF_TABLES_INET +case NFPROTO_INET : +#endif +#ifdef CONFIG_NF_TABLES_IPV4 +case NFPROTO_IPV4 : +#endif +#ifdef CONFIG_NF_TABLES_ARP +case NFPROTO_ARP : +#endif +#ifdef CONFIG_NF_TABLES_NETDEV +case NFPROTO_NETDEV : +#endif +#if IS_ENABLED (CONIFG_NF_TABLES_BRIDGE ) +case NFPROTO_BRIDGE : +#endif +#ifdef CONFIG_NF_TABLES_IPV6 +case NFPROTO_IPV6 : +#endif +return true; +default : +return false; + } +} +static int nf_tables_newtable (struct sk_buff *skb,const struct nfnl_info *info,const struct nlattr *const nla[]) {
@@ -1086,6 +1113,9 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,u32 flags =0 ;int err; +if (!nft_supported_family (family)) +return -EOPNOTSUPP ; +lockdep_assert_held (&nft_net->commit_mutex); attr = nla[NFTA_TABLE_NAME ]; table = nft_table_lookup(net, attr, family, genmask,
Signature · 1 line
2.34.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Phil,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on nf-next/master]
url: https://github.com/0day-ci/linux/commits/Phil-Sutter/netfilter-nf_tables-Reject-tables-of-unsupported-family/20220215-200808 base: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master config: i386-randconfig-a012 (https://download.01.org/0day-ci/archive/20220216/202202160311.x0sGfQ8f-lkp(a)intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/49585d5ef2f413b0bef6e50315e6b6c5bc85e475
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Phil-Sutter/netfilter-nf_tables-Reject-tables-of-unsupported-family/20220215-200808 git checkout 49585d5ef2f413b0bef6e50315e6b6c5bc85e475
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/netfilter/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
net/netfilter/nf_tables_api.c: In function 'nft_supported_family':
>> net/netfilter/nf_tables_api.c:1096:10: warning: statement will never be executed [-Wswitch-unreachable]
1096 | return true;
| ^~~~vim +1096 net/netfilter/nf_tables_api.c
1074
1075 static bool nft_supported_family(int family)
1076 {
1077 switch (family) {
1078 #ifdef CONFIG_NF_TABLES_INET
1079 case NFPROTO_INET:
1080 #endif
1081 #ifdef CONFIG_NF_TABLES_IPV4
1082 case NFPROTO_IPV4:
1083 #endif
1084 #ifdef CONFIG_NF_TABLES_ARP
1085 case NFPROTO_ARP:
1086 #endif
1087 #ifdef CONFIG_NF_TABLES_NETDEV
1088 case NFPROTO_NETDEV:
1089 #endif
1090 #if IS_ENABLED(CONIFG_NF_TABLES_BRIDGE)
1091 case NFPROTO_BRIDGE:
1092 #endif
1093 #ifdef CONFIG_NF_TABLES_IPV6
1094 case NFPROTO_IPV6:
1095 #endif
> 1096 return true;
1097 default:
1098 return false;
1099 }
1100 }
1101
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org