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=1796387312; b=VcwAs8jqWgzy1qpRsIA4nkYE450dJuAg6utXrgVpCek4Elcb+ttY3UfsO9W665MOESls Wk3oBaCHE0D2i2tkQG4Ejji1CIREldNXqt4DpsYLT14qx7RM3MGRo1jYXCs1zIfoMPOQj GFZAldGaE4Rh6RXc4gmDNhOrXGhtz5UpQjj/yEKT96d/e32xXufsVHySP29xAXG1CbfHM qQZYhN57lHeNCol5MWgaaHf9HuqD0V2MdTObDVN6uOscjJ026Y2iLw8XVk0SsRxtgOcUB x982JWAuJ0IgWp01hy2vUDeg/CY2vvvMZGptWFpl5gXAvQ/SwxVVwIqGYjvApszaKhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387312; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=3LK3uu4k0rROgfaVPVOqBKOD1Ua03u9x0SRUg8kt9xw=; b=nqpZ6AQb3zp9i8tyL2FlpJYqhNmj5sULdL4pWQvFweF7UYwhdXWFtdACAMeacjMRoB1G Wp3pe6P28DbvjVvWn9YvLvyVVxBp60ywxh2ZKxT+5y3Y7dr4xNkw/J4KD3VklGSXNI4SW L1KA3W2ynDwkSQEV6wiMkAz7JUSWeJmlmgckE57AWGhYtD6JE+QV6EDTn63yqtye3ykYH eOw4RsV0VAl195WzP6ceJ+7KJgObIx0x9NlSAaO6HnC6srqkThi6pyCNpWuwzQ3YI0DgR ogvaoMGkmZ1+fHr+Eiy1vLfDiG0KR/IGCmRWoMimHOfCJWZayUP0gXg5/oNHG0KMoLQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xaXIhRAj; 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 DA6ED606A322; Fri, 4 Dec 2026 12:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xaXIhRAj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 501131F000C2; Fri, 4 Dec 2026 12:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387312; bh=3LK3uu4k0rROgfaVPVOqBKOD1Ua03u9x0SRUg8kt9xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xaXIhRAjv13aVMZNRiVU8+7iWZkXHtTaL0lJeZUEfEa5RZzontOUj0w9ZvFT5G3dB F7RH0IamzpijkUS1ot84O/BUoJIYsVcKnTj3CiupEWCuFBaslMfFnS4z6vJdsXCk6Z dnHDK9fgGIaMXLu9Z4c/KmzYvsi5vtur+wjUwk2A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Eric Dumazet , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 0143/1059] tcp: bound snd_cwnd_clamp to TCP_MAX_SND_CWND Date: Fri, 4 Dec 2026 18:54:34 +0900 Message-ID: <20261204100647.921380586@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 475ff14ba558bb8857bca878f1d593784ccc4f0f ] snd_cwnd has no practical upper bound: snd_cwnd_clamp defaults to ~0, and RTAX_INITCWND, a locked RTAX_CWND metric, TCP_BPF_IW and TCP_BPF_SNDCWND_CLAMP accept any positive value. Congestion control modules do u32 arithmetic on cwnd that assumes much smaller values. For instance, ssthresh() handlers compute: CUBIC, BIC, ROCCET: cwnd * (BICTCP_BETA_SCALE + beta), up to 2047 DCTCP: cwnd * dctcp_alpha, up to 1024 CDG, NV, CUBIC, ...: cwnd * beta, below 1024 With a large initcwnd route or TCP_BPF_IW, cwnd is set directly to such values, and the next RTO or recovery calls ->ssthresh() with it. The product then wraps: DCTCP with cwnd = 2^24 and alpha = 1024 gets ssthresh == cwnd, and CUBIC computes a wrong ssthresh and Wmax. CUBIC bictcp_update() also expects cwnd below about one million packets. The paths that can grow cwnd by large amounts (tcp_slow_start(), tcp_cong_avoid_ai(), bbr_set_cwnd() and tcp_init_cwnd()) already bound it by snd_cwnd_clamp, so give snd_cwnd_clamp a finite default of 2^20 packets, and cap the metric and BPF paths that set it or set cwnd directly. 2^20 packets do not limit real flows: with the maximum window scale of 14, a peer can not advertise more than 65535 << 14 bytes (~1GB), which is less than 2^20 packets for any MSS of 1024 bytes or more. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Chris Mason Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20261030111528.2850082-1-edumazet@kernel.org Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- include/net/tcp.h | 9 +++++++++ net/core/filter.c | 3 ++- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_metrics.c | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index ff8025ff25a4e..0b618584fdbcb 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1250,6 +1250,15 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) #define TCP_INFINITE_SSTHRESH 0x7fffffff +/* Default and maximum snd_cwnd_clamp, in packets. + * A peer can not advertise more than 65535 << 14 bytes, so a larger + * cwnd is useless with any MSS of 1024 bytes or more. + * Congestion control modules multiply cwnd by u32 factors up to 2047 + * (cwnd * (BICTCP_BETA_SCALE + beta) in CUBIC), and CUBIC's + * bictcp_update() expects cwnd to stay below about one million packets. + */ +#define TCP_MAX_SND_CWND (1U << 20) + static inline u32 tcp_snd_cwnd(const struct tcp_sock *tp) { return tp->snd_cwnd; diff --git a/net/core/filter.c b/net/core/filter.c index bdb60caa7b36b..fe89172f39cb4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5291,11 +5291,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname, case TCP_BPF_IW: if (val <= 0 || tp->data_segs_out > tp->syn_data) return -EINVAL; - tcp_snd_cwnd_set(tp, val); + tcp_snd_cwnd_set(tp, min_t(u32, val, tp->snd_cwnd_clamp)); break; case TCP_BPF_SNDCWND_CLAMP: if (val <= 0) return -EINVAL; + val = min_t(u32, val, TCP_MAX_SND_CWND); tp->snd_cwnd_clamp = val; tp->snd_ssthresh = val; break; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 2c9b377c4b4d7..0d0cf7848d83b 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -442,7 +442,7 @@ void tcp_init_sock(struct sock *sk) * initialization of these values. */ tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; - tp->snd_cwnd_clamp = ~0; + tp->snd_cwnd_clamp = TCP_MAX_SND_CWND; tp->mss_cache = TCP_MSS_DEFAULT; tp->reordering = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering); diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 29969168f41db..e817d187af3af 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c @@ -495,7 +495,8 @@ void tcp_init_metrics(struct sock *sk) } if (tcp_metric_locked(tm, TCP_METRIC_CWND)) - tp->snd_cwnd_clamp = tcp_metric_get(tm, TCP_METRIC_CWND); + tp->snd_cwnd_clamp = min(tcp_metric_get(tm, TCP_METRIC_CWND), + TCP_MAX_SND_CWND); val = READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) ? 0 : tcp_metric_get(tm, TCP_METRIC_SSTHRESH); -- 2.53.0