netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net 0/2] RED qdisc fixes
@ 2017-12-04 11:31 Nogah Frankel
  2017-12-04 11:31 ` [patch net 1/2] net_sched: red: Avoid devision by zero Nogah Frankel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nogah Frankel @ 2017-12-04 11:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, jhs, xiyou.wangcong, jiri, mlxsw, Nogah Frankel

Add some input validation checks to RED qdisc.

Nogah Frankel (2):
  net_sched: red: Avoid devision by zero
  net_sched: red: Avoid illegal values

 include/net/red.h     | 13 ++++++++++++-
 net/sched/sch_choke.c |  3 +++
 net/sched/sch_gred.c  |  3 +++
 net/sched/sch_red.c   |  2 ++
 net/sched/sch_sfq.c   |  3 +++
 5 files changed, 23 insertions(+), 1 deletion(-)

-- 
2.4.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [patch net 1/2] net_sched: red: Avoid devision by zero
  2017-12-04 11:31 [patch net 0/2] RED qdisc fixes Nogah Frankel
@ 2017-12-04 11:31 ` Nogah Frankel
  2017-12-04 11:31 ` [patch net 2/2] net_sched: red: Avoid illegal values Nogah Frankel
  2017-12-05 19:37 ` [patch net 0/2] RED qdisc fixes David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Nogah Frankel @ 2017-12-04 11:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, jhs, xiyou.wangcong, jiri, mlxsw, Nogah Frankel

Do not allow delta value to be zero since it is used as a divisor.

Fixes: 8af2a218de38 ("sch_red: Adaptative RED AQM")
Signed-off-by: Nogah Frankel <nogahf@mellanox.com>
---
 include/net/red.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/red.h b/include/net/red.h
index 9a93477..5918f78 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -179,7 +179,7 @@ static inline void red_set_parms(struct red_parms *p,
 	p->qth_max	= qth_max << Wlog;
 	p->Wlog		= Wlog;
 	p->Plog		= Plog;
-	if (delta < 0)
+	if (delta <= 0)
 		delta = 1;
 	p->qth_delta	= delta;
 	if (!max_P) {
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [patch net 2/2] net_sched: red: Avoid illegal values
  2017-12-04 11:31 [patch net 0/2] RED qdisc fixes Nogah Frankel
  2017-12-04 11:31 ` [patch net 1/2] net_sched: red: Avoid devision by zero Nogah Frankel
@ 2017-12-04 11:31 ` Nogah Frankel
  2017-12-05 19:37 ` [patch net 0/2] RED qdisc fixes David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Nogah Frankel @ 2017-12-04 11:31 UTC (permalink / raw)
  To: netdev; +Cc: davem, jhs, xiyou.wangcong, jiri, mlxsw, Nogah Frankel

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>
---
 include/net/red.h     | 11 +++++++++++
 net/sched/sch_choke.c |  3 +++
 net/sched/sch_gred.c  |  3 +++
 net/sched/sch_red.c   |  2 ++
 net/sched/sch_sfq.c   |  3 +++
 5 files changed, 22 insertions(+)

diff --git a/include/net/red.h b/include/net/red.h
index 5918f78..9665582 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)
 	v->qcount	= -1;
 }
 
+static inline bool red_check_params(u32 qth_min, u32 qth_max, u8 Wlog)
+{
+	if (fls(qth_min) + Wlog > 32)
+		return false;
+	if (fls(qth_max) + Wlog > 32)
+		return false;
+	if (qth_max < qth_min)
+		return false;
+	return true;
+}
+
 static inline void red_set_parms(struct red_parms *p,
 				 u32 qth_min, u32 qth_max, u8 Wlog, u8 Plog,
 				 u8 Scell_log, u8 *stab, u32 max_P)
diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c
index b30a2c7..531250f 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)
 
 	ctl = nla_data(tb[TCA_CHOKE_PARMS]);
 
+	if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog))
+		return -EINVAL;
+
 	if (ctl->limit > CHOKE_MAX_QUEUE)
 		return -EINVAL;
 
diff --git a/net/sched/sch_gred.c b/net/sched/sch_gred.c
index 17c7130..bc30f91 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,
 	struct gred_sched *table = qdisc_priv(sch);
 	struct gred_sched_data *q = table->tab[dp];
 
+	if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog))
+		return -EINVAL;
+
 	if (!q) {
 		table->tab[dp] = q = *prealloc;
 		*prealloc = NULL;
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 7f8ea9e..9d874e6 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)
 	max_P = tb[TCA_RED_MAX_P] ? nla_get_u32(tb[TCA_RED_MAX_P]) : 0;
 
 	ctl = nla_data(tb[TCA_RED_PARMS]);
+	if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog))
+		return -EINVAL;
 
 	if (ctl->limit > 0) {
 		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 09c1203..930e5bd 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)
 	if (ctl->divisor &&
 	    (!is_power_of_2(ctl->divisor) || ctl->divisor > 65536))
 		return -EINVAL;
+	if (ctl_v1 && !red_check_params(ctl_v1->qth_min, ctl_v1->qth_max,
+					ctl_v1->Wlog))
+		return -EINVAL;
 	if (ctl_v1 && ctl_v1->qth_min) {
 		p = kmalloc(sizeof(*p), GFP_KERNEL);
 		if (!p)
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [patch net 0/2] RED qdisc fixes
  2017-12-04 11:31 [patch net 0/2] RED qdisc fixes Nogah Frankel
  2017-12-04 11:31 ` [patch net 1/2] net_sched: red: Avoid devision by zero Nogah Frankel
  2017-12-04 11:31 ` [patch net 2/2] net_sched: red: Avoid illegal values Nogah Frankel
@ 2017-12-05 19:37 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-12-05 19:37 UTC (permalink / raw)
  To: nogahf; +Cc: netdev, jhs, xiyou.wangcong, jiri, mlxsw

From: Nogah Frankel <nogahf@mellanox.com>
Date: Mon,  4 Dec 2017 13:31:09 +0200

> Add some input validation checks to RED qdisc.

Series applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-05 19:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-04 11:31 [patch net 0/2] RED qdisc fixes Nogah Frankel
2017-12-04 11:31 ` [patch net 1/2] net_sched: red: Avoid devision by zero Nogah Frankel
2017-12-04 11:31 ` [patch net 2/2] net_sched: red: Avoid illegal values Nogah Frankel
2017-12-05 19:37 ` [patch net 0/2] RED qdisc fixes David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).