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=1796384538; b=E+HxT3aKA06TlYvVisfa+tesGoKcNOU2f9JxOXK65J2U9OzTopyZ3PXlkfIGk8Ll776M /MfgTqmlp2Jyero6y9atlrXAUaLkymDeuh3IGRpfu4ZMfeooFMaZBgay5SewTXk4C5m61 HT/h8gltmFjtesqU3UA2sK8vqpWkau0LizXtfDRsrPVltMQDLgvNDcOwtV8CDrIu2pbcZ WAkubZNqNCb0XMcH/bmUAlOBYdc8KDFVQvgKf89L+CLHywPnTwBiMB+hVemHJU0yS/0ec eUZLx3c+BW/Lfzx/YZjHstf2PKuuifjNZfX0jcZd8CDsvrjYIA+Kpy7lZXLV7oME2dg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384538; 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=q5Du2ZB0YTP+YzdJDfP7WVx/BiHjvD+0HhycRKVBS/M=; b=FE8xN6cnq7H4j4EJGG3M6ZRNvyeWmrSlARfz7CIwdySqZZbQlnUJhJrVE47fQONzhaF+ NnjFZ1qqhA9dauCCaSL8t9NMrj/3K/jFCyY1pde32N0BiDCgtzlPjbQcy6jyN6jL4WOSF i8FTNbKWRbl8sqSCGVrB//8xRoiaCTqTf0cKbBnDtv2tcVZySgsFrOgzV9tCfkO2wullp 592i6NAHhvH3Y1OO5chx/dP6bEA5GzNpxBSwfnLXBwoPSjAjx8obid975DwEamIpcPV42 HIJZiMAoG+Ek+FahVCwb6tCY26qp2jmKfOE07wWLtzabkBrFqQvbrZqeAHFQ89O2/Zw== 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=OfCnuXHf; 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 179D5606A32C; Fri, 4 Dec 2026 11:42:18 +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=OfCnuXHf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D03B1F000CE; Fri, 4 Dec 2026 11:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384537; bh=q5Du2ZB0YTP+YzdJDfP7WVx/BiHjvD+0HhycRKVBS/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OfCnuXHfmowXbklroUlpY9Vl+JgVDoyVPd3KR8tEW53bSgglcjZbXlGFe+ihozzz3 pFCqj/s148pVeEI/2dTzUsfGF3TXPXfYCWUjRKhxAdlgflcBQ3IigWptlHlaGd7+Yw OkvXfGHXWrr957l51F9/ByjExON0Ynd0DF2Z9YOc= 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.6 0190/1167] tcp: bound snd_cwnd_clamp to TCP_MAX_SND_CWND Date: Fri, 4 Dec 2026 18:53:37 +0900 Message-ID: <20261204100707.013718728@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 1df0e2d66bfc1..925544ed1ee14 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1219,6 +1219,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 34713be30ac5a..356bf50afabea 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5374,11 +5374,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 a427a6ceec136..f5db8eabb8258 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 d28ef811f0efa..13a73b1b7a61f 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