Skip to contentSkip to conversation

net: sched: lock imbalance in hhf qdisc

PATCH Superseded John Fastabend 2 participants 3 messages May 1, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: sched: lock imbalance in hhf qdisc

hhf_change() takes the sch_tree_lock and releases it but misses the error cases. Fix the missed case here.

---
 net/sched/sch_hhf.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/sch_hhf.c +3 -1
index edee03d..1803f89 100644
@@ -565,8 +565,10 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt)
 		new_hhf_non_hh_weight = nla_get_u32(tb[TCA_HHF_NON_HH_WEIGHT]);
 
 	non_hh_quantum = (u64)new_quantum * new_hhf_non_hh_weight;
-	if (non_hh_quantum > INT_MAX)
+	if (non_hh_quantum > INT_MAX) {
+		sch_tree_unlock(sch);
 		return -EINVAL;
+	}
 	q->quantum = new_quantum;
 	q->hhf_non_hh_weight = new_hhf_non_hh_weight;
 
#1 lore raw
Quoted 14 lines · John Fastabend

hhf_change() takes the sch_tree_lock and releases it but misses the error cases. Fix the missed case here.

---
 net/sched/sch_hhf.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/sch_hhf.c +0 -0
index edee03d..1803f89 100644
@@ -565,8 +565,10 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt)
 		new_hhf_non_hh_weight = nla_get_u32(tb[TCA_HHF_NON_HH_WEIGHT]);

net/sched/sch_hhf.c static int hhf_change(struct Qdisc *sch, struct nlattr *opt) · line 574

Quoted 10 lines
net/sched/sch_hhf.c +3 -1
 
 	non_hh_quantum = (u64)new_quantum * new_hhf_non_hh_weight;
-	if (non_hh_quantum > INT_MAX)
+	if (non_hh_quantum > INT_MAX) {
+		sch_tree_unlock(sch);
 		return -EINVAL;
+	}
 	q->quantum = new_quantum;
 	q->hhf_non_hh_weight = new_hhf_non_hh_weight;
 

Good catch, could you refactor a bit more to do all checks before any change ?

net/sched/sch_hhf.c +6 -5
index edee03d922e2..6e957c3b9854 100644
@@ -553,11 +553,6 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt)
 	if (err < 0)
 		return err;
 
-	sch_tree_lock(sch);
-
-	if (tb[TCA_HHF_BACKLOG_LIMIT])
-		sch->limit = nla_get_u32(tb[TCA_HHF_BACKLOG_LIMIT]);
-
 	if (tb[TCA_HHF_QUANTUM])
 		new_quantum = nla_get_u32(tb[TCA_HHF_QUANTUM]);
 
@@ -567,6 +562,12 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt)
 	non_hh_quantum = (u64)new_quantum * new_hhf_non_hh_weight;
 	if (non_hh_quantum > INT_MAX)
 		return -EINVAL;
+
+	sch_tree_lock(sch);
+
+	if (tb[TCA_HHF_BACKLOG_LIMIT])
+		sch->limit = nla_get_u32(tb[TCA_HHF_BACKLOG_LIMIT]);
+
 	q->quantum = new_quantum;
 	q->hhf_non_hh_weight = new_hhf_non_hh_weight;
 
#2 lore raw
Quoted 16 lines · Eric Dumazet
Quoted 15 lines · John Fastabend

hhf_change() takes the sch_tree_lock and releases it but misses the error cases. Fix the missed case here.

---
  net/sched/sch_hhf.c |    4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
net/sched/sch_hhf.c +0 -0
index edee03d..1803f89 100644
@@ -565,8 +565,10 @@ static int hhf_change(struct Qdisc *sch, struct nlattr *opt)
  		new_hhf_non_hh_weight = nla_get_u32(tb[TCA_HHF_NON_HH_WEIGHT]);
 
Quoted 12 lines

net/sched/sch_hhf.c static int hhf_change(struct Qdisc *sch, struct nlattr *opt) · line 573

Quoted 9 lines
net/sched/sch_hhf.c +3 -1
  	non_hh_quantum = (u64)new_quantum * new_hhf_non_hh_weight;
-	if (non_hh_quantum > INT_MAX)
+	if (non_hh_quantum > INT_MAX) {
+		sch_tree_unlock(sch);
  		return -EINVAL;
+	}
  	q->quantum = new_quantum;
  	q->hhf_non_hh_weight = new_hhf_non_hh_weight;
 

Good catch, could you refactor a bit more to do all checks before any change ?

Sure. What you have below looks good. I'll submit an official v2 patch.

Signature · 1 line
John Fastabend         Intel Corporation