Skip to contentSkip to conversation

net: sched: act_ct: fix possible refcount leak in tcf_ct_init()

PATCH Applied Hangyu Hua 3 participants 3 messages Sep 23, 2022 – Oct 1, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH v2 1/1 net: sched: act_ct: fix possible refcount leak in tcf_ct_init()

nf_ct_put need to be called to put the refcount got by tcf_ct_fill_params to avoid possible refcount leak when tcf_ct_flow_table_get fails.

Fixes c34b961a2492 ("net/sched: act_ct: Create nf flow table per zone")

---

v2: use a new label to put the refcount.

 net/sched/act_ct.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/sched/act_ct.c +4 -1
index d55afb8d14be..5950974ae8f6 100644
@@ -1394,7 +1394,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
 
 	err = tcf_ct_flow_table_get(net, params);
 	if (err)
-		goto cleanup;
+		goto cleanup_params;
 
 	spin_lock_bh(&c->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
@@ -1409,6 +1409,9 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
 
 	return res;
 
+cleanup_params:
+	if (params->tmpl)
+		nf_ct_put(params->tmpl);
 cleanup:
 	if (goto_ch)
 		tcf_chain_put_by_act(goto_ch);
Signature · 1 line
2.34.1
#1 lore raw
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Fri, 23 Sep 2022 10:00:46 +0800 you wrote:

nf_ct_put need to be called to put the refcount got by tcf_ct_fill_params to avoid possible refcount leak when tcf_ct_flow_table_get fails.

Fixes c34b961a2492 ("net/sched: act_ct: Create nf flow table per zone")

---

[...]

Here is the summary with links:
- [net,v2] net: sched: act_ct: fix possible refcount leak in tcf_ct_init()

    https://git.kernel.org/netdev/net/c/6e23ec0ba92d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#2 lore raw
In reply to Hangyu Hua
Quoted 26 lines · Hangyu Hua

nf_ct_put need to be called to put the refcount got by tcf_ct_fill_params to avoid possible refcount leak when tcf_ct_flow_table_get fails.

Fixes c34b961a2492 ("net/sched: act_ct: Create nf flow table per zone")

---

v2: use a new label to put the refcount.

 net/sched/act_ct.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/sched/act_ct.c +1 -1
index d55afb8d14be..5950974ae8f6 100644
@@ -1394,7 +1394,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
 
 	err = tcf_ct_flow_table_get(net, params);
 	if (err)
-		goto cleanup;
+		goto cleanup_params;
 
 	spin_lock_bh(&c->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);

net/sched/act_ct.c static int tcf_ct_init(struct net *net, struct nlattr *nla, · line 1414

Quoted 6 lines
net/sched/act_ct.c +3 -0
@@ -1409,6 +1409,9 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
 
 	return res;
 
+cleanup_params:
+	if (params->tmpl)
+		nf_ct_put(params->tmpl);

Nit: this NULL check is unnecessary.

Thanks.