Received: by 10.223.185.116 with SMTP id b49csp6370751wrg; Wed, 28 Feb 2018 08:18:40 -0800 (PST) X-Google-Smtp-Source: AH8x226oX3IKENJ+S+sPPYOUDhBI5T3ixG8gp3dZgWy5RVXPa4S3MeIOO45VaIfp9xgFw0b+JDh7 X-Received: by 2002:a17:902:6c4c:: with SMTP id h12-v6mr18314641pln.101.1519834720836; Wed, 28 Feb 2018 08:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519834720; cv=none; d=google.com; s=arc-20160816; b=n2WT7ehxLGBCzK56WBoqknVJApQ/TdWS//JhLCy7eGqmq2cK3HAnY9g07x6Kv1Z4JG 9/xr8WmjUYnBPPiBsBI6BifcvstRQDLg9Lv1p0itp5bgkXv8YFiBaBPmLfqWyQza/CO7 eUqUOXX3dR5yMdPDj0Gy2cY1H4UmrGuEK71qKNMua0c5ZTCLgWNeBr6OWaktSyXZwxs0 4H0ABXXAntcdAx1sZvXcSVnTuEkawfj8p4jFZT3oLglU7rTjd8wC7tq6PBw4u5IYcZvc t2wfCVoCUd/19HkJN3Z57Cyc+xUz9dTUGU7Xq0q43bTAp+/ZdPIf4vHd9ybgpoJd4RKG HBBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=TK2ogfjZfzbZzJHI/+BR2khG8jlqxdARZGvm3woGgN0=; b=HiYlePHpqxb9ju6SdPuGRe9M8OyF+eD3lEInNd6VH+iAeLO4zavHxhePmTi6oqoNLm b8LGl0Z6Wfh+6v6XG5dfuwzaIMJMRsfFYvUsMPHe6w7deLiphamG1zRH+/zZxXCgl6bU cu2pHDJ5OuIpicT7bKV38/CylqLM+iD7r32xxhSP1NMa8X3PM9w2WaEn7/+XIwTA4X75 kLUlFN30es9gVHN9N6q0+bniExIVcACtyuBmVzwWuXfQFyiuJHS2VoNebCYurd4ZeZI6 MzEdAMvJYRARpIK2McbU6/FPz8KrxSwFxFTXN3ts9co7BYBUi3hdI3PbsK4N4/g+EiXv DTpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1si1158045pgn.661.2018.02.28.08.18.25; Wed, 28 Feb 2018 08:18:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934976AbeB1QQh (ORCPT + 99 others); Wed, 28 Feb 2018 11:16:37 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35241 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934542AbeB1QQe (ORCPT ); Wed, 28 Feb 2018 11:16:34 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yu-0006Xm-3w; Wed, 28 Feb 2018 15:22:32 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Ye-0008Ra-Lq; Wed, 28 Feb 2018 15:22:16 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Nogah Frankel" , "David S. Miller" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 057/254] net_sched: red: Avoid illegal values In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Nogah Frankel commit 8afa10cbe281b10371fee5a87ab266e48d71a7f9 upstream. 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 Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- 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(+) --- a/include/net/red.h +++ b/include/net/red.h @@ -167,6 +167,17 @@ static inline void red_set_vars(struct r 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) --- a/net/sched/sch_choke.c +++ b/net/sched/sch_choke.c @@ -419,6 +419,9 @@ static int choke_change(struct Qdisc *sc 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; --- a/net/sched/sch_gred.c +++ b/net/sched/sch_gred.c @@ -388,6 +388,9 @@ static inline int gred_change_vq(struct 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; --- a/net/sched/sch_red.c +++ b/net/sched/sch_red.c @@ -199,6 +199,8 @@ static int red_change(struct Qdisc *sch, 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); --- a/net/sched/sch_sfq.c +++ b/net/sched/sch_sfq.c @@ -658,6 +658,9 @@ static int sfq_change(struct Qdisc *sch, 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)