From: netdev-bot+sashiko@kernel.org
To: mason@kernel.org
Cc: 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: Re: [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update()
Date: Wed, 18 Nov 2026 18:23:03 +0000 [thread overview]
Message-ID: <179502618349.3136.1063676165373741119@kernel.org> (raw)
In-Reply-To: <20261118155144.18393-5-mason@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The fix is incomplete.
- [Low] The comment on TCP_RTT_MAX_US in include/net/tcp.h (lines
167-172) still says it is the 'Max RTT sample for tcp_rtt_estimator()'…
--
tcp: clamp the samples in tcp_rcv_rtt_update()
This patch clamps the sample passed to tcp_rcv_rtt_update() to
TCP_RTT_MAX_US before the shift left by 3. The goal is that a
receive-window fill time of 536.9 s or more no longer wraps in u32
arithmetic. The commit message says this covers both callers of
tcp_rcv_rtt_update().
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 69e038b9389ae..d9a66a1342efd 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;
[Severity: High]
Can a long window-fill time still wrap before it gets to this clamp?
In tcp_rcv_rtt_measure(), the sample comes from tcp_stamp_us_delta():
net/ipv4/tcp_input.c:tcp_rcv_rtt_measure() {
...
delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time);
if (!delta_us)
delta_us = 1;
tcp_rcv_rtt_update(tp, delta_us, 1);
...
}
That helper narrows the s64 difference to u32:
include/net/tcp.h:
static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0)
{
return max_t(s64, t1 - t0, 0);
}
So by the time min() sees an interval of 2^32 us (about 4295 s) or more,
it has already been reduced modulo 2^32.
For example, a 4300 s window-fill time arrives here as 5,032,704 us
(about 5.03 s). That passes the 120 s clamp unchanged. With win_dep=1 it
is stored when old_sample == 0 or when m < old_sample.
The only writer of rcv_rtt_est.time is the new_measure label in
tcp_rcv_rtt_measure(), and nothing resets a pending measurement when the
connection goes idle. The window-completing segment could arrive after
more than about 72 minutes of idle time or a slow sender. Would that
still hit the case the commit message describes, where "the wrapped
value is kept whenever it is below the current estimate", only with a
higher threshold?
Without timestamps the win_dep path only lowers the estimate. A bogus
small value would stay for the life of the connection.
Would it be better to clamp the 64-bit delta in tcp_rcv_rtt_measure()
before it is narrowed to u32?
[Severity: Low]
This isn't a bug, but the comment on TCP_RTT_MAX_US in include/net/tcp.h
still describes the constant only in terms of tcp_rtt_estimator() and the
RTO:
/* Max RTT sample for tcp_rtt_estimator(). srtt_us holds 8 times the RTT, and
* mdev_us and rttvar_us up to 4 times its deviation, all in u32, like the sum
* in __tcp_set_rto(). A larger sample could not raise the RTO, which
* TCP_RTO_MAX bounds.
*/
#define TCP_RTT_MAX_US (TCP_RTO_MAX_SEC * USEC_PER_SEC)
After this patch, tcp_rcv_rtt_update() also relies on 8 * TCP_RTT_MAX_US
fitting in u32 for rcv_rtt_est.rtt_us, which is not an input to
__tcp_set_rto(). tcp_rtt_tsopt_us() also uses the constant.
Could the header comment be extended to cover the receive-side users?
Alternatively, a static_assert could check that TCP_RTT_MAX_US << 3 fits
in a u32.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118155144.18393-1-mason%40kernel.org
next prev parent reply other threads:[~2026-11-18 18:23 UTC|newest]
Thread overview: 13+ 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 18:23 ` netdev-bot+sashiko
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 16:35 ` Eric Dumazet
2026-11-18 18:23 ` netdev-bot+sashiko
2026-11-18 15:51 ` [PATCH net v2 4/5] tcp: clamp the samples in tcp_rcv_rtt_update() Chris Mason
2026-11-18 16:34 ` Eric Dumazet
2026-11-18 18:23 ` netdev-bot+sashiko [this message]
2026-11-18 18:48 ` Chris Mason
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=179502618349.3136.1063676165373741119@kernel.org \
--to=netdev-bot+sashiko@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=mason@kernel.org \
--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