* [PATCH net 1/3] tcp: don't let __tcp_set_rto() return 0
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 ` Chris Mason
2026-11-18 10:08 ` Eric Dumazet
2026-11-18 13:33 ` David Laight
2026-11-18 0:50 ` [PATCH net 2/3] tcp: clamp RTT samples in tcp_rtt_estimator() Chris Mason
2026-11-18 0:50 ` [PATCH net 3/3] tcp: reject RTT samples from TSecr above 120 s Chris Mason
2 siblings, 2 replies; 9+ messages in thread
From: Chris Mason @ 2026-11-18 0:50 UTC (permalink / raw)
To: mason, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
willemb, josef, netdev
__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);
}
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);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net 1/3] tcp: don't let __tcp_set_rto() return 0
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
1 sibling, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2026-11-18 10:08 UTC (permalink / raw)
To: Chris Mason
Cc: ncardwell, kuniyu, davem, kuba, pabeni, horms, willemb, josef,
netdev
Le mer. 18 nov. 2026 à 01:50, Chris Mason <mason@kernel.org> a écrit :
>
> __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.
>
The wrap is what patch 2 fixes. Once samples are clamped to 120 s,
the sum is bounded by ~600 s and can not wrap anymore, so this
paragraph no longer justifies the patch.
Also, usecs_to_jiffies() rounds up, so a wrapped sum only gives
rto == 0 if it lands exactly on 0 modulo 2^32. Any other value gives
at least one jiffy, and the backoff recovers from that.
There is another way to get 0, with no wrap, and I think this is the
one the changelog should describe:
tcp_rto_min() can return 0 if the route has a locked RTAX_RTO_MIN
metric of 0. ip_metrics_convert() only rejects a zero locked cwnd.
All other knobs have a non zero floor (tcp_rto_min_us sysctl,
TCP_RTO_MIN_US, TCP_BPF_RTO_MIN).
Then a first RTT sample of 0 usec gives:
srtt_us = max(1U, 0 << 3) = 1
mdev_us = 0
rttvar_us = max(mdev_us, tcp_rto_min_us(sk)) = 0
__tcp_set_rto() = usecs_to_jiffies((1 >> 3) + 0) = 0
A 0 usec sample is possible with usec TS, because tcp_rtt_tsopt_us()
returns delta before min_delta is applied in that case.
> 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")
Linux-2.6.12-rc2 had no rto_min setting at all. rttvar was floored
by the TCP_RTO_MIN constant, and tcp_rtt_estimator() had:
if (m == 0)
m = 1;
So the comment was correct at that time, wraps aside.
The configurable minimum came with:
Fixes: 05bb1fad1cde ("[TCP]: Allow minimum RTO to be configurable via
routing metrics.")
Please use this tag and reword the changelog in v2, or drop the
Fixes: tag and send this one to net-next as hardening, since it needs
a zero locked rto_min route metric.
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH net 1/3] tcp: don't let __tcp_set_rto() return 0
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
1 sibling, 0 replies; 9+ messages in thread
From: David Laight @ 2026-11-18 13:33 UTC (permalink / raw)
To: Chris Mason
Cc: edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms, willemb,
josef, netdev
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);
> }
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net 2/3] tcp: clamp RTT samples in tcp_rtt_estimator()
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 0:50 ` 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
2 siblings, 1 reply; 9+ messages in thread
From: Chris Mason @ 2026-11-18 0:50 UTC (permalink / raw)
To: mason, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
willemb, josef, netdev
tcp_rtt_estimator() keeps its state in u32 fields, in microseconds.
srtt_us holds 8 times the smoothed RTT, so it wraps at an RTT of
536.9 s. Samples can be larger than that:
- For an ACK of retransmitted data, the sample is the timestamp clock
minus TSecr, and tcp_rtt_tsopt_us() accepts a sample of up to 2,147 s.
- For a SACK of a segment that was never retransmitted, the sample is
the age of that segment.
Samples from TSecr could wrap these fields when they still held jiffies.
The age of a segment can wrap them since commit 740b0f1841f6 ("tcp:
switch rtt estimations to usec resolution"), which took the wrap of the
smoothed RTT from 2^29 jiffies to 2^29 us.
The fix used here is to clamp each sample to 120 s, the largest possible
RTO, in tcp_rtt_estimator(), where the samples of all sources meet.
The smoothed RTT now saturates at 120 s. A path with a larger real RTT
sees that in TCP_INFO, in the pacing rate and in the metrics cache.
Found by code inspection (Eric Dumazet), 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")
Fixes: 740b0f1841f6 ("tcp: switch rtt estimations to usec resolution")
Signed-off-by: Chris Mason <mason@kernel.org>
---
include/net/tcp.h | 7 +++++++
net/ipv4/tcp_input.c | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 6a714189bcc7..a617a72ee2c6 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -164,6 +164,13 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX);
#define TCP_TIMEOUT_MIN_US (2*USEC_PER_MSEC) /* Min TCP timeout in microsecs */
+/* 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)
+
#define TCP_TIMEOUT_INIT ((unsigned)(1*HZ)) /* RFC6298 2.1 initial RTO value */
#define TCP_TIMEOUT_FALLBACK ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value, now
* used as a fallback RTO for the
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index f65697bc96c9..10a23ee20e61 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1098,7 +1098,7 @@ static void tcp_event_data_recv(struct sock *sk, struct sk_buff *skb)
static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
{
struct tcp_sock *tp = tcp_sk(sk);
- long m = mrtt_us; /* RTT */
+ long m = min(mrtt_us, TCP_RTT_MAX_US); /* RTT */
u32 srtt = tp->srtt_us;
/* The following amusing code comes from Jacobson's
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net 2/3] tcp: clamp RTT samples in tcp_rtt_estimator()
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
0 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2026-11-18 9:46 UTC (permalink / raw)
To: Chris Mason
Cc: ncardwell, kuniyu, davem, kuba, pabeni, horms, willemb, josef,
netdev
Le mer. 18 nov. 2026 à 01:50, Chris Mason <mason@kernel.org> a écrit :
>
> tcp_rtt_estimator() keeps its state in u32 fields, in microseconds.
> srtt_us holds 8 times the smoothed RTT, so it wraps at an RTT of
> 536.9 s. Samples can be larger than that:
>
> - For an ACK of retransmitted data, the sample is the timestamp clock
> minus TSecr, and tcp_rtt_tsopt_us() accepts a sample of up to 2,147 s.
>
> - For a SACK of a segment that was never retransmitted, the sample is
> the age of that segment.
>
> Samples from TSecr could wrap these fields when they still held jiffies.
> The age of a segment can wrap them since commit 740b0f1841f6 ("tcp:
> switch rtt estimations to usec resolution"), which took the wrap of the
> smoothed RTT from 2^29 jiffies to 2^29 us.
>
> The fix used here is to clamp each sample to 120 s, the largest possible
> RTO, in tcp_rtt_estimator(), where the samples of all sources meet.
>
> The smoothed RTT now saturates at 120 s. A path with a larger real RTT
> sees that in TCP_INFO, in the pacing rate and in the metrics cache.
>
> Found by code inspection (Eric Dumazet), 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")
> Fixes: 740b0f1841f6 ("tcp: switch rtt estimations to usec resolution")
> Signed-off-by: Chris Mason <mason@kernel.org>
> ---
> include/net/tcp.h | 7 +++++++
> net/ipv4/tcp_input.c | 2 +-
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 6a714189bcc7..a617a72ee2c6 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -164,6 +164,13 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX);
>
> #define TCP_TIMEOUT_MIN_US (2*USEC_PER_MSEC) /* Min TCP timeout in microsecs */
>
> +/* 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)
> +
> #define TCP_TIMEOUT_INIT ((unsigned)(1*HZ)) /* RFC6298 2.1 initial RTO value */
> #define TCP_TIMEOUT_FALLBACK ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value, now
> * used as a fallback RTO for the
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index f65697bc96c9..10a23ee20e61 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -1098,7 +1098,7 @@ static void tcp_event_data_recv(struct sock *sk, struct sk_buff *skb)
> static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
> {
> struct tcp_sock *tp = tcp_sk(sk);
> - long m = mrtt_us; /* RTT */
> + long m = min(mrtt_us, TCP_RTT_MAX_US); /* RTT */
> u32 srtt = tp->srtt_us;
>
Nit: the two tcp_bpf_rtt(sk, mrtt_us, srtt) calls below still pass the
unclamped sample, next to an srtt computed from the clamped one.
Maybe clamp the argument instead:
mrtt_us = min(mrtt_us, TCP_RTT_MAX_US);
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net 3/3] tcp: reject RTT samples from TSecr above 120 s
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 0:50 ` [PATCH net 2/3] tcp: clamp RTT samples in tcp_rtt_estimator() Chris Mason
@ 2026-11-18 0:50 ` Chris Mason
2026-11-18 9:58 ` Eric Dumazet
2 siblings, 1 reply; 9+ messages in thread
From: Chris Mason @ 2026-11-18 0:50 UTC (permalink / raw)
To: mason, edumazet, ncardwell, kuniyu, davem, kuba, pabeni, horms,
willemb, josef, netdev
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().
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.
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>
---
net/ipv4/tcp_input.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 10a23ee20e61..8de54d9804e1 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. */
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))) {
if (!delta)
delta = min_delta;
delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ);
--
2.55.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH net 3/3] tcp: reject RTT samples from TSecr above 120 s
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
0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2026-11-18 9:58 UTC (permalink / raw)
To: Chris Mason
Cc: ncardwell, kuniyu, davem, kuba, pabeni, horms, willemb, josef,
netdev
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);
+ m = sample << 3;
if (old_sample == 0 || m < old_sample) {
new_sample = m;
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH net 3/3] tcp: reject RTT samples from TSecr above 120 s
2026-11-18 9:58 ` Eric Dumazet
@ 2026-11-18 13:36 ` David Laight
0 siblings, 0 replies; 9+ messages in thread
From: David Laight @ 2026-11-18 13:36 UTC (permalink / raw)
To: Eric Dumazet
Cc: Chris Mason, ncardwell, kuniyu, davem, kuba, pabeni, horms,
willemb, josef, netdev
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.
>
^ permalink raw reply [flat|nested] 9+ messages in thread