Netdev List
 help / color / mirror / Atom feed
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 3/3] tcp: reject RTT samples from TSecr above 120 s
Date: Wed, 18 Nov 2026 15:25:25 +0000	[thread overview]
Message-ID: <179501552536.3136.7079470135971485944@kernel.org> (raw)
In-Reply-To: <20261118005048.53393-4-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: the u32 wrap of `sample << 3` in
  tcp_rcv_rtt_update() (net/ipv4/tcp_input.c:860) can still be reached.
- [Low] The patch gives TCP_RTT_MAX_US a second meaning but leaves its
  header comment as it was.

--

tcp: reject RTT samples from TSecr above 120 s

This commit makes tcp_rtt_tsopt_us() reject TSecr-derived RTT samples
above TCP_RTT_MAX_US (120 s), for both the usec and ms timestamp clocks.
Both callers are affected: tcp_ack_update_rtt() and
tcp_rcv_rtt_measure_ts(). The goal is to stop feeding the age of a stale
timestamp to the RTT estimator, the congestion control, and the u32
sample << 3 in tcp_rcv_rtt_update().

> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 10a23ee20e61d..8de54d9804e17 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -901,15 +901,16 @@ static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp)
>  	tp->rcv_rtt_est.time = tp->tcp_mstamp;
>  }
>  
> +/* A sample from TSecr above TCP_RTT_MAX_US is bogus, not large. */

[Severity: Low]
The header comment for TCP_RTT_MAX_US in include/net/tcp.h still
describes the constant only as a clamp for tcp_rtt_estimator():

    /* 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)

That matches how tcp_rtt_estimator() uses it, where a larger sample is
clamped and then used:

    long m = min(mrtt_us, TCP_RTT_MAX_US); /* RTT */

Here the same constant becomes a threshold for rejecting a sample. The
TSecr path, tcp_rcv_rtt_measure_ts()->tcp_rcv_rtt_update(), also now
depends on TCP_RTT_MAX_US * 8 fitting in u32.

Should the header comment mention this second use? As it stands, a later
change that raises TCP_RTO_MAX_SEC above about 536 would bring the wrap
back silently, and no BUILD_BUG_ON guards against that.

>  static s32 tcp_rtt_tsopt_us(const struct tcp_sock *tp, u32 min_delta)
>  {
>  	u32 delta, delta_us;
>  
>  	delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr;
>  	if (tp->tcp_usec_ts)
> -		return delta;
> +		return delta <= TCP_RTT_MAX_US ? delta : -1;
>  
> -	if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) {
> +	if (likely(delta <= TCP_RTT_MAX_US / (USEC_PER_SEC / TCP_TS_HZ))) {

[Severity: High]
The commit message says:

  tcp_rcv_rtt_measure_ts() passes the sample to tcp_rcv_rtt_update(),
  which computes sample << 3 in u32 arithmetic. That wraps from 536.9 s
  on.

Can that wrap in tcp_rcv_rtt_update() still be reached through its other
caller, tcp_rcv_rtt_measure()?

tcp_event_data_recv()->tcp_rcv_rtt_measure() runs on in-order data, with
or without timestamps. Nothing bounds its sample:

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);
    ...
}

rcv_rtt_est.time is only refreshed once rcv_nxt reaches rcv_rtt_est.seq.
Suppose the peer completes one measurement, stays idle for more than
2^29 us (about 536.9 s), and then sends a window of data. delta_us is
then above 2^29, and the shift wraps:

net/ipv4/tcp_input.c:tcp_rcv_rtt_update() {
	u32 new_sample, old_sample = tp->rcv_rtt_est.rtt_us;
	long m = sample << 3;

	if (old_sample == 0 || m < old_sample) {
		new_sample = m;
	} else {
		...
		if (win_dep)
			return;
    ...
}

If delta_us lands within about one RTT past a multiple of 2^29 us, the
wrapped m is below old_sample. It is accepted, and rcv_rtt_est.rtt_us
ends up near zero.

With win_dep=1, every later, larger and correct sample hits the early
return. So on connections without timestamps, the bad value appears to
stay for the life of the connection. Several things read it: receive
buffer autotuning in tcp_rcv_space_adjust() and tcp_rcvbuf_grow(),
tcpi_rcv_rtt, and MPTCP.

Would it make sense to bound sample, or do the shift in 64 bits, inside
tcp_rcv_rtt_update()? That would cover both callers, not only the TSecr
source.

>  		if (!delta)
>  			delta = min_delta;
>  		delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118005048.53393-1-mason%40kernel.org

      parent reply	other threads:[~2026-11-18 15:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  0:50 [PATCH net 0/3] tcp: avoid integer wraps in the RTT estimator and the RTO Chris Mason
2026-11-18  0:50 ` [PATCH net 1/3] tcp: don't let __tcp_set_rto() return 0 Chris Mason
2026-11-18 10:08   ` Eric Dumazet
2026-11-18 13:33   ` David Laight
2026-11-18 15:25   ` netdev-bot+sashiko
2026-11-18 15:37     ` Chris Mason
2026-11-18  0:50 ` [PATCH net 2/3] tcp: clamp RTT samples in tcp_rtt_estimator() Chris Mason
2026-11-18  9:46   ` Eric Dumazet
2026-11-18 15:25   ` netdev-bot+sashiko
2026-11-18  0:50 ` [PATCH net 3/3] tcp: reject RTT samples from TSecr above 120 s Chris Mason
2026-11-18  9:58   ` Eric Dumazet
2026-11-18 13:36     ` David Laight
2026-11-18 15:27       ` Eric Dumazet
2026-11-18 15:25   ` netdev-bot+sashiko [this message]

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=179501552536.3136.7079470135971485944@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