Skip to content

Commit 7f066cb

Browse files
GoodLuck612gregkh
authored andcommitted
netfilter: nf_tables: fix memory leak in nf_tables_newrule()
[ Upstream commit d077e81 ] In nf_tables_newrule(), if nft_use_inc() fails, the function jumps to the err_release_rule label without freeing the allocated flow, leading to a memory leak. Fix this by adding a new label err_destroy_flow and jumping to it when nft_use_inc() fails. This ensures that the flow is properly released in this error case. Fixes: 1689f25 ("netfilter: nf_tables: report use refcount overflow") Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 58dac9b commit 7f066cb

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

net/netfilter/nf_tables_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,7 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
43784378

43794379
if (!nft_use_inc(&chain->use)) {
43804380
err = -EMFILE;
4381-
goto err_release_rule;
4381+
goto err_destroy_flow;
43824382
}
43834383

43844384
if (info->nlh->nlmsg_flags & NLM_F_REPLACE) {
@@ -4428,6 +4428,7 @@ static int nf_tables_newrule(struct sk_buff *skb, const struct nfnl_info *info,
44284428

44294429
err_destroy_flow_rule:
44304430
nft_use_dec_restore(&chain->use);
4431+
err_destroy_flow:
44314432
if (flow)
44324433
nft_flow_rule_destroy(flow);
44334434
err_release_rule:

0 commit comments

Comments
 (0)