]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: sched: prevent invalid Scell_log shift count
authorRandy Dunlap <rdunlap@infradead.org>
Fri, 25 Dec 2020 06:23:44 +0000 (22:23 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Dec 2020 22:52:54 +0000 (14:52 -0800)
Check Scell_log shift size in red_check_params() and modify all callers
of red_check_params() to pass Scell_log.

This prevents a shift out-of-bounds as detected by UBSAN:
  UBSAN: shift-out-of-bounds in ./include/net/red.h:252:22
  shift exponent 72 is too large for 32-bit type 'int'

Fixes: c6a9af1541cd ("net_sched: red: Avoid illegal values")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Reported-by: syzbot+97c5bd9cc81eca63d36e@syzkaller.appspotmail.com
Cc: Nogah Frankel <nogahf@mellanox.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/red.h
net/sched/sch_choke.c
net/sched/sch_gred.c
net/sched/sch_red.c
net/sched/sch_sfq.c

index fc455445f4b226373b78ff4cce4fe3de2cddb0c0..932f0d79d60cbbab60db73baddc8b650935b3bf6 100644 (file)
@@ -168,12 +168,14 @@ 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)
+static inline bool red_check_params(u32 qth_min, u32 qth_max, u8 Wlog, u8 Scell_log)
 {
        if (fls(qth_min) + Wlog > 32)
                return false;
        if (fls(qth_max) + Wlog > 32)
                return false;
+       if (Scell_log >= 32)
+               return false;
        if (qth_max < qth_min)
                return false;
        return true;
index bd618b00d3193242b1a166b5c48b3bccbcef5d2e..50f680f03a547ebe952eae9657b40d4de0fc5c9f 100644 (file)
@@ -362,7 +362,7 @@ 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))
+       if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Scell_log))
                return -EINVAL;
 
        if (ctl->limit > CHOKE_MAX_QUEUE)
index 8599c6f31b057f494f64941929a2012e5fddac5a..e0bc77533acc39d90dbbffc88241ea3063e27d3f 100644 (file)
@@ -480,7 +480,7 @@ 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)) {
+       if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Scell_log)) {
                NL_SET_ERR_MSG_MOD(extack, "invalid RED parameters");
                return -EINVAL;
        }
index e89fab6ccb34f733a474111a08128076b8c77198..b4ae34d7aa965decf541660ee195df92f646f799 100644 (file)
@@ -250,7 +250,7 @@ static int __red_change(struct Qdisc *sch, struct nlattr **tb,
        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))
+       if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Scell_log))
                return -EINVAL;
 
        err = red_get_flags(ctl->flags, TC_RED_HISTORIC_FLAGS,
index bca2be57d9fc1785d0c246861641c63021f2764c..b25e51440623bce56628ff33142c63739c4ac239 100644 (file)
@@ -647,7 +647,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
        }
 
        if (ctl_v1 && !red_check_params(ctl_v1->qth_min, ctl_v1->qth_max,
-                                       ctl_v1->Wlog))
+                                       ctl_v1->Wlog, ctl_v1->Scell_log))
                return -EINVAL;
        if (ctl_v1 && ctl_v1->qth_min) {
                p = kmalloc(sizeof(*p), GFP_KERNEL);