Skip to contentSkip to conversation

sch_tbf: Fix potential memory leak in tbf_change().

PATCH In review Hiroaki SHIMODA 3 participants 4 messages Feb 26, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sch_tbf: Fix potential memory leak in tbf_change().

The allocated child qdisc is not freed in error conditions. Defer the allocation after user configuration turns out to be valid and acceptable.

Fixes cc106e4 ("net: sched: tbf: fix the calculation of max_size")
Cc Yang Yingliang <[email protected]>
---
 net/sched/sch_tbf.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
net/sched/sch_tbf.c +12 -12
index 1cb413f..4f505a0 100644
@@ -334,18 +334,6 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
 			qdisc_put_rtab(qdisc_get_rtab(&qopt->peakrate,
 						      tb[TCA_TBF_PTAB]));
 
-	if (q->qdisc != &noop_qdisc) {
-		err = fifo_set_limit(q->qdisc, qopt->limit);
-		if (err)
-			goto done;
-	} else if (qopt->limit > 0) {
-		child = fifo_create_dflt(sch, &bfifo_qdisc_ops, qopt->limit);
-		if (IS_ERR(child)) {
-			err = PTR_ERR(child);
-			goto done;
-		}
-	}
-
 	buffer = min_t(u64, PSCHED_TICKS2NS(qopt->buffer), ~0U);
 	mtu = min_t(u64, PSCHED_TICKS2NS(qopt->mtu), ~0U);
 
@@ -390,6 +378,18 @@ static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
 		goto done;
 	}
 
+	if (q->qdisc != &noop_qdisc) {
+		err = fifo_set_limit(q->qdisc, qopt->limit);
+		if (err)
+			goto done;
+	} else if (qopt->limit > 0) {
+		child = fifo_create_dflt(sch, &bfifo_qdisc_ops, qopt->limit);
+		if (IS_ERR(child)) {
+			err = PTR_ERR(child);
+			goto done;
+		}
+	}
+
 	sch_tree_lock(sch);
 	if (child) {
 		qdisc_tree_decrease_qlen(q->qdisc, q->qdisc->q.qlen);
Signature · 1 line
1.8.3.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Hiroaki SHIMODA

The allocated child qdisc is not freed in error conditions. Defer the allocation after user configuration turns out to be valid and acceptable.

Fixes cc106e4 ("net: sched: tbf: fix the calculation of max_size")

Please prefer/use 12 digits : cc106e441a63b

You can put in your .git/config file :

[core]

	...
	abbrev = 12
	...
Quoted 3 lines

---

Thanks

maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Wed, 26 Feb 2014 07:29:44 -0800

Quoted 8 lines · Hiroaki SHIMODA
Quoted 5 lines

The allocated child qdisc is not freed in error conditions. Defer the allocation after user configuration turns out to be valid and acceptable.

Fixes cc106e4 ("net: sched: tbf: fix the calculation of max_size")

Please prefer/use 12 digits : cc106e441a63b

Applied with SHA1 adjustment, thanks.

#3 lore raw
In reply to Eric Dumazet
Quoted 7 lines · On Wed, 26 Feb 2014 07:29:44 -0800 Eric Dumazet <[email protected]> wrote:
Quoted 5 lines · Hiroaki SHIMODA

The allocated child qdisc is not freed in error conditions. Defer the allocation after user configuration turns out to be valid and acceptable.

Fixes cc106e4 ("net: sched: tbf: fix the calculation of max_size")
Quoted 8 lines

Please prefer/use 12 digits : cc106e441a63b

You can put in your .git/config file :

[core]

	...
	abbrev = 12
	...

Thank you for your kind suggestion.
I will use 12 digits next time.

Quoted 9 lines
Quoted 3 lines

---

Thanks