From: Chris Mason <mason@kernel.org>
To: mason@kernel.org, edumazet@kernel.org, ncardwell@google.com,
kuniyu@google.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, willemb@google.com,
josef@toxicpanda.com, netdev@vger.kernel.org
Subject: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Date: Wed, 18 Nov 2026 10:51:48 -0500 [thread overview]
Message-ID: <20261118155144.18393-5-mason@kernel.org> (raw)
In-Reply-To: <20261118155144.18393-1-mason@kernel.org>
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
next prev parent reply other threads:[~2026-11-18 15:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 15:51 [PATCH net v2 0/5] tcp: avoid integer wraps in the RTT estimator and the RTO Chris Mason
2026-11-18 15:51 ` [PATCH net v2 1/5] tcp: don't let __tcp_set_rto() return 0 Chris Mason
2026-11-18 15:51 ` [PATCH net v2 2/5] tcp: clamp RTT samples in tcp_rtt_estimator() Chris Mason
2026-11-18 15:51 ` [PATCH net v2 3/5] tcp: reject RTT samples from TSecr above 120 s Chris Mason
2026-11-18 15:51 ` Chris Mason [this message]
2026-11-18 16:34 ` [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update() Eric Dumazet
2026-11-18 15:51 ` [PATCH net v2 5/5] tcp: bound the rto_min of a route in tcp_rto_min() Chris Mason
2026-11-18 16:33 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118155144.18393-5-mason@kernel.org \
--to=mason@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox