🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #14200

Re: [PATCH v2 net] tcp: cubic: avoid looping in bictcp_update() TCP friendliness code

#14200
From: netdev-bot+sashiko
Date: Tue, 10 Nov 2026 20:24
170 lines
13764 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 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] tcp_cong_avoid_ai() (net/ipv4/tcp_cong.c:480) runs `u32 delta =
  tp->snd_cwnd_cnt / w;` and never checks that w is non-zero.
- [Medium] net/ipv4/tcp_roccet.c has its own copy of bictcp_update(),
  derived from CUBIC, with the same TCP-friendliness loop this patch…
- [Low] cubictcp_register() (net/ipv4/tcp_cubic.c:527-528) has the
  comment `/* bictcp_update() needs (cwnd * beta_scale) >> 3 to be >= 1…

--

tcp: cubic: avoid looping in bictcp_update() TCP friendliness code

This commit replaces the subtract-and-increment loop in the TCP
friendliness part of bictcp_update() with one division, and clamps delta
to at least 1. It addresses a CPU hang that happens when a BPF congestion
control stores arbitrary values in snd_cwnd and icsk_ca_priv and then
calls cubictcp_cong_avoid() or switches the socket to CUBIC.

Link: https://lore.kernel.org/netdev/179363987528.3131.2987776489427079887@kernel.org/

> diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
> index a88e4bf86150f..e74dabde34324 100644
> --- a/net/ipv4/tcp_cubic.c
> +++ b/net/ipv4/tcp_cubic.c
> @@ -298,10 +298,16 @@ static inline void bictcp_update(struct bictcp *ca, u32 cwnd, u32 acked)
>  	if (tcp_friendliness) {
>  		u32 scale = beta_scale;
>  
> -		delta = (cwnd * scale) >> 3;
> -		while (ca->ack_cnt > delta) {		/* update tcp cwnd */
> -			ca->ack_cnt -= delta;
> -			ca->tcp_cwnd++;

[Severity: Medium]
net/ipv4/tcp_roccet.c has its own CUBIC-derived bictcp_update(), and it
still has the same loop:

net/ipv4/tcp_roccet.c:bictcp_update() {
	...
		delta = (cwnd * scale) >> 3;
		if (delta > 0) {
			while (ca->ack_cnt > delta) { /* update tcp cwnd */
				ca->ack_cnt -= delta;
				ca->tcp_cwnd++;
			}
		}
	...
}

The delta > 0 check rules out a zero delta. Does the huge ack_cnt case
from the commit message still apply there?

sol_tcp_sockopt_congestion() in net/core/filter.c blocks only "cdg". A
BPF CC can therefore call bpf_setsockopt(TCP_CONGESTION, "roccet") and
then overwrite icsk_ca_priv with epoch_start != 0 and
ack_cnt = 0xFFFFFFFF. With the default beta, beta_scale is 15, so
snd_cwnd = 1 gives delta == 1.

The next ACK reaches roccettcp_cong_avoid()->bictcp_update(), and the loop
runs about 2^32 times in ACK processing context.

Should the same max(..., 1U) plus division change go into the ROCCET copy,
perhaps as a companion patch?

> +		/* BPF congestion controls can call us with any cwnd
> +		 * and ack_cnt: cwnd * scale can wrap and give a zero delta,
> +		 * and a loop could run up to 2^32 times.
> +		 */
> +		delta = max((cwnd * scale) >> 3, 1U);

[Severity: Low]
This isn't a bug, but now that delta is clamped here, is the comment in
cubictcp_register() still accurate?

net/ipv4/tcp_cubic.c:cubictcp_register() {
	...
	/* bictcp_update() needs (cwnd * beta_scale) >> 3 to be >= 1 */
	beta_scale = max(beta_scale, 8U);
	...
}

bictcp_update() now guarantees delta >= 1 on its own. The new comment also
says cwnd * scale can wrap to zero anyway.

The registration clamp is no longer needed for loop safety. It still
overrides the beta module parameter when beta < 512, which changes the
Reno emulation rate.

Could the clamp and its comment be dropped or reworded, or mentioned in
the new comment here?

> +		if (ca->ack_cnt > delta) {		/* update tcp cwnd */
> +			u32 n = (ca->ack_cnt - 1) / delta;
> +
> +			ca->ack_cnt -= n * delta;
> +			ca->tcp_cwnd += n;
>  		}
>  
>  		if (ca->tcp_cwnd > cwnd) {	/* if bic is slower than tcp */

[Severity: High]
Under the threat model in the commit message, can this still divide by
zero in tcp_cong_avoid_ai()? In that model, a BPF congestion control
writes arbitrary values into icsk_ca_priv and snd_cwnd and then calls the
cubictcp_cong_avoid() kfunc.

The early return in bictcp_update() skips the final clamp on ca->cnt:

net/ipv4/tcp_cubic.c:bictcp_update() {
	...
	if (ca->last_cwnd == cwnd &&
	    (s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32)
		return;
	...
	ca->cnt = max(ca->cnt, 2U);
}

A BPF CC can set ca->cnt = 0, ca->last_cwnd = snd_cwnd and ca->last_time
to a future jiffies value. It can do this in its own priv area before
calling the kfunc, or after bpf_setsockopt(TCP_CONGESTION, "cubic").
cubictcp_cong_avoid() then passes the unclamped value as the divisor:

	bictcp_update(ca, tcp_snd_cwnd(tp), acked);
	tcp_cong_avoid_ai(tp, ca->cnt, acked);

tcp_cong_avoid_ai() divides by w without checking it:

net/ipv4/tcp_cong.c:tcp_cong_avoid_ai() {
	...
	tp->snd_cwnd_cnt += acked;
	if (tp->snd_cwnd_cnt >= w) {
		u32 delta = tp->snd_cwnd_cnt / w;
	...
}

With w == 0, both snd_cwnd_cnt >= w tests are always true, so the
division runs for any acked value. In NET_RX softirq context, would this
oops and end in a panic?

The ROCCET code already guards the same call:

net/ipv4/tcp_roccet.c:roccettcp_cong_avoid() {
	...
	tcp_cong_avoid_ai(tp, max(1, ca->cnt), acked);
}

There are also more direct routes to the same division:

- The tcp_cong_avoid_ai kfunc is registered in
  bpf_tcp_ca_check_kfunc_ids, so it can be called directly with w = 0.
  The verifier only checks that w is a scalar.
- tcp_reno_cong_avoid() passes the BPF-writable tcp_snd_cwnd(tp) as w.

Would a guard such as max(ca->cnt, 1U) in cubictcp_cong_avoid(), or a
clamp on w inside tcp_cong_avoid_ai(), be needed to fully close this bug
class?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109172356.3113732-1-edumazet%40kernel.org
Technical Details
Message-ID: <179434225619.994134.848424997770273753@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360580-linux-kernel-netdev=dewy.ru
References: <20261109172356.3113732-1-edumazet@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360580-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2 net] tcp: cubic: avoid looping in bictcp_update() TCP
 friendliness code
Date: Tue, 10 Nov 2026 20:24:16 +0000
Organization: Usenet Network
Message-ID: <179434225619.994134.848424997770273753@kernel.org>
References: <20261109172356.3113732-1-edumazet@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="706460"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xjoYvqj+vXnqK+QQinB9KunFCZo= sha256:7L0rXvIWGygIdGxntunUJ9goGxVSOI8MZX1ewALhQgQ=
	sha1:iE5wTFA9TUUNEHF3npagivdROfs= sha256:LGQBYZdK1CtA/aA3j5YetTnnlg4SGC6EoeWsxelC65s=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id C878F113D3F; Wed, 11 Nov 2026 00:26:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Y9Wttd94VX8X;
	Wed, 11 Nov 2026 00:26:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-360580-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 14EE7113D2E; Wed, 11 Nov 2026 00:26:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id DB716160858; Tue, 10 Nov 2026 20:25:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794342258;
	b=Fp9IXou+Qm85WkaTply25Wm9QFfJjH/1Od+ZeUbEdEIbW2KcVCrDb70oe1DlPb41PLUN
	 VBJ1Xf+Qbq4zYEcJJfHssZ0sfeEqU2AZPeWbnJ3KA3JyZ/+welqaVxrWzaEE2ndkUA4rI
	 9qIT2wvG2kVnTVCQYCQvHbloBQXPAf1qLK/qkQ3VSxK7DbHIF9C0l8LDqxMipL/i8n7pF
	 fRYc5lGyF4ydQemi6bWydGHrAN0cxcElg4xKUyjXZC8sMijq4LZZJUa+1VAI/tcQQACfW
	 tE/m7UlAA1nTzjqUHxkpJ6Ui6JBb6xQcIPkPZ7DuLM7fubvi5em6TfAnsNrmMzAC07Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794342258;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=WXnKr1hj5Sb6AzUQW1f1VYYXx371bE27a+KWHBaQ1eA=;
	b=tPrmPrLH9Abqwc7ocuj0eFXK3xNWAzrg4r+2jxPzg3+67K1LEErdutiseEVPaVl8mSt0
	 tRLHn9SVv14MQtirUww4z5l5cg+xf7BgzxymgMDzS66fn0zJxrBswDFgHBbrb7QNgxzeO
	 0AO4fiUntOJnw8IO6hF3JfcsAbhEMTtMdaCnZHrtvuBMFIFUzbhTu9iuT2kp/t8DO3OSN
	 9idczLVWyQmieSCNMDfgc4+IYvRDsYPpsuC9HqajCSl/fbRcE0JE5fArHbApcZRV5dzf2
	 JT0rZuC8o0obRdwkQd6KXhtNVGqp3IHY1w0Rxq3Av3Afx71/uMi2K0kxqs+rN7XRZlw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bg+Myafv;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BEB2606A8BA;
	Tue, 10 Nov 2026 20:24:18 +0000 (UTC)
X-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=bg+Myafv
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794342257;
	b=YaRYferVGujbm01O6WubThiWnGZErpqazTysrIoh6fUlaozkzqGlIcu1XtRK9y01hPRT
	 N0VQA0LAkUW2/ETtjka452g1nuadJfCCDrrV7V17NDfHv+SNUAgM2dNnzSebV5nDWaYvV
	 uoics06X8O3fbm2LFnnQZGsdmgPyfok91vKwwjHHanTvOmUEuhhrdwtLAsDIraOSHOcpU
	 /sxq11XSviX+LEP4GJMcV30qn970yQ2YgygmH2WO6FspYELIyADu7sBCNPi/vx1dYTZH0
	 6+SrpMHBTVaaZ3usr7gwyPSvwbxTRKew7WnNLe6xQWk6h/CcaNNeRrsDbyTM0zDjVvQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794342257;
	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=WXnKr1hj5Sb6AzUQW1f1VYYXx371bE27a+KWHBaQ1eA=;
	b=m+oXvAOsUeax52CuokA0djdX+rGVWjn77/wWBehV6yiN7M/VKpEdH+dbBQ5/dLfzjams
	 kCNLX5Pj3zw7ftyU8KbO6WSU22lnP1Guwz1r6+jXZ2RkwgqnuYexMiea2KzQOJKgj1K3L
	 H+BZoaDEQqZs+AWpsuR69MeVCiCbup/h84hnTAKU68cdUJ5YRpp0WvN/Ak1Nvig3vFGlZ
	 9H2avT2hLTxd4qYLyX6bmrPsJ3eEOxqzekXgIe/9S8PRvXdV+aiYTt97USE5tC0Z1K6nd
	 HncOV0qDMEZZC1cb3t9HSGyTHjglAqz53TIOsxabYWp6aB7VqpVt5wUS5CS555FHYgQ==
X-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=bg+Myafv;
	arc=none smtp.remote-ip=100.103.45.18
X-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 3CC94606A325
	for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 20:24:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D4D21F008A1;
	Tue, 10 Nov 2026 20:24:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794342257;
	bh=WXnKr1hj5Sb6AzUQW1f1VYYXx371bE27a+KWHBaQ1eA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=bg+MyafvwBOztt5CEJf6oZ8ei7A250rOXmxa4RpVIYwHC7oVb2L7BqLiFc6DSjWJC
	 qvAz8AGaEF8viiO27CftqYTOi1HWTna7tpcU0CSBOJp8wU8wa3Unp73pYpZset/Q4L
	 AGZ2328mIZHxAiZKJhjSUZtxLr67fCoRhDSI6/bLCkA2VmjOMwqpxlF7z8NyYWfn4l
	 DtB6jLuYdtCoQU5VEyUHnoc7x+Os5Jn5Jsn0MGipYrflDvuoI1An2jPZrSfkCN32rq
	 vBBNQT7OX416OOZg/UdFKumxFRbqcvq0WswjQFDfNMpYCO9hbMjWuyFQtchmhDqMzR
	 ETmg6hrJM/FYg==
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
 ncardwell@google.com, kuniyu@google.com, horms@kernel.org,
 netdev@vger.kernel.org, sashiko-bot@kernel.org
X-In-Reply-To: <20261109172356.3113732-1-edumazet@kernel.org>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list