Skip to content

Commit 30e99ed

Browse files
Wei Yongjundavem330
authored andcommitted
net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
'keys_ex' is malloced by tcf_pedit_keys_ex_parse() in tcf_pedit_init() but not all of the error handle path free it, this may cause memory leak. This patch fix it. Fixes: 71d0ed7 ("net/act_pedit: Support using offset relative to the conventional network headers") Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Acked-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7184e7e commit 30e99ed

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

net/sched/act_pedit.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,35 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
175175
if (!tcf_idr_check(tn, parm->index, a, bind)) {
176176
if (!parm->nkeys) {
177177
NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed");
178-
return -EINVAL;
178+
ret = -EINVAL;
179+
goto out_free;
179180
}
180181
ret = tcf_idr_create(tn, parm->index, est, a,
181182
&act_pedit_ops, bind, false);
182183
if (ret)
183-
return ret;
184+
goto out_free;
184185
p = to_pedit(*a);
185186
keys = kmalloc(ksize, GFP_KERNEL);
186187
if (!keys) {
187188
tcf_idr_release(*a, bind);
188-
kfree(keys_ex);
189-
return -ENOMEM;
189+
ret = -ENOMEM;
190+
goto out_free;
190191
}
191192
ret = ACT_P_CREATED;
192193
} else {
193194
if (bind)
194-
return 0;
195+
goto out_free;
195196
tcf_idr_release(*a, bind);
196-
if (!ovr)
197-
return -EEXIST;
197+
if (!ovr) {
198+
ret = -EEXIST;
199+
goto out_free;
200+
}
198201
p = to_pedit(*a);
199202
if (p->tcfp_nkeys && p->tcfp_nkeys != parm->nkeys) {
200203
keys = kmalloc(ksize, GFP_KERNEL);
201204
if (!keys) {
202-
kfree(keys_ex);
203-
return -ENOMEM;
205+
ret = -ENOMEM;
206+
goto out_free;
204207
}
205208
}
206209
}
@@ -222,6 +225,10 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
222225
if (ret == ACT_P_CREATED)
223226
tcf_idr_insert(tn, *a);
224227
return ret;
228+
out_free:
229+
kfree(keys_ex);
230+
return ret;
231+
225232
}
226233

227234
static void tcf_pedit_cleanup(struct tc_action *a)

0 commit comments

Comments
 (0)