Article View: linux.kernel.netdev
Article #7912[PATCH net] tcp: bound snd_cwnd_clamp to TCP_MAX_SND_CWND
From: Eric Dumazet
Date: Tue, 27 Oct 2026 13:06
Date: Tue, 27 Oct 2026 13:06
91 lines
10937 bytes
10937 bytes
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, and can misbehave if cwnd gets too big.
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^24 packets, and cap the metric and BPF paths that set it or set
cwnd directly.
2^24 packets is more than 24GB in flight with a 1448 byte MSS, well
above what any sk_sndbuf allows.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Chris Mason <mason@kernel.org>
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
include/net/tcp.h | 6 ++++++
net/core/filter.c | 3 ++-
net/ipv4/tcp.c | 2 +-
net/ipv4/tcp_metrics.c | 3 ++-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 0265c27a5fd77df8a86991e364ec7caff3a7ea0d..be1609cd78840cfb1da75517273be0d64f4c3981 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1553,6 +1553,12 @@ 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.
+ * Far above any usable BDP, but low enough that congestion control
+ * arithmetic such as 100 * cwnd in CUBIC cannot overflow a u32.
+ */
+#define TCP_MAX_SND_CWND (1U << 24)
+
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 70dc621672f2e9fccd9cf54808e002ff0f82da62..63bb314e8697db81ecef3a0b3dcf4fed85ac79fa 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5562,11 +5562,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 76df69aa01154cddd4c7940f3c3749d04487ae7b..a11c1b06ed5e5591c47f585a3f9e4fba4de30153 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -456,7 +456,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 d58f99c67d4dc0877d0e853c9e9faddd80343c22..ae551546422fe7c38b2ac3224f9ea9adbd3679d0 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
Technical Details
Message-ID:
<20261027130617.1550253-1-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352445-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352445-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net] tcp: bound snd_cwnd_clamp to TCP_MAX_SND_CWND Date: Tue, 27 Oct 2026 14:06:17 +0100 Organization: Usenet Network Message-ID: <20261027130617.1550253-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1541539"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:UKx0YbcqUgIX1gJbYt4iZg5m/ZA= sha256:NrtGB6hTwD3oKq4GtGxHgTiX5hkXpe6XQ1lz/Wy3jxg= sha1:QMAUdaaoSCR4iXMiZQ0c0oLBPA8= sha256:aMyagAT1TWXaVoQH6CREDhkfLSdEivrPatyUInXg2No= 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 73B0E125BFD; Tue, 27 Oct 2026 16:07:51 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 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] 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 1SjpZPR3QwXO; Tue, 27 Oct 2026 16:07:48 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-352445-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 7DC20125BF9; Tue, 27 Oct 2026 16:07:40 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 48C8524DF5; Tue, 27 Oct 2026 13:06:24 +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=1793106383; b=LM6+VngVtqM4P9OtSByguCvJj4ti0FICMrisay0s0A485DvD+oIeMrlj4rfchgskdMz3 QPbXuMKfddb9WZ6T0CfUVZKv8RIg5bHMHUOCgCPHD/h4APtf6SZRGvBsBJwxBZSJ0dx69 KPc1SQ/a0TcRsvRahK61cl4IBRjCJVjQzImHnNihDzshbVRgNjZsInu7bzpVFfFMYWtol Eh8ZbbwWDMGo//JwDAkjSuZZ0DNiVFrW17Ht4mDCwJi/xhrDF8JhI+rEfQ/fGWjDDp32J VyzfNM9JN5P7ngR02PdsRm1C1cxkARNmTGsdJEkZr7g6knTNk3YAeexWW6SPikvwodw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793106383; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding; bh=7uGiIIsGwotu1dNVo2fGPdi4w1b/0QD6iVQaceH2QM0=; b=QkK75w8ADhWmW1YVhqjvHrTWTqZDyFKuqIKQ0c40Uav7oLi5sV4gend6n+sqS97P979s EEWl1KJUsnGNZXh8L6lH7GvGITRTgfdN8r3L5jIPEjCjiEr0UKExNQBYYlEkFvDboR7LW K801k27Mypn6TzALCJefVopP0b+ayTo2l337u2F0Y4/4GldrfuPB/aREv+ym9OUuNOwmQ 2FGOiQMRsyWAi/7aN1Y2Z9OJ9jk5gYv5Diq2NckGpbwsPcDkGhJr+YHwooHqzLVF+HB/N Of/CbLwBQ7fw2V/wnbN07EFg2SsQ3Bv2q+31nPNiKrT4Tlooyc1FJS94BToDYQR0PfA== 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=Jbm2Qmrr; 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 7C90E606A322; Tue, 27 Oct 2026 13:06:23 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Jbm2Qmrr 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=1793106382; b=0ms582Hv+amlVz9+oWy92xzhZvS0NXiolruM6bTLmuaTNxwzz87fTbmKmh+je7LHy3If 0PkOsuR/8gOiOflQF2G1yUYAVmwJIEpVEZqn0zpYT0jP8y9Qri1ZR6PQkKKmYMldFotLJ +Hfl06+CB32/VS++5dIyf/hpJe/7ecIV5l0Ne3EBE+E6aIpazzRIXbiEhf5Z6TdJKgevh t1NDIV8qwbk0R7i5Q/JsSZ/Vu/6TejkN2g71W3OwFm2QwpGvORAKC3LBXLCnDhzV2/Uv7 i7rsDYl6IuLfHYbv/0O77ogMZ88deHKVjCw6IRk2NHcAl2dZu6jn4q+LDFGmriTAdBw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793106382; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=7uGiIIsGwotu1dNVo2fGPdi4w1b/0QD6iVQaceH2QM0=; b=oVCrMHzAAP11pYgNNwKY4xxYIKV8pcXCQxFtaOLT58++U2Ly93cAR9SKkv4N+pdjrqSr QqZidDxw5UxBCzDkXYeOxJvFxRdvS7rBhJ1bB6RyDdRpTojnppiVTqrce1/Wt8vQBr8h1 YhaaIh7CNq2QPF0c++e+3qs9EO/g8Vlc16NhEWxg9S1PoI7MiSMjLIcjyA+406DeoFV+i XAq8r7mUFatXTPEPfaAl5n+AfUc8aGWqSK+/OygJGvXBBUp33YciynWDUXBwMM3zusuqC A2aOHv3WJoHPh1p+3pr0Qn1ezEgzDkj5/4yliClf48vEqMQvPxqmJLU5gYe+OjFjs2A== 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=Jbm2Qmrr; 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 5DD5F606A31A for <netdev@vger.kernel.org>; Tue, 27 Oct 2026 13:06:22 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 442291F01829; Tue, 27 Oct 2026 13:06:20 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793106382; bh=7uGiIIsGwotu1dNVo2fGPdi4w1b/0QD6iVQaceH2QM0=; h=From:To:Cc:Subject:Date; b=Jbm2QmrrCy2awObRjp/fjZ25opWWkzo+70hj+nxrqoJAqwevfK/gYQjdvE1Ljb0rd oIHSw77vh8Hk717TN28xQCOqki5c9UKtMTOzKcQ4SDhKyjR/lUtkP7uyRJgfCos/9d ++Q9iNHAnyuTGy8Fu3LxePNmu+XOuLJC4GKJLNuEufRkw3AaqFPIbUnfaXs/pViONn QHpizXO8npe3FqXiXEA3WnBNCdl8uZWwW0ILdCJ2iMo+eqCCSzh7e6CqxLA45xez4K jqn+tmJ5MdHzRyK7rUP7uXGx8PWmuy6DOtzUt/RNswXrVGLnJp5CKQPipXiNIigYdy xQLv/1PCAYXlw== X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>, Chris Mason <mason@kernel.org> X-Mailer: git-send-email 2.53.0 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