]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/netfilter-nf_tables-reject-table-flag-and-netdev-bas.patch
Linux 6.1.85
[thirdparty/kernel/stable-queue.git] / queue-6.6 / netfilter-nf_tables-reject-table-flag-and-netdev-bas.patch
1 From 4f6a31316eafb9f7b010e2d2188ce0775fa8962e Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Thu, 21 Mar 2024 01:27:59 +0100
4 Subject: netfilter: nf_tables: reject table flag and netdev basechain updates
5
6 From: Pablo Neira Ayuso <pablo@netfilter.org>
7
8 [ Upstream commit 1e1fb6f00f52812277963365d9bd835b9b0ea4e0 ]
9
10 netdev basechain updates are stored in the transaction object hook list.
11 When setting on the table dormant flag, it iterates over the existing
12 hooks in the basechain. Thus, skipping the hooks that are being
13 added/deleted in this transaction, which leaves hook registration in
14 inconsistent state.
15
16 Reject table flag updates in combination with netdev basechain updates
17 in the same batch:
18
19 - Update table flags and add/delete basechain: Check from basechain update
20 path if there are pending flag updates for this table.
21 - add/delete basechain and update table flags: Iterate over the transaction
22 list to search for basechain updates from the table update path.
23
24 In both cases, the batch is rejected. Based on suggestion from Florian Westphal.
25
26 Fixes: b9703ed44ffb ("netfilter: nf_tables: support for adding new devices to an existing netdev chain")
27 Fixes: 7d937b107108f ("netfilter: nf_tables: support for deleting devices in an existing netdev chain")
28 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
29 Signed-off-by: Sasha Levin <sashal@kernel.org>
30 ---
31 net/netfilter/nf_tables_api.c | 31 ++++++++++++++++++++++++++++++-
32 1 file changed, 30 insertions(+), 1 deletion(-)
33
34 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
35 index 0653f1e5e8929..6e4e22a10a826 100644
36 --- a/net/netfilter/nf_tables_api.c
37 +++ b/net/netfilter/nf_tables_api.c
38 @@ -1200,6 +1200,25 @@ static void nf_tables_table_disable(struct net *net, struct nft_table *table)
39 #define __NFT_TABLE_F_UPDATE (__NFT_TABLE_F_WAS_DORMANT | \
40 __NFT_TABLE_F_WAS_AWAKEN)
41
42 +static bool nft_table_pending_update(const struct nft_ctx *ctx)
43 +{
44 + struct nftables_pernet *nft_net = nft_pernet(ctx->net);
45 + struct nft_trans *trans;
46 +
47 + if (ctx->table->flags & __NFT_TABLE_F_UPDATE)
48 + return true;
49 +
50 + list_for_each_entry(trans, &nft_net->commit_list, list) {
51 + if ((trans->msg_type == NFT_MSG_NEWCHAIN ||
52 + trans->msg_type == NFT_MSG_DELCHAIN) &&
53 + trans->ctx.table == ctx->table &&
54 + nft_trans_chain_update(trans))
55 + return true;
56 + }
57 +
58 + return false;
59 +}
60 +
61 static int nf_tables_updtable(struct nft_ctx *ctx)
62 {
63 struct nft_trans *trans;
64 @@ -1223,7 +1242,7 @@ static int nf_tables_updtable(struct nft_ctx *ctx)
65 return -EOPNOTSUPP;
66
67 /* No dormant off/on/off/on games in single transaction */
68 - if (ctx->table->flags & __NFT_TABLE_F_UPDATE)
69 + if (nft_table_pending_update(ctx))
70 return -EINVAL;
71
72 trans = nft_trans_alloc(ctx, NFT_MSG_NEWTABLE,
73 @@ -2621,6 +2640,13 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
74 }
75 }
76
77 + if (table->flags & __NFT_TABLE_F_UPDATE &&
78 + !list_empty(&hook.list)) {
79 + NL_SET_BAD_ATTR(extack, attr);
80 + err = -EOPNOTSUPP;
81 + goto err_hooks;
82 + }
83 +
84 if (!(table->flags & NFT_TABLE_F_DORMANT) &&
85 nft_is_base_chain(chain) &&
86 !list_empty(&hook.list)) {
87 @@ -2850,6 +2876,9 @@ static int nft_delchain_hook(struct nft_ctx *ctx,
88 struct nft_trans *trans;
89 int err;
90
91 + if (ctx->table->flags & __NFT_TABLE_F_UPDATE)
92 + return -EOPNOTSUPP;
93 +
94 err = nft_chain_parse_hook(ctx->net, basechain, nla, &chain_hook,
95 ctx->family, chain->flags, extack);
96 if (err < 0)
97 --
98 2.43.0
99