]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
fq_codel: reject silly quantum parameters
authorEric Dumazet <edumazet@google.com>
Fri, 3 Sep 2021 22:03:43 +0000 (15:03 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Sep 2021 10:39:31 +0000 (12:39 +0200)
[ Upstream commit c7c5e6ff533fe1f9afef7d2fa46678987a1335a7 ]

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: 4b549a2ef4be ("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>
include/uapi/linux/pkt_sched.h
net/sched/sch_fq_codel.c

index 79a699f106b14ef36afe459b955ab136326e36a0..ec88590b3198441f18cc9def7bd40c48f0bc82a1 100644 (file)
@@ -827,6 +827,8 @@ struct tc_codel_xstats {
 
 /* FQ_CODEL */
 
+#define FQ_CODEL_QUANTUM_MAX (1 << 20)
+
 enum {
        TCA_FQ_CODEL_UNSPEC,
        TCA_FQ_CODEL_TARGET,
index bbd5f8753600624f2eba9a91d2efa21333f4221f..99e8db2621984903af8104ca0082d262e5f372b7 100644 (file)
@@ -369,6 +369,7 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
 {
        struct fq_codel_sched_data *q = qdisc_priv(sch);
        struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
+       u32 quantum = 0;
        int err;
 
        if (!opt)
@@ -386,6 +387,13 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
                    q->flows_cnt > 65536)
                        return -EINVAL;
        }
+       if (tb[TCA_FQ_CODEL_QUANTUM]) {
+               quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
+               if (quantum > FQ_CODEL_QUANTUM_MAX) {
+                       NL_SET_ERR_MSG(extack, "Invalid quantum");
+                       return -EINVAL;
+               }
+       }
        sch_tree_lock(sch);
 
        if (tb[TCA_FQ_CODEL_TARGET]) {
@@ -412,8 +420,8 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
        if (tb[TCA_FQ_CODEL_ECN])
                q->cparams.ecn = !!nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
 
-       if (tb[TCA_FQ_CODEL_QUANTUM])
-               q->quantum = max(256U, nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]));
+       if (quantum)
+               q->quantum = quantum;
 
        if (tb[TCA_FQ_CODEL_DROP_BATCH_SIZE])
                q->drop_batch_size = max(1U, nla_get_u32(tb[TCA_FQ_CODEL_DROP_BATCH_SIZE]));