Skip to contentSkip to conversation

net_sched: fix a resource leak in tcindex_set_parms()

PATCH In review Cong Wang 2 participants 2 messages Feb 4, 2020 – Feb 5, 2020

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: fix a resource leak in tcindex_set_parms()

Jakub noticed there is a potential resource leak in tcindex_set_parms(): when tcindex_filter_result_init() fails and it jumps to 'errout1' which doesn't release the memory and resources allocated by tcindex_alloc_perfect_hash().

We should just jump to 'errout_alloc' which calls
tcindex_free_perfect_hash().

Fixes b9a24bb76bf6 ("net_sched: properly handle failure case of tcf_exts_init()")
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>
---
 net/sched/cls_tcindex.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/sched/cls_tcindex.c +1 -2
index 0323aee03de7..09b7dc5fe7e0 100644
@@ -365,7 +365,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
 
 	err = tcindex_filter_result_init(&new_filter_result, net);
 	if (err < 0)
-		goto errout1;
+		goto errout_alloc;
 	if (old_r)
 		cr = r->res;
 
@@ -484,7 +484,6 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
 		tcindex_free_perfect_hash(cp);
 	else if (balloc == 2)
 		kfree(cp->h);
-errout1:
 	tcf_exts_destroy(&new_filter_result.exts);
 errout:
 	kfree(cp);
Signature · 1 line
2.21.1
maintainer
#1 lore raw

From: Cong Wang <[email protected]>
Date: Tue, 4 Feb 2020 11:10:12 -0800

Quoted 5 lines

Jakub noticed there is a potential resource leak in tcindex_set_parms(): when tcindex_filter_result_init() fails and it jumps to 'errout1' which doesn't release the memory and resources allocated by tcindex_alloc_perfect_hash().

Quoted 8 lines

We should just jump to 'errout_alloc' which calls
tcindex_free_perfect_hash().

Fixes b9a24bb76bf6 ("net_sched: properly handle failure case of tcf_exts_init()")
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>

Applied and queued up for -stable.