Skip to content

Commit 956b5ae

Browse files
edumazetgregkh
authored andcommitted
net_sched: sch_sfq: reject invalid perturb period
commit 7ca5254 upstream. Gerrard Tai reported that SFQ perturb_period has no range check yet, and this can be used to trigger a race condition fixed in a separate patch. We want to make sure ctl->perturb_period * HZ will not overflow and is positive. Tested: tc qd add dev lo root sfq perturb -10 # negative value : error Error: sch_sfq: invalid perturb period. tc qd add dev lo root sfq perturb 1000000000 # too big : error Error: sch_sfq: invalid perturb period. tc qd add dev lo root sfq perturb 2000000 # acceptable value tc -s -d qd sh dev lo qdisc sfq 8005: root refcnt 2 limit 127p quantum 64Kb depth 127 flows 128 divisor 1024 perturb 2000000sec Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: Gerrard Tai <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Cc: [email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6c589aa commit 956b5ae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

net/sched/sch_sfq.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,14 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,
653653
NL_SET_ERR_MSG_MOD(extack, "invalid quantum");
654654
return -EINVAL;
655655
}
656+
657+
if (ctl->perturb_period < 0 ||
658+
ctl->perturb_period > INT_MAX / HZ) {
659+
NL_SET_ERR_MSG_MOD(extack, "invalid perturb period");
660+
return -EINVAL;
661+
}
662+
perturb_period = ctl->perturb_period * HZ;
663+
656664
if (ctl_v1 && !red_check_params(ctl_v1->qth_min, ctl_v1->qth_max,
657665
ctl_v1->Wlog, ctl_v1->Scell_log, NULL))
658666
return -EINVAL;
@@ -669,14 +677,12 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt,
669677
headdrop = q->headdrop;
670678
maxdepth = q->maxdepth;
671679
maxflows = q->maxflows;
672-
perturb_period = q->perturb_period;
673680
quantum = q->quantum;
674681
flags = q->flags;
675682

676683
/* update and validate configuration */
677684
if (ctl->quantum)
678685
quantum = ctl->quantum;
679-
perturb_period = ctl->perturb_period * HZ;
680686
if (ctl->flows)
681687
maxflows = min_t(u32, ctl->flows, SFQ_MAX_FLOWS);
682688
if (ctl->divisor) {

0 commit comments

Comments
 (0)