Skip to contentSkip to conversation

net_sched: fix a memory leak in atm_tc_init()

PATCH In review Cong Wang 2 participants 2 messages Jul 9, 2020

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: fix a memory leak in atm_tc_init()

When tcf_block_get() fails inside atm_tc_init(), atm_tc_put() is called to release the qdisc p->link.q. But the flow->ref prevents it to do so, as the flow->ref is still zero.

Fix this by moving the p->link.ref initialization before tcf_block_get().

Fixes 6529eaba33f0 ("net: sched: introduce tcf block infractructure")
Reported-and-tested-by [email protected]
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>
---
 net/sched/sch_atm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/sched/sch_atm.c +4 -4
index ee12ca9f55b4..1c281cc81f57 100644
@@ -553,16 +553,16 @@ static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt,
 	if (!p->link.q)
 		p->link.q = &noop_qdisc;
 	pr_debug("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
+	p->link.vcc = NULL;
+	p->link.sock = NULL;
+	p->link.common.classid = sch->handle;
+	p->link.ref = 1;
 
 	err = tcf_block_get(&p->link.block, &p->link.filter_list, sch,
 			    extack);
 	if (err)
 		return err;
 
-	p->link.vcc = NULL;
-	p->link.sock = NULL;
-	p->link.common.classid = sch->handle;
-	p->link.ref = 1;
 	tasklet_init(&p->task, sch_atm_dequeue, (unsigned long)sch);
 	return 0;
 }
Signature · 1 line
2.27.0
maintainer
#1 lore raw

From: Cong Wang <[email protected]>
Date: Wed, 8 Jul 2020 20:13:59 -0700

Quoted 5 lines

When tcf_block_get() fails inside atm_tc_init(), atm_tc_put() is called to release the qdisc p->link.q. But the flow->ref prevents it to do so, as the flow->ref is still zero.

Quoted 8 lines

Fix this by moving the p->link.ref initialization before tcf_block_get().

Fixes 6529eaba33f0 ("net: sched: introduce tcf block infractructure")
Reported-and-tested-by [email protected]
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>

Applied and queued up for -stable, thanks.