]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
cdbeda5cb43075a84f8fe973542363be9f1de3c0
[thirdparty/kernel/stable-queue.git] /
1 From stable-owner@vger.kernel.org Wed Jul 5 18:55:57 2023
2 From: Pablo Neira Ayuso <pablo@netfilter.org>
3 Date: Wed, 5 Jul 2023 18:55:13 +0200
4 Subject: netfilter: nf_tables: add NFT_TRANS_PREPARE_ERROR to deal with bound set/chain
5 To: netfilter-devel@vger.kernel.org
6 Cc: sashal@kernel.org, gregkh@linuxfoundation.org, stable@vger.kernel.org
7 Message-ID: <20230705165516.50145-8-pablo@netfilter.org>
8
9 From: Pablo Neira Ayuso <pablo@netfilter.org>
10
11 [ 26b5a5712eb85e253724e56a54c17f8519bd8e4e ]
12
13 Add a new state to deal with rule expressions deactivation from the
14 newrule error path, otherwise the anonymous set remains in the list in
15 inactive state for the next generation. Mark the set/chain transaction
16 as unbound so the abort path releases this object, set it as inactive in
17 the next generation so it is not reachable anymore from this transaction
18 and reference counter is dropped.
19
20 Fixes: 1240eb93f061 ("netfilter: nf_tables: incorrect error path handling with NFT_MSG_NEWRULE")
21 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 ---
24 include/net/netfilter/nf_tables.h | 1 +
25 net/netfilter/nf_tables_api.c | 26 ++++++++++++++++++++++----
26 2 files changed, 23 insertions(+), 4 deletions(-)
27
28 --- a/include/net/netfilter/nf_tables.h
29 +++ b/include/net/netfilter/nf_tables.h
30 @@ -736,6 +736,7 @@ struct nft_expr_type {
31
32 enum nft_trans_phase {
33 NFT_TRANS_PREPARE,
34 + NFT_TRANS_PREPARE_ERROR,
35 NFT_TRANS_ABORT,
36 NFT_TRANS_COMMIT,
37 NFT_TRANS_RELEASE
38 --- a/net/netfilter/nf_tables_api.c
39 +++ b/net/netfilter/nf_tables_api.c
40 @@ -120,7 +120,8 @@ static void nft_trans_destroy(struct nft
41 kfree(trans);
42 }
43
44 -static void nft_set_trans_bind(const struct nft_ctx *ctx, struct nft_set *set)
45 +static void __nft_set_trans_bind(const struct nft_ctx *ctx, struct nft_set *set,
46 + bool bind)
47 {
48 struct nftables_pernet *nft_net;
49 struct net *net = ctx->net;
50 @@ -134,16 +135,26 @@ static void nft_set_trans_bind(const str
51 switch (trans->msg_type) {
52 case NFT_MSG_NEWSET:
53 if (nft_trans_set(trans) == set)
54 - nft_trans_set_bound(trans) = true;
55 + nft_trans_set_bound(trans) = bind;
56 break;
57 case NFT_MSG_NEWSETELEM:
58 if (nft_trans_elem_set(trans) == set)
59 - nft_trans_elem_set_bound(trans) = true;
60 + nft_trans_elem_set_bound(trans) = bind;
61 break;
62 }
63 }
64 }
65
66 +static void nft_set_trans_bind(const struct nft_ctx *ctx, struct nft_set *set)
67 +{
68 + return __nft_set_trans_bind(ctx, set, true);
69 +}
70 +
71 +static void nft_set_trans_unbind(const struct nft_ctx *ctx, struct nft_set *set)
72 +{
73 + return __nft_set_trans_bind(ctx, set, false);
74 +}
75 +
76 static void nft_trans_commit_list_add_tail(struct net *net, struct nft_trans *trans)
77 {
78 struct nftables_pernet *nft_net;
79 @@ -2784,7 +2795,7 @@ static int nf_tables_newrule(struct net
80
81 return 0;
82 err2:
83 - nft_rule_expr_deactivate(&ctx, rule, NFT_TRANS_PREPARE);
84 + nft_rule_expr_deactivate(&ctx, rule, NFT_TRANS_PREPARE_ERROR);
85 nf_tables_rule_destroy(&ctx, rule);
86 err1:
87 for (i = 0; i < n; i++) {
88 @@ -3809,6 +3820,13 @@ void nf_tables_deactivate_set(const stru
89 enum nft_trans_phase phase)
90 {
91 switch (phase) {
92 + case NFT_TRANS_PREPARE_ERROR:
93 + nft_set_trans_unbind(ctx, set);
94 + if (nft_set_is_anonymous(set))
95 + nft_deactivate_next(ctx->net, set);
96 +
97 + set->use--;
98 + break;
99 case NFT_TRANS_PREPARE:
100 if (nft_set_is_anonymous(set))
101 nft_deactivate_next(ctx->net, set);