Skip to contentSkip to conversation

netfilter: nf_tables: fix flow rule leak in nft_delrule() error path

PATCH In review Xingyuan Mo 3 participants 3 messages Oct 28 – Nov 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nf_tables: fix flow rule leak in nft_delrule() error path

On the nf_tables_delrule_deactivate() failure path, nft_trans_destroy() frees the transaction but not the attached HW offload flow rule. Destroy the flow after the transaction to avoid memory leak.

Fixes 63b48c73ff56 ("netfilter: nf_tables_offload: undo updates if transaction fails")
Assisted-by opencode:deepseek-v4
---
 net/netfilter/nf_tables_api.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +3 -1
index 59ac623e6805..ec56ea8c8436 100644
@@ -752,7 +752,7 @@ static struct nft_trans *nft_trans_rule_add(struct nft_ctx *ctx, int msg_type,
 
 static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
 {
-	struct nft_flow_rule *flow;
+	struct nft_flow_rule *flow = NULL;
 	struct nft_trans *trans;
 	int err;
 
@@ -773,6 +773,8 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
 	err = nf_tables_delrule_deactivate(ctx, rule);
 	if (err < 0) {
 		nft_trans_destroy(trans);
+		if (flow)
+			nft_flow_rule_destroy(flow);
 		return err;
 	}
 	nft_rule_expr_deactivate(ctx, rule, NFT_TRANS_PREPARE);
Signature · 1 line
2.43.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

#2 lore raw
In reply to Xingyuan Mo
Quoted 3 lines · Xingyuan Mo

On the nf_tables_delrule_deactivate() failure path, nft_trans_destroy() frees the transaction but not the attached HW offload flow rule. Destroy the flow after the transaction to avoid memory leak.

For the record, alternative proposed patch:

https://patch.msgid.link/netfilter-devel/[email protected]

Quoted 32 lines
Fixes 63b48c73ff56 ("netfilter: nf_tables_offload: undo updates if transaction fails")
Assisted-by opencode:deepseek-v4
---
 net/netfilter/nf_tables_api.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +3 -1
index 59ac623e6805..ec56ea8c8436 100644
@@ -752,7 +752,7 @@ static struct nft_trans *nft_trans_rule_add(struct nft_ctx *ctx, int msg_type,
 
 static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
 {
-	struct nft_flow_rule *flow;
+	struct nft_flow_rule *flow = NULL;
 	struct nft_trans *trans;
 	int err;
 
@@ -773,6 +773,8 @@ static int nft_delrule(struct nft_ctx *ctx, struct nft_rule *rule)
 	err = nf_tables_delrule_deactivate(ctx, rule);
 	if (err < 0) {
 		nft_trans_destroy(trans);
+		if (flow)
+			nft_flow_rule_destroy(flow);
 		return err;
 	}
 	nft_rule_expr_deactivate(ctx, rule, NFT_TRANS_PREPARE);
Signature · 1 line
2.43.0