Skip to content

Commit

Permalink
Merge branch 'RED-qdisc-fixes'
Browse files Browse the repository at this point in the history
Nogah Frankel says:

====================
RED qdisc fixes

Add some input validation checks to RED qdisc.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Dec 5, 2017
2 parents 5811767 + 8afa10c commit c1d69de
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/net/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -179,7 +190,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) {
Expand Down
3 changes: 3 additions & 0 deletions net/sched/sch_choke.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions net/sched/sch_gred.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions net/sched/sch_red.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions net/sched/sch_sfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1d69de

Please sign in to comment.