summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNogah Frankel <nogahf@mellanox.com>2017-12-04 06:31:11 -0500
committerDavid S. Miller <davem@davemloft.net>2017-12-05 14:37:13 -0500
commit8afa10cbe281b10371fee5a87ab266e48d71a7f9 (patch)
treef821390027974ff7b78d22df3862e181bea9d2ca
parent5c472203421ab4f928aa1ae9e1dbcfdd80324148 (diff)
net_sched: red: Avoid illegal values
Check the qmin & qmax values doesn't overflow for the given Wlog value. Check that qmin <= qmax. Fixes: a783474591f2 ("[PKT_SCHED]: Generic RED layer") Signed-off-by: Nogah Frankel <nogahf@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/red.h11
-rw-r--r--net/sched/sch_choke.c3
-rw-r--r--net/sched/sch_gred.c3
-rw-r--r--net/sched/sch_red.c2
-rw-r--r--net/sched/sch_sfq.c3
5 files changed, 22 insertions, 0 deletions
diff --git a/include/net/red.h b/include/net/red.h
index 5918f78d36a0..9665582c4687 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -168,6 +168,17 @@ static inline void red_set_vars(struct red_vars *v)
168 v->qcount = -1; 168 v->qcount = -1;
169} 169}
170 170
171static inline bool red_check_params(u32 qth_min, u32 qth_max, u8 Wlog)
172{
173 if (fls(qth_min) + Wlog > 32)
174 return false;
175 if (fls(qth_max) + Wlog > 32)
176 return false;
177 if (qth_max < qth_min)
178 return false;
179 return true;
180}
181
171static inline void red_set_parms(struct red_parms *p, 182static inline void red_set_parms(struct red_parms *p,
172 u32 qth_min, u32 qth_max, u8 Wlog, u8 Plog, 183 u32 qth_min, u32 qth_max, u8 Wlog, u8 Plog,
173 u8 Scell_log, u8 *stab, u32 max_P) 184 u8 Scell_log, u8 *stab, u32 max_P)
diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c
index b30a2c70bd48..531250fceb9e 100644
--- a/net/sched/sch_choke.c
+++ b/net/sched/sch_choke.c
@@ -369,6 +369,9 @@ static int choke_change(struct Qdisc *sch, struct nlattr *opt)
369 369
370 ctl = nla_data(tb[TCA_CHOKE_PARMS]); 370 ctl = nla_data(tb[TCA_CHOKE_PARMS]);
371 371
372 if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog))
373 return -EINVAL;
374
372 if (ctl->limit > CHOKE_MAX_QUEUE) 375 if (ctl->limit > CHOKE_MAX_QUEUE)
373 return -EINVAL; 376 return -EINVAL;
374 377
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 17c7130454bd..bc30f9186ac6 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -356,6 +356,9 @@ static inline int gred_change_vq(struct Qdisc *sch, int dp,
356 struct gred_sched *table = qdisc_priv(sch); 356 struct gred_sched *table = qdisc_priv(sch);
357 struct gred_sched_data *q = table->tab[dp]; 357 struct gred_sched_data *q = table->tab[dp];
358 358
359 if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog))
360 return -EINVAL;
361
359 if (!q) { 362 if (!q) {
360 table->tab[dp] = q = *prealloc; 363 table->tab[dp] = q = *prealloc;
361 *prealloc = NULL; 364 *prealloc = NULL;
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 7f8ea9e297c3..9d874e60e032 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -212,6 +212,8 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt)
212 max_P = tb[TCA_RED_MAX_P] ? nla_get_u32(tb[TCA_RED_MAX_P]) : 0; 212 max_P = tb[TCA_RED_MAX_P] ? nla_get_u32(tb[TCA_RED_MAX_P]) : 0;
213 213
214 ctl = nla_data(tb[TCA_RED_PARMS]); 214 ctl = nla_data(tb[TCA_RED_PARMS]);
215 if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog))
216 return -EINVAL;
215 217
216 if (ctl->limit > 0) { 218 if (ctl->limit > 0) {
217 child = fifo_create_dflt(sch, &bfifo_qdisc_ops, ctl->limit); 219 child = fifo_create_dflt(sch, &bfifo_qdisc_ops, ctl->limit);
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index 09c1203c1711..930e5bd26d3d 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -639,6 +639,9 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
639 if (ctl->divisor && 639 if (ctl->divisor &&
640 (!is_power_of_2(ctl->divisor) || ctl->divisor > 65536)) 640 (!is_power_of_2(ctl->divisor) || ctl->divisor > 65536))
641 return -EINVAL; 641 return -EINVAL;
642 if (ctl_v1 && !red_check_params(ctl_v1->qth_min, ctl_v1->qth_max,
643 ctl_v1->Wlog))
644 return -EINVAL;
642 if (ctl_v1 && ctl_v1->qth_min) { 645 if (ctl_v1 && ctl_v1->qth_min) {
643 p = kmalloc(sizeof(*p), GFP_KERNEL); 646 p = kmalloc(sizeof(*p), GFP_KERNEL);
644 if (!p) 647 if (!p)