Skip to contentSkip to conversation

netfilter: nf_tables: mark set as dead when deactivating anonymous set

PATCH Superseded Pablo Neira Ayuso 2 participants 3 messages Mar 4, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: mark set as dead when deactivating anonymous set

While the rhashtable set gc runs asynchronously, a race allows it to collect elements from an anonymous set while it is being released from the abort path. This also seems possible from the rule error path.

Mingi Cho originally reported this issue in a different path in 6.1.x with a pipapo set with low timeouts which is not possible upstream since 7395dfacfff6 ("netfilter: nf_tables: use timestamp to check for set element timeout").

Fix this by setting on the dead flag to signal set gc to skip anonymous sets from prepare_error, abort and commit paths.

Fixes 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
---
 net/netfilter/nf_tables_api.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_tables_api.c +2 -0
index ca54d4c23123..26d33ce3b682 100644
@@ -5513,6 +5513,7 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
 			list_del_rcu(&binding->list);
 
 		nft_use_dec(&set->use);
+		set->dead = 1;
 		break;
 	case NFT_TRANS_PREPARE:
 		if (nft_set_is_anonymous(set)) {
@@ -5534,6 +5535,7 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
 	default:
 		nf_tables_unbind_set(ctx, set, binding,
 				     phase == NFT_TRANS_COMMIT);
+		set->dead = 1;
 	}
 }
 EXPORT_SYMBOL_GPL(nf_tables_deactivate_set);
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 11 lines · Pablo Neira Ayuso

While the rhashtable set gc runs asynchronously, a race allows it to collect elements from an anonymous set while it is being released from the abort path. This also seems possible from the rule error path.

Mingi Cho originally reported this issue in a different path in 6.1.x with a pipapo set with low timeouts which is not possible upstream since 7395dfacfff6 ("netfilter: nf_tables: use timestamp to check for set element timeout").

Fix this by setting on the dead flag to signal set gc to skip anonymous sets from prepare_error, abort and commit paths.

This seems to contradict what patch is doing, the flag gets toggled for all set types.

Quoted 21 lines
Fixes 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
---
 net/netfilter/nf_tables_api.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_tables_api.c +1 -0
index ca54d4c23123..26d33ce3b682 100644
@@ -5513,6 +5513,7 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
 			list_del_rcu(&binding->list);
 
 		nft_use_dec(&set->use);
+		set->dead = 1;
 		break;
 	case NFT_TRANS_PREPARE:
 		if (nft_set_is_anonymous(set)) {

net/netfilter/nf_tables_api.c void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set, · line 5538

Quoted 4 lines
net/netfilter/nf_tables_api.c +1 -0
@@ -5534,6 +5535,7 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
 	default:
 		nf_tables_unbind_set(ctx, set, binding,
 				     phase == NFT_TRANS_COMMIT);
+		set->dead = 1;

Shouldn't that be restricted to nf_tables_unbind_set() anonymous-set branch?

author maintainer
#2 lore raw
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Pablo Neira Ayuso

While the rhashtable set gc runs asynchronously, a race allows it to collect elements from an anonymous set while it is being released from the abort path. This also seems possible from the rule error path.

Mingi Cho originally reported this issue in a different path in 6.1.x with a pipapo set with low timeouts which is not possible upstream since 7395dfacfff6 ("netfilter: nf_tables: use timestamp to check for set element timeout").

Quoted 5 lines
Quoted 2 lines

Fix this by setting on the dead flag to signal set gc to skip anonymous sets from prepare_error, abort and commit paths.

This seems to contradict what patch is doing, the flag gets toggled for all set types.

Setting set->dead for non-anonymous sets break those that remain in place. This needs a v2.

Quoted 15 lines
Quoted 15 lines
Fixes 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
---
 net/netfilter/nf_tables_api.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/nf_tables_api.c +0 -0
index ca54d4c23123..26d33ce3b682 100644
@@ -5513,6 +5513,7 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
 			list_del_rcu(&binding->list);
 
Quoted 13 lines

net/netfilter/nf_tables_api.c void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set, · line 5538

Quoted 10 lines
net/netfilter/nf_tables_api.c +2 -0
 		nft_use_dec(&set->use);
+		set->dead = 1;
 		break;
 	case NFT_TRANS_PREPARE:
 		if (nft_set_is_anonymous(set)) {
@@ -5534,6 +5535,7 @@ void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set,
 	default:
 		nf_tables_unbind_set(ctx, set, binding,
 				     phase == NFT_TRANS_COMMIT);
+		set->dead = 1;

Shouldn't that be restricted to nf_tables_unbind_set() anonymous-set branch?

Right, thanks for reviewing.

Preparing v2.