Article View: linux.kernel.netdev
Article #18619[PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
From: Chris Mason
Date: Wed, 18 Nov 2026 15:51
Date: Wed, 18 Nov 2026 15:51
48 lines
9213 bytes
9213 bytes
tcp_rcv_rtt_update() starts with sample << 3 in u32 arithmetic, so a
sample of 536.9 s or more wraps.
tcp_rcv_rtt_measure() can hand it one. Its sample is the time the sender
took to fill one receive window, and a low rate flow can take longer
than that. This caller only looks for a minimum, so the wrapped value is
kept whenever it is below the current estimate. A 540 s sample ends up
as an estimate of about 3.1 s.
Clamp the sample to TCP_RTT_MAX_US in tcp_rcv_rtt_update(), like
tcp_rtt_estimator() does on the send side. That covers both callers, and
the smoothed estimate now tops out at 8 * 120 s, which fits in a u32.
Found by code inspection (Eric Dumazet), who also suggested the fix.
Confirmed with an LLM generated reproducer on an unmodified kernel, and
tested with the reproducer and existing kernel selftests.
Fixes: 645f4c6f2ebd ("tcp: switch rcv_rtt_est and rcvq_space to high resolution timestamps")
Suggested-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Chris Mason <mason@kernel.org>
---
Notes:
v1->v2: new patch (Eric), with min() instead of min_t() (David)
net/ipv4/tcp_input.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 69e038b9389a..d9a66a1342ef 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -857,7 +857,11 @@ void tcp_initialize_rcv_mss(struct sock *sk)
static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep)
{
u32 new_sample, old_sample = tp->rcv_rtt_est.rtt_us;
- long m = sample << 3;
+ long m;
+
+ /* Keep sample << 3 and the smoothed estimate within u32. */
+ sample = min(sample, TCP_RTT_MAX_US);
+ m = sample << 3;
if (old_sample == 0 || m < old_sample) {
new_sample = m;
--
2.55.0
Technical Details
Message-ID:
<20261118155144.18393-5-mason@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366260-linux-kernel-netdev=dewy.ruReferences:
<20261118155144.18393-1-mason@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366260-linux-kernel-netdev=dewy.ru From: mason@kernel.org (Chris Mason) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update() Date: Wed, 18 Nov 2026 10:51:48 -0500 Organization: Usenet Network Message-ID: <20261118155144.18393-5-mason@kernel.org> References: <20261118155144.18393-1-mason@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2633280"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:D4k+kGd3CQIBawR/EwjaQh+j92M= sha256:SxNdnip6muZcZZRWrko7dJgVNQLDDhH80Bl46FPMgBc= sha1:X02yxe7Y898YiCGBZSkM9GsO+6I= sha256:xUwZvwckyIJ4At/9IkpsJjxVmPoygcZsuxDFV45szDc= 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 8BE57115317; Wed, 18 Nov 2026 18:52:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 S9-JCU_NeS7Q; Wed, 18 Nov 2026 18:52:08 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-366260-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 38FBF115312; Wed, 18 Nov 2026 18:51:54 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 61351617C61; Wed, 18 Nov 2026 15:51:54 +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=1795017114; b=UOEzPBGGr3lqOwjzkJR3MX0RNj1WIATu38V+N+5RnLemVlnmsEH2K1XPckd/WyeuJLYL rufememv3DGr2Q75c1V+5eTopKE2hKO51LBqKCOXWoofNumkeK4IFmyQymglSEcywCpX9 vEABVVLmrkM2Z6BV5HCsaKQcmtHxzGUe/FGZTRlzYh7SvaZZ6URfdS67bwpEvKwoXzUZc fnFJuEfgMear9v/xGhqfHBdXi1rc9MTOh11FUlT78EGGsFBTlAxsMoG+hBBDmIxjArB+n bYZHgaF69hmHXPOco/knvFU1xUlRpGJzdfayVtE79pp/gogi7QZrwwNg8Enx8HY32Og== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795017114; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Subject:Date: Message-ID:In-Reply-To:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=8Y1HCpFZlaidrgWFpk/K5x/UrGFMGKpcw+uVLtGpXCg=; b=CJRjaKuivS8pJRtwQQPdi9a2U+wGbRirUCpcmxJ4W++++9DtraGzrRmvTxOrRhw8sE1W 0f1ZgA6qKAJ6sRlJJhftti/Uf1Ov2B2tSCaHg5efXrE9XdMVnhvUnFUQIE11I5jLajYEe 8Tms0/dljU29YDfoGF5kXJAziELlnmoYYoZiwHzBgRP/Tj/2VKWtazy138mihalh6L17i ba6G1qzYTw5tPr/TAsO8YWa/sgNkA0sx/yUQGXGl68r7CHxjDb7gtAfGiUmsKAfcxFu7H qDxDk+UBc0rf8n7hikEHDmRIm2qo69UgXf2OP9xT0Eev4W16oSkQaKwHxUey5DCG7Uw== 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=Wf9Oy45A; 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 04629606A337; Wed, 18 Nov 2026 15:51:54 +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=Wf9Oy45A 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=1795017113; b=ymXIbVtdSsAsFipbFsJEUW6btwuaLsoQCf8Ky9E96lSqUTfb23xDiOEx283rlxhwZgAJ xbZ8hnWtCT9rODALZV93PVauT2VGKfqGfaigQuqrHROASghetnrDT+swBkaJaYXxNs/vQ FCqsbmXjb2h6KMw8C6U2krHC4Refa/85CemffPtk3PGUC1Cs0O642XIIhvoKg0SrjDYlE 5th77XlGzkZYTYNwLyLDoZqnvtczgqS8ZvTsORJNzovHnDJtl97ya8W2nTFm9QlN9P3qj vs/kCGyEUCOeoeVt1o1njfpLxBc/YbJCvWtJoBltWe2lRjL9C5BRFooB6cB5DfJDvZA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795017113; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=8Y1HCpFZlaidrgWFpk/K5x/UrGFMGKpcw+uVLtGpXCg=; b=rJr+1ScRhkwxaFgmhXOEjbuMEvJ4hAr4ERkaOWnJlmW65rh3tuW3NXF6qM00LPPgQYXH EMGoGooKRYQOcQiygRXaALelyYzJ4/ctKqdoCvIdjWHKMdNd9tFLT+/Bihor21zi7xzwq s6RaCwwJLcOsEI7XyTBLY/Nz0JBJF/reX+cBtU6fD+liVGUS5Xo3T8dhczDJ3pGfpLprK WIn/saubaHTCmTDV7c8dU7f7KynJixz7KfSLzhMMy+iU0U16SHI7yGx9k3UBCqq3Uy0PY CE+cmPrmAG66Mzy6eFUWY3qImhnU3IV7dcadz3Sbl7OT0dgQ5VrhIzqElR466stSeww== 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=Wf9Oy45A; 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 23CD2606A33A for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 15:51:52 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 934CD1F000CD; Wed, 18 Nov 2026 15:51:51 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795017112; bh=8Y1HCpFZlaidrgWFpk/K5x/UrGFMGKpcw+uVLtGpXCg=; h=From:To:Subject:Date:In-Reply-To:References; b=Wf9Oy45Aw4cHUKyPIap1a/y68VC5ka1j7e82zd40sBQvxJ8R/9479tpmQPMj/90XK CwVeiEd3aE+BbZu9kwXaAK0H+yNuDsFj0RhUAWYvNV3mmtBp+fGVGCNsib1FwBuJ1M zYjeuUrh6JVjSOYCmUNBixLztaE7P6QkZfeB8Of4cEAVc2ZPFpWv2yX529r6sp5Qjk frpmhswVdjCPW+FtUOQNgB2+KgBg75CxXdZfJHpf77no9l/kLsHUGK2vuVNQswzavl 0igrIspmuuR6qU9y7sIu4Tk6KSzTt1jc5f+cOXWgDqaTj7FR9H6/x64Oi0pAPBU4Oz 3Up6U+gBcKz+w== X-In-Reply-To: <20261118155144.18393-1-mason@kernel.org> 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