|
| 1 | +netfilter: nf_tables: Reject tables of unsupported family |
| 2 | + |
| 3 | +jira LE-3201 |
| 4 | +cve CVE-2023-6040 |
| 5 | +Rebuild_History Non-Buildable kernel-rt-4.18.0-553.22.1.rt7.363.el8_10 |
| 6 | +commit-author Phil Sutter <phil@nwl.cc> |
| 7 | +commit f1082dd31fe461d482d69da2a8eccfeb7bf07ac2 |
| 8 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 9 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 10 | +ciq/ciq_backports/kernel-rt-4.18.0-553.22.1.rt7.363.el8_10/f1082dd3.failed |
| 11 | + |
| 12 | +An nftables family is merely a hollow container, its family just a |
| 13 | +number and such not reliant on compile-time options other than nftables |
| 14 | +support itself. Add an artificial check so attempts at using a family |
| 15 | +the kernel can't support fail as early as possible. This helps user |
| 16 | +space detect kernels which lack e.g. NFPROTO_INET. |
| 17 | + |
| 18 | + Signed-off-by: Phil Sutter <phil@nwl.cc> |
| 19 | + Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> |
| 20 | +(cherry picked from commit f1082dd31fe461d482d69da2a8eccfeb7bf07ac2) |
| 21 | + Signed-off-by: Jonathan Maple <jmaple@ciq.com> |
| 22 | + |
| 23 | +# Conflicts: |
| 24 | +# net/netfilter/nf_tables_api.c |
| 25 | +diff --cc net/netfilter/nf_tables_api.c |
| 26 | +index de9460cb3c8a,3168ad8cffd1..000000000000 |
| 27 | +--- a/net/netfilter/nf_tables_api.c |
| 28 | ++++ b/net/netfilter/nf_tables_api.c |
| 29 | +@@@ -1077,23 -1072,51 +1077,59 @@@ static int nft_objname_hash_cmp(struct |
| 30 | + return strcmp(obj->key.name, k->name); |
| 31 | + } |
| 32 | + |
| 33 | +++<<<<<<< HEAD |
| 34 | + +static int nf_tables_newtable(struct net *net, struct sock *nlsk, |
| 35 | + + struct sk_buff *skb, const struct nlmsghdr *nlh, |
| 36 | + + const struct nlattr * const nla[], |
| 37 | + + struct netlink_ext_ack *extack) |
| 38 | +++======= |
| 39 | ++ static bool nft_supported_family(u8 family) |
| 40 | ++ { |
| 41 | ++ return false |
| 42 | ++ #ifdef CONFIG_NF_TABLES_INET |
| 43 | ++ || family == NFPROTO_INET |
| 44 | ++ #endif |
| 45 | ++ #ifdef CONFIG_NF_TABLES_IPV4 |
| 46 | ++ || family == NFPROTO_IPV4 |
| 47 | ++ #endif |
| 48 | ++ #ifdef CONFIG_NF_TABLES_ARP |
| 49 | ++ || family == NFPROTO_ARP |
| 50 | ++ #endif |
| 51 | ++ #ifdef CONFIG_NF_TABLES_NETDEV |
| 52 | ++ || family == NFPROTO_NETDEV |
| 53 | ++ #endif |
| 54 | ++ #if IS_ENABLED(CONFIG_NF_TABLES_BRIDGE) |
| 55 | ++ || family == NFPROTO_BRIDGE |
| 56 | ++ #endif |
| 57 | ++ #ifdef CONFIG_NF_TABLES_IPV6 |
| 58 | ++ || family == NFPROTO_IPV6 |
| 59 | ++ #endif |
| 60 | ++ ; |
| 61 | ++ } |
| 62 | ++ |
| 63 | ++ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info, |
| 64 | ++ const struct nlattr * const nla[]) |
| 65 | +++>>>>>>> f1082dd31fe4 (netfilter: nf_tables: Reject tables of unsupported family) |
| 66 | + { |
| 67 | + - struct nftables_pernet *nft_net = nft_pernet(info->net); |
| 68 | + - struct netlink_ext_ack *extack = info->extack; |
| 69 | + - u8 genmask = nft_genmask_next(info->net); |
| 70 | + - u8 family = info->nfmsg->nfgen_family; |
| 71 | + - struct net *net = info->net; |
| 72 | + + const struct nfgenmsg *nfmsg = nlmsg_data(nlh); |
| 73 | + + u8 genmask = nft_genmask_next(net); |
| 74 | + + int family = nfmsg->nfgen_family; |
| 75 | + const struct nlattr *attr; |
| 76 | + struct nft_table *table; |
| 77 | + - struct nft_ctx ctx; |
| 78 | + u32 flags = 0; |
| 79 | + + struct nft_ctx ctx; |
| 80 | + int err; |
| 81 | + |
| 82 | +++<<<<<<< HEAD |
| 83 | + + lockdep_assert_held(&net->nft_commit_mutex); |
| 84 | +++======= |
| 85 | ++ if (!nft_supported_family(family)) |
| 86 | ++ return -EOPNOTSUPP; |
| 87 | ++ |
| 88 | ++ lockdep_assert_held(&nft_net->commit_mutex); |
| 89 | +++>>>>>>> f1082dd31fe4 (netfilter: nf_tables: Reject tables of unsupported family) |
| 90 | + attr = nla[NFTA_TABLE_NAME]; |
| 91 | + - table = nft_table_lookup(net, attr, family, genmask, |
| 92 | + - NETLINK_CB(skb).portid); |
| 93 | + + table = nft_table_lookup(net, attr, family, genmask); |
| 94 | + if (IS_ERR(table)) { |
| 95 | + if (PTR_ERR(table) != -ENOENT) |
| 96 | + return PTR_ERR(table); |
| 97 | +* Unmerged path net/netfilter/nf_tables_api.c |
0 commit comments