From: Nogah Frankel Date: Mon, 4 Dec 2017 11:31:11 +0000 (+0200) Subject: net_sched: red: Avoid illegal values X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90eef1fb80510728ba6422c871e9e0a9825ea779;p=pandora-kernel.git net_sched: red: Avoid illegal values 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 [bwh: Backported to 3.2: - Drop changes in sch_sfq - Adjust context] Signed-off-by: Ben Hutchings --- diff --git a/include/net/red.h b/include/net/red.h index b72a3b833936..d2eb24d72e63 100644 --- a/include/net/red.h +++ b/include/net/red.h @@ -124,6 +124,17 @@ static inline u32 red_rmask(u8 Plog) return Plog < 32 ? ((1 << Plog) - 1) : ~0UL; } +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) diff --git a/net/sched/sch_choke.c b/net/sched/sch_choke.c index 081ffb9188d5..f3b1ed07ef64 100644 --- a/net/sched/sch_choke.c +++ b/net/sched/sch_choke.c @@ -479,6 +479,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 e1afe0c205fa..c65c8315e889 100644 --- a/net/sched/sch_gred.c +++ b/net/sched/sch_gred.c @@ -384,6 +384,9 @@ static inline int gred_change_vq(struct Qdisc *sch, int dp, struct gred_sched *table = qdisc_priv(sch); struct gred_sched_data *q; + if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog)) + return -EINVAL; + if (table->tab[dp] == NULL) { table->tab[dp] = kzalloc(sizeof(*q), GFP_ATOMIC); if (table->tab[dp] == NULL) diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c index d617161f8dd3..bbf2dfdab831 100644 --- a/net/sched/sch_red.c +++ b/net/sched/sch_red.c @@ -189,6 +189,8 @@ static int red_change(struct Qdisc *sch, struct nlattr *opt) return -EINVAL; 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);