Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2353790pxb; Mon, 20 Sep 2021 19:52:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJze+hV2hPcthJXT86uqj3lEE/AMUBIrWx0+PtPqHKQCrVf0pXLx6fqk1f9cL9rfJ9Zr4Br5 X-Received: by 2002:a5d:851a:: with SMTP id q26mr20925971ion.163.1632192754367; Mon, 20 Sep 2021 19:52:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192754; cv=none; d=google.com; s=arc-20160816; b=qQbFLZrqymRyAhfIKOcdh3S4yinvNkhE3KhaLY/1mr2VHVHH/83cKWGSdbPgdaDR6z xiWRFReKmzRrlmu7KPZgF+VLjNAhS7B26nq8BHvMBmuNmX2OiTYYJ7EGXuIHL3isT5IC D26pWL47gZpoFI2+oUo/G/oF4jVZ06RLKu7a3xJvQZ3najXDYZkp4rjBZZupWjWZPsNz qTeuQQ1PdnrRqsfdTlGmkZfwxctjQTUyZOiSFX9DUSWi1HFIaIapD479bRvwW+Dx31Cf opuCtQ9m2GxTQTIXxNSi5StGL3fkYz4pT2QjtrgE1uOrHz9J7jx4RW1m/JXL+v+5aDpG mjLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RC/LZB80axH05prTcqKOrpXxd+76txwKQTqJFBXgpI4=; b=BXcdYDJoS8tTa5IkgA7+/J0korX2fQNwrt6tIYJOrYJbGOgAiqtfaDfArNqvfrlKYt 132VxkuhvO+AwrepY5XK3rWaCc4FynXQPFtxV7yF8Jr6HI4zGunux9808s9ZgHSGlUJP nthNIG2idm29JT+rBBbjxPo+LEQ2/DY8CZl+6H3WBMw/xRHsuUJXPsorgHGOnxjPEtTo zqpH2n393hGAOjKGCZxBe6S7RiyfxFugJmZAUhf1KHzftwS1pqnnKA+S9lZD1q+HtNOY QX26PUdKOnfSXiJpIe0B1lcCUQn66uR1SuEKUQiJQUBCgr+PMalwPICP71u9nxl5eKul /bCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1503ivzZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si16425719ilc.20.2021.09.20.19.52.23; Mon, 20 Sep 2021 19:52:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1503ivzZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353822AbhITSwc (ORCPT + 99 others); Mon, 20 Sep 2021 14:52:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:33186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385435AbhITSu0 (ORCPT ); Mon, 20 Sep 2021 14:50:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E5DC61B03; Mon, 20 Sep 2021 17:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159274; bh=KAregwlMscd5uw90uV8kW1moOjFbUefEZg0er8b6MUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1503ivzZ4KbZAN56BMNpxsE+/Rc0YL76na4vZBRpcxPpdVO/qSTjd4E63f5GK61XT w+orMfUEWOzm51SSyFLVAUJHYfPhwfpPCnajWuG+xp3yAlOrU0J6o66kmggIx3VRGC tR+RjaGh1ZOXrjZNPoHu/TwpQ7SBgLR6kdJRxxZY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 156/168] fq_codel: reject silly quantum parameters Date: Mon, 20 Sep 2021 18:44:54 +0200 Message-Id: <20210920163926.795422352@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ 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 Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/uapi/linux/pkt_sched.h | 2 ++ net/sched/sch_fq_codel.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h index 79a699f106b1..ec88590b3198 100644 --- a/include/uapi/linux/pkt_sched.h +++ b/include/uapi/linux/pkt_sched.h @@ -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, diff --git a/net/sched/sch_fq_codel.c b/net/sched/sch_fq_codel.c index bbd5f8753600..99e8db262198 100644 --- a/net/sched/sch_fq_codel.c +++ b/net/sched/sch_fq_codel.c @@ -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])); -- 2.30.2