All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
@ 2018-07-03 13:45 ` Wei Yongjun
  0 siblings, 0 replies; 6+ messages in thread
From: Wei Yongjun @ 2018-07-03 13:45 UTC (permalink / raw)
  To: Jamal Hadi Salim, Cong Wang, Jiri Pirko, Amir Vadai
  Cc: Wei Yongjun, netdev, kernel-janitors

'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: 71d0ed7079df ("net/act_pedit: Support using offset relative to the conventional network headers")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 net/sched/act_pedit.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 55bc96b..e43aef2 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -175,32 +175,35 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
 	if (!tcf_idr_check(tn, parm->index, a, bind)) {
 		if (!parm->nkeys) {
 			NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out_free;
 		}
 		ret = tcf_idr_create(tn, parm->index, est, a,
 				     &act_pedit_ops, bind, false);
 		if (ret)
-			return ret;
+			goto out_free;
 		p = to_pedit(*a);
 		keys = kmalloc(ksize, GFP_KERNEL);
 		if (!keys) {
 			tcf_idr_release(*a, bind);
-			kfree(keys_ex);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto out_free;
 		}
 		ret = ACT_P_CREATED;
 	} else {
 		if (bind)
-			return 0;
+			goto out_free;
 		tcf_idr_release(*a, bind);
-		if (!ovr)
-			return -EEXIST;
+		if (!ovr) {
+			ret = -EEXIST;
+			goto out_free;
+		}
 		p = to_pedit(*a);
 		if (p->tcfp_nkeys && p->tcfp_nkeys != parm->nkeys) {
 			keys = kmalloc(ksize, GFP_KERNEL);
 			if (!keys) {
-				kfree(keys_ex);
-				return -ENOMEM;
+				ret = -ENOMEM;
+				goto out_free;
 			}
 		}
 	}
@@ -222,6 +225,10 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
 	if (ret == ACT_P_CREATED)
 		tcf_idr_insert(tn, *a);
 	return ret;
+out_free:
+	kfree(keys_ex);
+	return ret;
+
 }
 
 static void tcf_pedit_cleanup(struct tc_action *a)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
@ 2018-07-03 13:45 ` Wei Yongjun
  0 siblings, 0 replies; 6+ messages in thread
From: Wei Yongjun @ 2018-07-03 13:45 UTC (permalink / raw)
  To: Jamal Hadi Salim, Cong Wang, Jiri Pirko, Amir Vadai
  Cc: Wei Yongjun, netdev, kernel-janitors

'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: 71d0ed7079df ("net/act_pedit: Support using offset relative to the conventional network headers")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 net/sched/act_pedit.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index 55bc96b..e43aef2 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -175,32 +175,35 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
 	if (!tcf_idr_check(tn, parm->index, a, bind)) {
 		if (!parm->nkeys) {
 			NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed");
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out_free;
 		}
 		ret = tcf_idr_create(tn, parm->index, est, a,
 				     &act_pedit_ops, bind, false);
 		if (ret)
-			return ret;
+			goto out_free;
 		p = to_pedit(*a);
 		keys = kmalloc(ksize, GFP_KERNEL);
 		if (!keys) {
 			tcf_idr_release(*a, bind);
-			kfree(keys_ex);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto out_free;
 		}
 		ret = ACT_P_CREATED;
 	} else {
 		if (bind)
-			return 0;
+			goto out_free;
 		tcf_idr_release(*a, bind);
-		if (!ovr)
-			return -EEXIST;
+		if (!ovr) {
+			ret = -EEXIST;
+			goto out_free;
+		}
 		p = to_pedit(*a);
 		if (p->tcfp_nkeys && p->tcfp_nkeys != parm->nkeys) {
 			keys = kmalloc(ksize, GFP_KERNEL);
 			if (!keys) {
-				kfree(keys_ex);
-				return -ENOMEM;
+				ret = -ENOMEM;
+				goto out_free;
 			}
 		}
 	}
@@ -222,6 +225,10 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
 	if (ret = ACT_P_CREATED)
 		tcf_idr_insert(tn, *a);
 	return ret;
+out_free:
+	kfree(keys_ex);
+	return ret;
+
 }
 
 static void tcf_pedit_cleanup(struct tc_action *a)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
  2018-07-03 13:45 ` Wei Yongjun
@ 2018-07-04  4:30   ` Cong Wang
  -1 siblings, 0 replies; 6+ messages in thread
From: Cong Wang @ 2018-07-04  4:30 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Jamal Hadi Salim, Jiri Pirko, Amir Vadai,
	Linux Kernel Network Developers, kernel-janitors

On Tue, Jul 3, 2018 at 6:36 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:
>
> '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: 71d0ed7079df ("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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
@ 2018-07-04  4:30   ` Cong Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Cong Wang @ 2018-07-04  4:30 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Jamal Hadi Salim, Jiri Pirko, Amir Vadai,
	Linux Kernel Network Developers, kernel-janitors

On Tue, Jul 3, 2018 at 6:36 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:
>
> '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: 71d0ed7079df ("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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
  2018-07-03 13:45 ` Wei Yongjun
@ 2018-07-04 13:09   ` David Miller
  -1 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-07-04 13:09 UTC (permalink / raw)
  To: weiyongjun1; +Cc: jhs, xiyou.wangcong, jiri, amir, netdev, kernel-janitors

From: Wei Yongjun <weiyongjun1@huawei.com>
Date: Tue, 3 Jul 2018 13:45:12 +0000

> '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: 71d0ed7079df ("net/act_pedit: Support using offset relative to the conventional network headers")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>

Applied.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init()
@ 2018-07-04 13:09   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-07-04 13:09 UTC (permalink / raw)
  To: weiyongjun1; +Cc: jhs, xiyou.wangcong, jiri, amir, netdev, kernel-janitors

From: Wei Yongjun <weiyongjun1@huawei.com>
Date: Tue, 3 Jul 2018 13:45:12 +0000

> '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: 71d0ed7079df ("net/act_pedit: Support using offset relative to the conventional network headers")
> Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>

Applied.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-07-04 13:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-03 13:45 [PATCH net-next] net: sched: act_pedit: fix possible memory leak in tcf_pedit_init() Wei Yongjun
2018-07-03 13:45 ` Wei Yongjun
2018-07-04  4:30 ` Cong Wang
2018-07-04  4:30   ` Cong Wang
2018-07-04 13:09 ` David Miller
2018-07-04 13:09   ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.