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=1795621717; b=AyDZAvs3zldxJFFykpddwnNTHltekBgwqCRp3K8uGSkI8nBBqwOwXJpuMUozoFxHGoCR OeWQgr+lJVOFpKfvcV/tv4/XQfs8mobjxkxcDJJ8mueyPzIIpFgSB+ST58P8GOtAV5j2W Du8KXevONn4EgwRCOY5mO7eYXp0bfgM4ZN1nz2oqXvfp3hDHx8/B4loIU/mh+u+GBJn0d yHZXqf/ijCnpT7PTzGBQ6UZ3/0SW4erREoSnTCKLfpCAFAj4jpA4aoVbPA9fivZBxDKih fAZZCWsqY+22ghDIBjxD7IV8NXXNBV/C1UOC+b9FHZFTt+YEqh3/bu97u2zpqkQfhdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795621717; 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=AEtuRBZyBn8cGtEoJbQEs+0h7bQcWKAoIjdsh1zKEs0=; b=VSdf5fdio6fLyKWQeQDgUU1HPL/CwNAhNxiAqrXdq1o+WK1uLT9nYVIWNZCAqe1Yzm4y T39jkj6MXgD0oyze+PlzoFaC0kqwuLxvuLOUMatN1lL6SkzSzxP6x0AH2PT0TWgUV9Win tYi1QB6i5yAxQyVdSrpBRoUcLzCsBVx+mMAWB9CiWKZ3zAOqh8QyUEKSEqfjxeONU1O8r GvN1wmqBLa1xYOsmGsltGwWoLoxUp1xxlhMKgBjcQD6vErbj0ZY1VxE9jxtqVfda2DcEH eif+Cnp+1ImRNJqtc5PTEy7v5sA++B8/x5Lwbjngose6sEVosDlIPHPin7tyHSLg3wA== 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=DHjNcS9K; 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 0B0D4606A327; Wed, 25 Nov 2026 15:48:36 +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=DHjNcS9K Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DF171F000C0; Wed, 25 Nov 2026 15:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795621716; bh=AEtuRBZyBn8cGtEoJbQEs+0h7bQcWKAoIjdsh1zKEs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DHjNcS9KbfnHN3OjzeiFm6r4jaergdnhHBuph0POrZgKoPxcuk+3/L9E4erdhxRbS BclC808lPuc6XJ8gHpSyqWDeOQJ9JFdygNjBRgdgAP34BymTChbYwnD/4iV43Yb6kT RZvRKdM9OweKBuGLU7PqymHOVnSS3VQUsZgZ+6Rg= 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.18 315/990] tcp: bound snd_cwnd_clamp to TCP_MAX_SND_CWND Date: Wed, 25 Nov 2026 15:28:02 +0100 Message-ID: <20261125143829.471255172@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143822.072087159@linuxfoundation.org> References: <20261125143822.072087159@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.18-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 f9bcfa8773a3a..3bf508ceae7b0 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1430,6 +1430,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 c6677657656c9..8b76dd1201038 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5498,11 +5498,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; WRITE_ONCE(tp->snd_ssthresh, val); break; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index aa860cbd3a442..5f983535bc1d6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -472,7 +472,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 276127902f154..5a83f09cdbd7d 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