net:sched fix a bug about memery leak
Subsystems (3)
PATCH 1/1 net:sched fix a bug about memery leak
From: Jing Wang <[email protected]>
the code isn't properly release memory
--- net/sched/cls_route.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
net/sched/cls_route.c +6 -3
@@ -466,11 +466,11 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, goto reinsert; } - err = -ENOBUFS ; + err = -ENOMEM ;if (head ==NULL ) { head =kzalloc (sizeof (struct route4_head ),GFP_KERNEL );if (head ==NULL ) - goto errout; + goto errhead;tcf_tree_lock (tp); tp->root = head;
@@ -479,7 +479,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL );if (f ==NULL ) - goto errout; + goto errflt; err =route4_set_parms (net, tp, base, f, handle, head, tb, tca[TCA_RATE ],1 );
@@ -517,6 +517,9 @@ reinsert: errout:kfree (f); +errflt: +kfree (head); +errhead:return err; }
Signature · 1 line
1.7.1
Quoted 37 lines · Jing Wang
From: Jing Wang <[email protected]>
the code isn't properly release memory
Signed-off-by Jing Wang <[email protected]>--- net/sched/cls_route.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)net/sched/cls_route.c +3
-3@@ -466,11 +466,11 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, goto reinsert; } - err = -ENOBUFS ; + err = -ENOMEM ;if (head ==NULL ) { head =kzalloc (sizeof (struct route4_head ),GFP_KERNEL );if (head ==NULL ) - goto errout; + goto errhead;tcf_tree_lock (tp); tp->root = head;@@ -479,7 +479,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL );if (f ==NULL ) - goto errout; + goto errflt; err =route4_set_parms (net, tp, base, f, handle, head, tb, tca[TCA_RATE ],1 );
net/sched/cls_route.c reinsert: · line 525
Quoted 9 lines
net/sched/cls_route.c +3
-0@@ -517,6 +517,9 @@ reinsert: errout:kfree (f); +errflt: +kfree (head); +errhead:return err; }
I don't think this patch is needed or correct.
tp->root is the head, you cannot free it like that.
It will be freed properly in route4_destroy()
Please elaborate, thanks.
Quoted 50 lines · Eric Dumazet
Quoted 37 lines · Jing Wang
From: Jing Wang <[email protected]>
the code isn't properly release memory
Signed-off-by Jing Wang <[email protected]>--- net/sched/cls_route.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)net/sched/cls_route.c +3
-3@@ -466,11 +466,11 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, goto reinsert; } - err = -ENOBUFS ; + err = -ENOMEM ;if (head ==NULL ) { head =kzalloc (sizeof (struct route4_head ),GFP_KERNEL );if (head ==NULL ) - goto errout; + goto errhead;tcf_tree_lock (tp); tp->root = head;@@ -479,7 +479,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL );if (f ==NULL ) - goto errout; + goto errflt; err =route4_set_parms (net, tp, base, f, handle, head, tb, tca[TCA_RATE ],1 );net/sched/cls_route.c reinsert: · line 525
Quoted 9 lines
net/sched/cls_route.c +3
-0@@ -517,6 +517,9 @@ reinsert: errout:kfree (f); +errflt: +kfree (head); +errhead:return err; }I don't think this patch is needed or correct.
Quoted 5 lines
tp->rootis the head, you cannot free it like that.It will be freed properly in
route4_destroy()Please elaborate, thanks.
I think there is something else wrong in route4_change:
----
Quoted 1 line
From
1409402bf964bef79667755a5d0d5e0c2bd663f3Mon Sep 17 00:00:00 2001
From: Christoph Paasch <[email protected]>
Date: Thu, 24 Oct 2013 15:33:28 +0200
Subject: [PATCH net] net: sched: Don't free f before it is allocated in
route4_change
f is set to *arg in route4_change at the beginning, which points to a route4_filter in the hash-table (gotten through route4_get, called by tc_ctl_filter). If the alloc of head fails, we should not goto errout, because this will free f and thus freed memory will be referenced by the hash-table.
Only later the pointer f will change to an allocated route4_filter.
This patch returns err if the allocation of head fails as f has not yet been allocated inside route4_change.
Seems the code has been like this since Linus's original git-commit.
--- net/sched/cls_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/cls_route.c +1 -1
@@ -470,7 +470,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,if (head ==NULL ) { head =kzalloc (sizeof (struct route4_head ),GFP_KERNEL );if (head ==NULL ) - goto errout; +return err;tcf_tree_lock (tp); tp->root = head;
Signature · 1 line
1.8.3.2
Quoted 88 lines · Christoph Paasch
Quoted 50 lines · Eric Dumazet
Quoted 37 lines · Jing Wang
From: Jing Wang <[email protected]>
the code isn't properly release memory
Signed-off-by Jing Wang <[email protected]>--- net/sched/cls_route.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)net/sched/cls_route.c +3
-3@@ -466,11 +466,11 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, goto reinsert; } - err = -ENOBUFS ; + err = -ENOMEM ;if (head ==NULL ) { head =kzalloc (sizeof (struct route4_head ),GFP_KERNEL );if (head ==NULL ) - goto errout; + goto errhead;tcf_tree_lock (tp); tp->root = head;@@ -479,7 +479,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL );if (f ==NULL ) - goto errout; + goto errflt; err =route4_set_parms (net, tp, base, f, handle, head, tb, tca[TCA_RATE ],1 );net/sched/cls_route.c reinsert: · line 525
Quoted 9 lines
net/sched/cls_route.c +3
-0@@ -517,6 +517,9 @@ reinsert: errout:kfree (f); +errflt: +kfree (head); +errhead:return err; }I don't think this patch is needed or correct.
Quoted 5 lines
tp->rootis the head, you cannot free it like that.It will be freed properly in
route4_destroy()Please elaborate, thanks.
I think there is something else wrong in
route4_change:----
From1409402bf964bef79667755a5d0d5e0c2bd663f3Mon Sep 17 00:00:00 2001
From: Christoph Paasch <[email protected]>
Date: Thu, 24 Oct 2013 15:33:28 +0200
Subject: [PATCH net] net: sched: Don't free f before it is allocated in
route4_changef is set to *arg in
route4_changeat the beginning, which points to aroute4_filterin the hash-table (gotten throughroute4_get, called bytc_ctl_filter). If the alloc of head fails, we should not goto errout, because this will free f and thus freed memory will be referenced by the hash-table.
Only later the pointer f will change to an allocatedroute4_filter.This patch returns err if the allocation of head fails as f has not yet been allocated inside
route4_change.Seems the code has been like this since Linus's original git-commit.
Signed-off-by Christoph Paasch <[email protected]>--- net/sched/cls_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/sched/cls_route.c +0
-0
net/sched/cls_route.c static int route4_change(struct net *net, struct sk_buff *in_skb, · line 473
Quoted 5 lines
net/sched/cls_route.c +1
-1@@ -470,7 +470,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,if (head ==NULL ) { head =kzalloc (sizeof (struct route4_head ),GFP_KERNEL );if (head ==NULL ) - goto errout; +return err;
Oh... copy-paste from vim into mutt actually replaced the tabs by spaces...
I will resend. Sorry.
Christoph
Quoted 10 lines
net/sched/cls_route.c +0
-0tcf_tree_lock (tp); tp->root = head;Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello.
On 10/24/2013 01:12 PM, Jing Wang wrote:
s/mememry/memory/ in the subject.
Quoted 3 lines
From: Jing Wang <[email protected]>
the code isn't properly release memory
s/release/releasing/.
Quoted 1 line
Signed-off-by Jing Wang <[email protected]>
WBR, Sergei