All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Eric Dumazet <edumazet@kernel.org>
Cc: Chris Mason <mason@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 13:36:29 +0000	[thread overview]
Message-ID: <20261118133629.1e9714b4@pumpkin> (raw)
In-Reply-To: <CAL4WiirGtN4e6HO-aEBU57507XxSdEz5b0oto45hbRA_0sivtw@mail.gmail.com>

On Wed, 18 Nov 2026 10:58:14 +0100
Eric Dumazet <edumazet@kernel.org> wrote:

> Le mer. 18 nov. 2026 à 01:50, Chris Mason <mason@kernel.org> a écrit :
> >
> > tcp_rtt_tsopt_us() returns the timestamp clock minus TSecr as an RTT
> > sample, and accepts up to 2,147 s. If TSecr echoes an old timestamp,
> > the sample is the age of that timestamp, not an RTT.
> >
> > tcp_ack_update_rtt() takes this sample for an ACK of retransmitted data.
> > tcp_rtt_estimator() clamps it to 120 s. The congestion control gets the
> > sample unclamped, in rs->rtt_us.
> >
> > 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.
> >
> > The fix used here is to reject a sample from TSecr above 120 s, for both
> > callers of tcp_rtt_tsopt_us().  
> 
> This only covers one of the two callers of tcp_rcv_rtt_update().
> 
> tcp_rcv_rtt_measure() is called from tcp_event_data_recv() for every
> data segment, with or without timestamps:
> 
> 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);
> 
> delta_us is the time the peer took to send one receive window. Any low
> rate flow can take more than 536.9 s for that, no bogus TSecr needed.
> 
> Then 'sample << 3' wraps, and since win_dep is 1, the wrapped value
> is kept whenever it is smaller than the current estimate:
> 
> if (old_sample == 0 || m < old_sample) {
>         new_sample = m;
> 
> For instance a 540 s sample ends up as rcv_rtt_est.rtt_us >> 3 == ~3.1 s.
> 
> We should also clamp in tcp_rcv_rtt_update(), like patch 2
> does in tcp_rtt_estimator(), so that both sources are covered [1]
> 
> With that, 'old_sample - (old_sample >> 3) + sample' converges to at
> most 8 * 120 s, which fits in u32 too.
> 
> >
> > An ACK of retransmitted data whose TSecr is more than 120 s old now
> > gives no RTT sample. So it no longer resets the backoff, as on a
> > connection without timestamps.
> >  
> 
> This seems fine to me. We send a retransmit at least every
> TCP_RTO_MAX, and the retransmit filling the hole updates TS.Recent on
> the receiver, so a well behaved peer does not echo a TSval that is more
> than 120 s old in an ACK of new data.
> 
> [1]
> Something like this on top of your patch (compile tested only):
> 
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 2d739cfdae8c33d12cd34e00388a29f0f4229806..708a989e5a63bb6ad67cc777d57815ae197c451e
> 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_t(u32, sample, TCP_RTT_MAX_US);

You can't need min_t() here.

David

> +       m = sample << 3;
> 
>         if (old_sample == 0 || m < old_sample) {
>                 new_sample = m;
> 
> Thanks.
> 


  reply	other threads:[~2026-11-18 13:36 UTC|newest]

Thread overview: 16+ 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 [this message]
2026-11-18 15:27       ` Eric Dumazet
2026-11-18 18:51         ` David Laight
2026-11-18 19:16           ` Chris Mason
2026-11-18 15:25   ` netdev-bot+sashiko

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=20261118133629.1e9714b4@pumpkin \
    --to=david.laight.linux@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.