stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Nogah Frankel <nogahf@mellanox.com>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 3.18 13/25] net_sched: red: Avoid illegal values
Date: Sun, 28 Jan 2018 22:29:51 +0000	[thread overview]
Message-ID: <20180128222931.7781-13-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180128222931.7781-1-alexander.levin@microsoft.com>

From: Nogah Frankel <nogahf@mellanox.com>

[ Upstream commit 8afa10cbe281b10371fee5a87ab266e48d71a7f9 ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.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 ba5039418a93..3618cdfec884 100644
--- a/include/net/red.h
+++ b/include/net/red.h
@@ -167,6 +167,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 3f6437db9b0f..ec11aced121d 100644
--- a/net/sched/sch_choke.c
+++ b/net/sched/sch_choke.c
@@ -431,6 +431,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 a4ca4517cdc8..5d004ecdbefd 100644
--- a/net/sched/sch_gred.c
+++ b/net/sched/sch_gred.c
@@ -388,6 +388,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 8c0508c0e287..0505b8408c8b 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -199,6 +199,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 4417fb25166f..093f55d0a19a 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -653,6 +653,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.11.0

  parent reply	other threads:[~2018-01-28 22:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-28 22:29 [PATCH AUTOSEL for 3.18 01/25] usb: build drivers/usb/common/ when USB_SUPPORT is set Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 02/25] ARM: AM33xx: PRM: Remove am33xx_pwrdm_read_prev_pwrst function Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 03/25] ARM: dts: am4372: Correct the interrupts_properties of McASP Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 04/25] perf top: Fix window dimensions change handling Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 05/25] perf bench numa: Fixup discontiguous/sparse numa nodes Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 06/25] media: s5k6aa: describe some function parameters Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 07/25] scripts/kernel-doc: Don't fail with status != 0 if error encountered with -none Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 08/25] m68k: add missing SOFTIRQENTRY_TEXT linker section Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 09/25] powerpc/perf: Fix oops when grouping different pmu events Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 10/25] s390/dasd: prevent prefix I/O error Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 12/25] net_sched: red: Avoid devision by zero Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 11/25] gianfar: fix a flooded alignment reports because of padding issue Sasha Levin
2018-01-28 22:29 ` Sasha Levin [this message]
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 14/25] dccp: CVE-2017-8824: use-after-free in DCCP code Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 15/25] btrfs: Fix possible off-by-one in btrfs_search_path_in_tree Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 16/25] 509: fix printing uninitialized stack memory when OID is empty Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 17/25] netfilter: nfnetlink_cthelper: Add missing permission checks Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 18/25] netfilter: xt_osf: " Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 19/25] spi: sun4i: disable clocks in the remove function Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 20/25] xfrm: Fix stack-out-of-bounds with misconfigured transport mode policies Sasha Levin
2018-01-28 22:29 ` [PATCH AUTOSEL for 3.18 21/25] dmaengine: jz4740: disable/unprepare clk if probe fails Sasha Levin
2018-01-28 22:30 ` [PATCH AUTOSEL for 3.18 23/25] x86/mm/kmmio: Fix mmiotrace for page unaligned addresses Sasha Levin
2018-01-28 22:30 ` [PATCH AUTOSEL for 3.18 24/25] xen: XEN_ACPI_PROCESSOR is Dom0-only Sasha Levin
2018-01-28 22:30 ` [PATCH AUTOSEL for 3.18 25/25] hippi: Fix a Fix a possible sleep-in-atomic bug in rr_close Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180128222931.7781-13-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nogahf@mellanox.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).