Skip to content

Commit 842e238

Browse files
author
Xin Long
committed
net: sched: call tcf_ct_params_free to free params in tcf_ct_init
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2106859 Tested: compile only commit 1913894 Author: Xin Long <lucien.xin@gmail.com> Date: Sun Nov 6 15:34:16 2022 -0500 net: sched: call tcf_ct_params_free to free params in tcf_ct_init This patch is to make the err path simple by calling tcf_ct_params_free(), so that it won't cause problems when more members are added into param and need freeing on the err path. Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Xin Long <lxin@redhat.com>
1 parent 1391e06 commit 842e238

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

net/sched/act_ct.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,9 @@ static void tcf_ct_flow_table_cleanup_work(struct work_struct *work)
345345
module_put(THIS_MODULE);
346346
}
347347

348-
static void tcf_ct_flow_table_put(struct tcf_ct_params *params)
348+
static void tcf_ct_flow_table_put(struct tcf_ct_flow_table *ct_ft)
349349
{
350-
struct tcf_ct_flow_table *ct_ft = params->ct_ft;
351-
352-
if (refcount_dec_and_test(&params->ct_ft->ref)) {
350+
if (refcount_dec_and_test(&ct_ft->ref)) {
353351
rhashtable_remove_fast(&zones_ht, &ct_ft->node, zones_params);
354352
INIT_RCU_WORK(&ct_ft->rwork, tcf_ct_flow_table_cleanup_work);
355353
queue_rcu_work(act_ct_wq, &ct_ft->rwork);
@@ -836,18 +834,23 @@ static int tcf_ct_handle_fragments(struct net *net, struct sk_buff *skb,
836834
return err;
837835
}
838836

839-
static void tcf_ct_params_free(struct rcu_head *head)
837+
static void tcf_ct_params_free(struct tcf_ct_params *params)
840838
{
841-
struct tcf_ct_params *params = container_of(head,
842-
struct tcf_ct_params, rcu);
843-
844-
tcf_ct_flow_table_put(params);
845-
839+
if (params->ct_ft)
840+
tcf_ct_flow_table_put(params->ct_ft);
846841
if (params->tmpl)
847842
nf_ct_put(params->tmpl);
848843
kfree(params);
849844
}
850845

846+
static void tcf_ct_params_free_rcu(struct rcu_head *head)
847+
{
848+
struct tcf_ct_params *params;
849+
850+
params = container_of(head, struct tcf_ct_params, rcu);
851+
tcf_ct_params_free(params);
852+
}
853+
851854
#if IS_ENABLED(CONFIG_NF_NAT)
852855
/* Modelled after nf_nat_ipv[46]_fn().
853856
* range is only used for new, uninitialized NAT state.
@@ -1394,7 +1397,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
13941397

13951398
err = tcf_ct_flow_table_get(net, params);
13961399
if (err)
1397-
goto cleanup_params;
1400+
goto cleanup;
13981401

13991402
spin_lock_bh(&c->tcf_lock);
14001403
goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
@@ -1405,17 +1408,15 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
14051408
if (goto_ch)
14061409
tcf_chain_put_by_act(goto_ch);
14071410
if (params)
1408-
call_rcu(&params->rcu, tcf_ct_params_free);
1411+
call_rcu(&params->rcu, tcf_ct_params_free_rcu);
14091412

14101413
return res;
14111414

1412-
cleanup_params:
1413-
if (params->tmpl)
1414-
nf_ct_put(params->tmpl);
14151415
cleanup:
14161416
if (goto_ch)
14171417
tcf_chain_put_by_act(goto_ch);
1418-
kfree(params);
1418+
if (params)
1419+
tcf_ct_params_free(params);
14191420
tcf_idr_release(*a, bind);
14201421
return err;
14211422
}
@@ -1427,7 +1428,7 @@ static void tcf_ct_cleanup(struct tc_action *a)
14271428

14281429
params = rcu_dereference_protected(c->params, 1);
14291430
if (params)
1430-
call_rcu(&params->rcu, tcf_ct_params_free);
1431+
call_rcu(&params->rcu, tcf_ct_params_free_rcu);
14311432
}
14321433

14331434
static int tcf_ct_dump_key_val(struct sk_buff *skb,

0 commit comments

Comments
 (0)