Skip to content

Commit 8c01c62

Browse files
edumazetgregkh
authored andcommitted
fq_codel: reject silly quantum parameters
[ Upstream commit c7c5e6f ] syzbot found that forcing a big quantum attribute would crash hosts fast, essentially using this: tc qd replace dev eth0 root fq_codel quantum 4294967295 This is because fq_codel_dequeue() would have to loop ~2^31 times in : if (flow->deficit <= 0) { flow->deficit += q->quantum; list_move_tail(&flow->flowchain, &q->old_flows); goto begin; } SFQ max quantum is 2^19 (half a megabyte) Lets adopt a max quantum of one megabyte for FQ_CODEL. Fixes: 4b549a2 ("fq_codel: Fair Queue Codel AQM") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6e2d36f commit 8c01c62

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎include/uapi/linux/pkt_sched.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ struct tc_codel_xstats {
826826

827827
/* FQ_CODEL */
828828

829+
#define FQ_CODEL_QUANTUM_MAX (1 << 20)
830+
829831
enum {
830832
TCA_FQ_CODEL_UNSPEC,
831833
TCA_FQ_CODEL_TARGET,

‎net/sched/sch_fq_codel.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
369369
{
370370
struct fq_codel_sched_data *q = qdisc_priv(sch);
371371
struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
372+
u32 quantum = 0;
372373
int err;
373374

374375
if (!opt)
@@ -386,6 +387,13 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
386387
q->flows_cnt > 65536)
387388
return -EINVAL;
388389
}
390+
if (tb[TCA_FQ_CODEL_QUANTUM]) {
391+
quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
392+
if (quantum > FQ_CODEL_QUANTUM_MAX) {
393+
NL_SET_ERR_MSG(extack, "Invalid quantum");
394+
return -EINVAL;
395+
}
396+
}
389397
sch_tree_lock(sch);
390398

391399
if (tb[TCA_FQ_CODEL_TARGET]) {
@@ -412,8 +420,8 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
412420
if (tb[TCA_FQ_CODEL_ECN])
413421
q->cparams.ecn = !!nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
414422

415-
if (tb[TCA_FQ_CODEL_QUANTUM])
416-
q->quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
423+
if (quantum)
424+
q->quantum = quantum;
417425

418426
if (tb[TCA_FQ_CODEL_DROP_BATCH_SIZE])
419427
q->drop_batch_size = max(1U, nla_get_u32(tb[TCA_FQ_CODEL_DROP_BATCH_SIZE]));

0 commit comments

Comments
 (0)