Skip to contentSkip to conversation

sch_sfq: validate silly quantum values

PATCH In review Eric Dumazet 2 participants 2 messages Apr 27, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sch_sfq: validate silly quantum values

syzbot managed to set up sfq so that q->scaled_quantum was zero, triggering an infinite loop in sfq_dequeue()

More generally, we must only accept quantum between 1 and 2^18 - 7, meaning scaled_quantum must be in [1, 0x7FFF] range.

Otherwise, we also could have a loop in sfq_dequeue() if scaled_quantum happens to be 0x8000, since slot->allot could indefinitely switch between 0 and 0x8000.

Fixes eeaeb068f139 ("sch_sfq: allow big packets and be fair")
Reported-by [email protected]
Cc Jason A. Donenfeld <[email protected]>
---
 net/sched/sch_sfq.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/sched/sch_sfq.c +9 -0
index c787d4d46017b4b41b8eb6d41f2b0a44560ff5bf..5a6def5e4e6df2e7b66c88aa877c7318270d48be 100644
@@ -637,6 +637,15 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
 	if (ctl->divisor &&
 	    (!is_power_of_2(ctl->divisor) || ctl->divisor > 65536))
 		return -EINVAL;
+
+	/* slot->allot is a short, make sure quantum is not too big. */
+	if (ctl->quantum) {
+		unsigned int scaled = SFQ_ALLOT_SIZE(ctl->quantum);
+
+		if (scaled <= 0 || scaled > SHRT_MAX)
+			return -EINVAL;
+	}
+
 	if (ctl_v1 && !red_check_params(ctl_v1->qth_min, ctl_v1->qth_max,
 					ctl_v1->Wlog))
 		return -EINVAL;
Signature · 1 line
2.26.2.303.gf8c07b1a785-goog
maintainer
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Sun, 26 Apr 2020 18:19:07 -0700

Quoted 6 lines

syzbot managed to set up sfq so that q->scaled_quantum was zero, triggering an infinite loop in sfq_dequeue()

More generally, we must only accept quantum between 1 and 2^18 - 7, meaning scaled_quantum must be in [1, 0x7FFF] range.

Quoted 7 lines

Otherwise, we also could have a loop in sfq_dequeue() if scaled_quantum happens to be 0x8000, since slot->allot could indefinitely switch between 0 and 0x8000.

Fixes eeaeb068f139 ("sch_sfq: allow big packets and be fair")
Reported-by [email protected]

Applied and queued up for -stable, thanks Eric.