Netdev List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Chris Mason <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 1/3] tcp: don't let __tcp_set_rto() return 0
Date: Wed, 18 Nov 2026 13:33:10 +0000	[thread overview]
Message-ID: <20261118133310.6a2c48da@pumpkin> (raw)
In-Reply-To: <20261118005048.53393-2-mason@kernel.org>

On Tue, 17 Nov 2026 19:50:49 -0500
Chris Mason <mason@kernel.org> wrote:

> __tcp_set_rto() computes the RTO as (srtt_us >> 3) + rttvar_us, in u32
> arithmetic and with no lower bound. A comment in tcp_set_rto() says that
> the algorithm guarantees an RTO above TCP_RTO_MIN. But tcp_rto_min() is
> only applied to rttvar_us, so that guarantee is lost if the sum wraps.
> 
> tcp_retransmit_timer() backs off by doubling icsk_rto, so the backoff
> only works if icsk_rto is nonzero.
> 
> Of the three callers, only the thin-stream branch of
> tcp_retransmit_timer() clamps the result. tcp_set_rto() and
> tcp_ld_RTO_revert() store it in icsk_rto with an upper bound only.
> 
> The fix used here is to keep the result of __tcp_set_rto() from 0, for
> all of its callers, so that the backoff recovers from any state of the
> RTT estimator.
> 
> Found by LLM code inspection, and confirmed with LLM generated
> reproducers on an unmodified kernel. Fixed by LLM, and tested with
> the reproducers and existing kernel selftests.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Chris Mason <mason@kernel.org>
> ---
>  include/net/tcp.h    | 4 +++-
>  net/ipv4/tcp_input.c | 5 +++--
>  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 5c9203aae834..6a714189bcc7 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -910,7 +910,9 @@ static inline void tcp_bound_rto(struct sock *sk)
>  
>  static inline u32 __tcp_set_rto(const struct tcp_sock *tp)
>  {
> -	return usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us);
> +	u32 rto = usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us);
> +
> +	return max(rto, 1U);

	return rto ?: 1;
is possibly more readable?

David

>  }
>  
>  static inline unsigned long tcp_reqsk_timeout(struct request_sock *req)
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index a2074a1af422..f65697bc96c9 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -1221,8 +1221,9 @@ void tcp_set_rto(struct sock *sk)
>  	 *    with correct one. It is exactly, which we pretend to do.
>  	 */
>  
> -	/* NOTE: clamping at TCP_RTO_MIN is not required, current algo
> -	 * guarantees that rto is higher.
> +	/* NOTE: clamping at tcp_rto_min() is not required, tcp_rtt_estimator()
> +	 * applies it to rttvar_us. But rto must never be 0, which exponential
> +	 * backoff could not leave: __tcp_set_rto() takes care of that.
>  	 */
>  	tcp_bound_rto(sk);
>  }


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

Thread overview: 9+ 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 [this message]
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  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

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=20261118133310.6a2c48da@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox