From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385279; b=A6qxCG/dYzyrnyaezKpiaRWt5kG7Ua6hSnM+inQl3ZqqrWTA+tE0AAG7/2iMVJBLqVR0 vdiHK6HqLCCSs0PB/jvlgS/jFue3yLs5Fg4W/hB8hg6aFCHBVabgICCWPsMhb9hWJHhXv KhZ2fs19VhE0U1ZMOJgzsKCYjAoXldluPke7zXAeo2URNloVsocZIbngPGfUgObz+//wC J4FiZ41poxiW2v1Iualu5le0LPJeHrA61v4QZDTPnxOd5/HIWll5jJjHPZbCxSK7d91z3 gG6y8zmBSHlQMN54UxYgfw8z0CCEy4fHO7MJxr9irQihlip/fZx6tlpd5laB6nzfSAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385279; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=PRqlCQ77hmN2AdNk9dRFFvqMHBhT1IpcpKDEKFl7aTI=; b=GOoMYZv99Z/rx1AXPrY0+4sdvxb+dXTiKXxQzAhYL2LMDht2f5QlixS8Zhwbfvl0ncA2 CA71VMA25BKNJkadbOwEUCojHUrJHUsiHT+JCcFRncCZZPwl4opDDCuSf5ZN+sZN62gE6 4zs3mTVHtnBfpKrpy9+Y+Qn2AJ2QRKb1XPzAZXasNrqZQ3/PUezAGrraMJPdSAYoHP1dX QGEjgX2aYS8DT2qqyQvozGKIkk7DNzkB6P12L3h2nFceFJV4TFIlSdZ47sKPG7ffsC1Vd ulApgnIFoQTvvAwsd6cepVuXImM7rjXItLblUxtEM8+JoGwypWnVUyy7cFqcR3CAs+Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RrbQe7Rt; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2308606A687; Fri, 4 Dec 2026 11:54:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RrbQe7Rt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 013FF1F0092C; Fri, 4 Dec 2026 11:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385278; bh=PRqlCQ77hmN2AdNk9dRFFvqMHBhT1IpcpKDEKFl7aTI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=RrbQe7Rtzs01Upz9AuSRdb+TcqR6XskNKuYS6+rq7ZvnfHIfH2Xhnh5u/UwX3Wwc2 gR3tzQbM418Qqj3oP4DrEvkivlZflv5fMbl8vvdf9fUEAFLav7TVJCOC0ozgjlv6Y8 EwHkm4Hr1fyM3We4K3KG1t2FI9foF2v/FwEdOfuD7zyMhNub2b65D/HR5DB1x8CnIB /Ypqep2TqpTYm5iawv56GP6x3GN3LFt+ECjjLljLotsBgoPN0UjziqygXCkXV0hKdA VqAlAhs5IOkk1Gpl/bMbLIOSTUHIdCjMJOsXu0MV6waj7T0FrWQGNg6c3oTR+BzZj7 djjh4/iI2JXUg== Subject: Re: [PATCH net v4] net/sched: cbs: perform rate conversions in signed 64-bit arithmetic From: netdev-bot+sashiko@kernel.org To: 163wangjack@gmail.com Cc: vinicius.gomes@intel.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, victor@mojatatu.com, mhm.dawod@gmail.com, esalomatkina@ispras.ru, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 04 Dec 2026 11:54:37 +0000 Message-ID: <179638527754.3146.11550286389900504432@kernel.org> In-Reply-To: <20261201085406.228-1-163wangjack@gmail.com> References: <20261201085406.228-1-163wangjack@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 1 (1) · Medium: 0 (1) · Low: 2 (1) If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The patch title says it makes CBS 'perform rate conversions in signed 64-bit arithmetic', but one rate conversion in… - [Low] The commit message does not say what bug this patch fixes or what users see. - [Low] The patch bundles two separate fixes under one set of Fixes: tags. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but it is a real local DoS, and the patch widens it on 32-bit. - [Medium] This problem wasn't introduced by this patch, and the changelog explicitly defers it. - [Low] This problem wasn't introduced by this patch, but cbs_change() publishes hicredit, locredit, idleslope, sendslope and offload as… -- net/sched: cbs: perform rate conversions in signed 64-bit arithmetic This patch casts BYTES_PER_KBIT to s64 in the CBS rate conversions, so they are done in signed 64-bit arithmetic on 32-bit kernels too. It also converts q->idleslope and q->sendslope to atomic64_t, so 64-bit loads and stores of them cannot tear on 32-bit kernels. > Cast BYTES_PER_KBIT to s64 so conversions use signed 64-bit arithmetic > on all architecture. Convert q->idleslope and q->sendslope to atomic64_t > to avoid 64-bit tearing on 32-bit kernels. [Severity: Low] Could the changelog describe the user-visible regression that this fixes? Since 000db9e9ad42, BYTES_PER_KBIT comes from include/linux/units.h: #define KILO 1000UL #define BYTES_PER_KBIT (KILO / BITS_PER_BYTE) This makes it unsigned long. The old local definition was (1000LL / 8). On ILP32, qopt->sendslope * BYTES_PER_KBIT in cbs_change() is a 32-bit unsigned multiply, and the result is zero-extended into the s64 field. A negative sendslope such as -900000 kbit/s is stored as about +4.18e9. credits_from_len() in cbs_dequeue_soft() then adds credits for every packet, so q->credits never goes negative and software CBS never shapes. cbs_dump() also reports a positive sendslope to user space. The same 32-bit wrap hits idleslope above about 34.36 Gbit/s. It also hits port_rate in cbs_set_port_rate() for speeds above 34359 Mbit/s, which 397006ba5d91 did not fix on 32-bit. Could the changelog say that LP64 kernels already gave correct results, and that since v6.8 software CBS has not shaped at all on 32-bit kernels? > Fixes: 000db9e9ad42 ("net/sched: cbs: Use units.h instead of the copy of a definition") > Fixes: 397006ba5d91 ("net/sched: cbs: Fix integer overflow in cbs_set_port_rate()") [Severity: Low] Should the atomic64_t conversion be a separate patch with its own Fixes: tag? The s64 sendslope and idleslope fields come from 585d763af09c (the original CBS qdisc). The lockless WRITE_ONCE() stores in cbs_change() came from 8eb54a421a625a. Neither cited commit introduced the tearing. With these tags, stable tooling would apply the tearing fix only to kernels that contain 000db9e9ad42 or 397006ba5d91. The v4 notes also say the earlier Acked-by was dropped because of the atomic64_t change. > diff --git a/net/sched/sch_cbs.c b/net/sched/sch_cbs.c > index 1c93469c56e3d..27d08ce07ecf9 100644 > --- a/net/sched/sch_cbs.c > +++ b/net/sched/sch_cbs.c [ ... ] > @@ -188,7 +188,9 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch) > return NULL; > } > if (q->credits < 0) { > - credits = timediff_to_credits(now - q->last, q->idleslope); > + s64 idleslope = atomic64_read(&q->idleslope); > + > + credits = timediff_to_credits(now - q->last, idleslope); [Severity: Medium] This is a pre-existing issue, and the changelog already defers it, but can the multiply in timediff_to_credits() overflow here? static s64 timediff_to_credits(s64 timediff, s64 slope) { return div64_s64(timediff * slope, NSEC_PER_SEC); } idleslope can be as large as about 2^31 * 125 bytes/s. At that maximum, timediff * slope wraps once now - q->last exceeds about 34 ms. At an idleslope of 1 Gbit/s it wraps after about 74 s. The watchdog normally keeps this gap small. Dequeue can still run long after the watchdog while q->credits < 0, for example when the TX queue is stopped or softirqs are delayed. The wrapped product can then make q->credits very negative. delay_from_credits() then computes -credits * NSEC_PER_SEC, which can wrap again. The result is either an expiry in the past or a very large delay. On 32-bit, this patch makes idleslope values above 34.36 Gbit/s take effect at full size, which lowers the threshold there. LP64 is unchanged. > > credits = q->credits + credits; > q->credits = min_t(s64, credits, q->hicredit); > @@ -196,7 +198,7 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch) > if (q->credits < 0) { > s64 delay; > > - delay = delay_from_credits(q->credits, q->idleslope); > + delay = delay_from_credits(q->credits, idleslope); > qdisc_watchdog_schedule_ns(&q->watchdog, now + delay); [Severity: High] This isn't a bug introduced by this patch, but can an idleslope of zero or less pin a CPU here? cbs_change() stores the user-supplied idleslope with no sign or range check. cbs_policy only checks the attribute length, and v4 dropped the idleslope < 0 check. Once q->credits < 0, there are two cases: With idleslope < 0, timediff_to_credits() returns <= 0, so credits stay negative. delay_from_credits() returns a negative delay, so now + delay is already in the past. With idleslope == 0, delay_from_credits() returns S64_MAX, and now + S64_MAX wraps to a negative value. qdisc_watchdog_schedule_range_ns() passes this expiry to the hrtimer without clamping it: hrtimer_start_range_ns(&wd->timer, ns_to_ktime(expires), delta_ns, HRTIMER_MODE_ABS_PINNED); The timer fires at once and the qdisc is rescheduled. Dequeue finds credits still negative and arms the timer in the past again. That looks like an endless hrtimer and NET_TX softirq loop. It only needs CAP_NET_ADMIN, which an unprivileged user can get in a user namespace, for example on a veth they own. idleslope == 0 already triggers this on every architecture, and a negative idleslope already did on LP64. On ILP32, the old unsigned multiply turned a negative idleslope into a large positive value. With the new (s64) cast, 32-bit kernels get this second trigger as well. The v4 notes say the watchdog busy loop will be fixed separately. > > q->last = now; > @@ -213,7 +215,7 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch) > /* As sendslope is a negative number, this will decrease the > * amount of q->credits. > */ > - credits = credits_from_len(len, q->sendslope, > + credits = credits_from_len(len, atomic64_read(&q->sendslope), > atomic64_read(&q->port_rate)); > credits += q->credits; [Severity: High] Is there one more rate conversion in this function that still uses 32-bit arithmetic on ILP32? Just below this hunk: if (unlikely(atomic64_read(&q->port_rate) == 0)) q->last = now; else q->last = now + div64_s64(len * NSEC_PER_SEC, atomic64_read(&q->port_rate)); len is an int, and NSEC_PER_SEC is 1000000000L, which is a 32-bit long on ILP32. So len * NSEC_PER_SEC overflows for any len >= 3 before it is widened for div64_s64(). For a 1500-byte packet the product wraps to 1,056,413,696. At 1 Gbit/s that gives q->last = now + 8 ns instead of now + 12 us. For some other lengths the product goes negative: len = 64 gives -424,509,440. As a result, the "previous packet is still being sent" check almost never waits: if (now < q->last) { Idle credits also start to accrue from the wrong q->last. So even with the sendslope sign fixed, software CBS on 32-bit would let through idleslope * port_rate / (port_rate - idleslope). That means no shaping at all when idleslope is half the line rate, and about 33% of the line rate when it is 25%. Would this need (s64)len * NSEC_PER_SEC to match the subject line? [ ... ] > @@ -405,8 +407,8 @@ static int cbs_change(struct Qdisc *sch, struct nlattr *opt, > /* Everything went OK, save the parameters used. */ > WRITE_ONCE(q->hicredit, qopt->hicredit); > WRITE_ONCE(q->locredit, qopt->locredit); > - WRITE_ONCE(q->idleslope, qopt->idleslope * BYTES_PER_KBIT); > - WRITE_ONCE(q->sendslope, qopt->sendslope * BYTES_PER_KBIT); > + atomic64_set(&q->idleslope, qopt->idleslope * (s64)BYTES_PER_KBIT); > + atomic64_set(&q->sendslope, qopt->sendslope * (s64)BYTES_PER_KBIT); > WRITE_ONCE(q->offload, qopt->offload); [Severity: Low] This is a pre-existing issue, but can cbs_dequeue_soft() see a mix of old and new parameters here? qdisc_change() calls sch->ops->change() with only RTNL held, and cbs_change() does not take sch_tree_lock(). So these five stores are published one by one. Meanwhile cbs_dequeue_soft() reads idleslope, hicredit, sendslope and locredit at different points under the root lock. There are also data races KCSAN may report: - cbs_dequeue_soft() reads q->hicredit and q->locredit with plain loads, while cbs_change() writes them with WRITE_ONCE(). - cbs_disable_offload() does plain stores to q->enqueue and q->dequeue, which race with plain loads in cbs_enqueue() and cbs_dequeue(). The atomic64_t conversion does stop each slope from tearing, which is all the changelog claims. Would committing the whole parameter set under sch_tree_lock() be a more complete fix? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201085406.228-1-163wangjack%40gmail.com