Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Chris Mason
Wed, 18 Nov 2026 15:51
[PATCH net v2 3/5] tcp: reject RTT samples from TSecr above 120 s
Author: Chris Mason
Date: Wed, 18 Nov 2026 15:51
Date: Wed, 18 Nov 2026 15:51
58 lines
9421 bytes
9421 bytes
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() takes the same sample for the RTT estimate of
the receive side.
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>
---
Notes:
v1->v2: no code change, the part on sample << 3 moved to patch 4
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 e796497b84be..69e038b9389a 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
Re: [PATCH net v2 3/5] tcp: reject RTT samples from TSecr above 120 s
Author: Eric Dumazet
Date: Wed, 18 Nov 2026 16:35
Date: Wed, 18 Nov 2026 16:35
30 lines
9960 bytes
9960 bytes
Le mer. 18 nov. 2026 à 16:51, 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() takes the same sample for the RTT estimate of
> the receive side.
>
> 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>
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Re: [PATCH net v2 3/5] tcp: reject RTT samples from TSecr above 120 s
Author: netdev-bot+sashiko
Date: Wed, 18 Nov 2026 18:23
Date: Wed, 18 Nov 2026 18:23
76 lines
10824 bytes
10824 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The header comment for TCP_RTT_MAX_US is out of date after this
patch.
--
tcp: reject RTT samples from TSecr above 120 s
This patch makes tcp_rtt_tsopt_us() reject any TSecr-derived RTT sample
above TCP_RTT_MAX_US (120 s), in both the usec and ms timestamp branches.
Before, samples of up to about 2,147 s were accepted. Both callers,
tcp_ack_update_rtt() and tcp_rcv_rtt_measure_ts(), now get no sample when
TSecr echoes a very old timestamp.
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index e796497b84be8..69e038b9389ae 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))) {
[Severity: Low]
This isn't a bug, but should the comment on TCP_RTT_MAX_US in
include/net/tcp.h be updated to match its new use here? It currently reads:
/* 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 comment names tcp_rtt_estimator() as the only user. The only reason
it gives for the value is u32 headroom for a saturating clamp.
With this patch the same constant is also the validity cutoff in
tcp_rtt_tsopt_us(). That cutoff covers more than the estimator: it
decides rs->rtt_us, the tcp_update_rtt_min() input, and whether
icsk_backoff is reset in tcp_ack_update_rtt(). It also gates the
receive-side estimate in tcp_rcv_rtt_measure_ts().
The later patch in the series, "tcp: clamp the samples in
tcp_rcv_rtt_update()", adds another user, and the header comment is still
unchanged at the end of the series.
Someone who changes TCP_RTO_MAX_SEC or TCP_RTT_MAX_US because of the u32
headroom reasoning would not see that this also moves the TSecr rejection
threshold. Could the header comment mention that the constant also bounds
valid TSecr samples?
> 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/20261118155144.18393-1-mason%40kernel.org
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads