tcp: make probe0 timer handle expired user timeout
Subsystems (3)
PATCH 1/1 tcp: make probe0 timer handle expired user timeout
tcp_clamp_probe0_to_user_timeout() computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configured TCP_USER_TIMEOUT, the subtraction underflows and yields a large value.
Handle this expiration case similarly to tcp_clamp_rto_to_user_timeout().
--- net/ipv4/tcp_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_timer.c +4 -1
@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);
@@ -61,6 +62,8 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; +if (remaining <=0 ) +return 1 ; remaining =max_t (u32, remaining,TCP_TIMEOUT_MIN );return min_t (u32, remaining, when);
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 9 lines · On Mon, 13 Apr 2026 18:36:34 -0700 Altan Hacigumus wrote:
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configuredTCP_USER_TIMEOUT, the subtraction underflows and yields a large value.Handle this expiration case similarly to
tcp_clamp_rto_to_user_timeout().Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>
Hi Eric, Neal, does this makes sense?
Quoted 23 lines
net/ipv4/tcp_timer.c +4
-1@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);@@ -61,6 +62,8 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; +if (remaining <=0 ) +return 1 ; remaining =max_t (u32, remaining,TCP_TIMEOUT_MIN );return min_t (u32, remaining, when);
Quoted 7 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 13 Apr 2026 18:36:34 -0700 Altan Hacigumus wrote:
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configuredTCP_USER_TIMEOUT, the subtraction underflows and yields a large value.
Quoted 7 lines
Quoted 4 lines
Handle this expiration case similarly to
tcp_clamp_rto_to_user_timeout().Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>Hi Eric, Neal, does this makes sense?
I missed this patch. I will take a look asap.
Thanks.
Quoted 29 lines · Altan Hacigumus
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configuredTCP_USER_TIMEOUT, the subtraction underflows and yields a large value.Handle this expiration case similarly to
tcp_clamp_rto_to_user_timeout().Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>--- net/ipv4/tcp_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/ipv4/tcp_timer.c +2
-1@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);
net/ipv4/tcp_timer.c u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) · line 66
Quoted 5 lines
net/ipv4/tcp_timer.c +2
-0@@ -61,6 +62,8 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; +if (remaining <=0 ) +return 1 ;
I do not think this chunk is needed ?
If @remaining is signed, then perhaps change the following line to:
remaining = max_t(int, remaining, TCP_TIMEOUT_MIN);
Also, it would be great to have a new packetdrill test.
Quoted 6 lines
net/ipv4/tcp_timer.c +0
-1remaining =max_t (u32, remaining,TCP_TIMEOUT_MIN );return min_t (u32, remaining, when); --2.43.0
Quoted 40 lines · Eric Dumazet
Quoted 29 lines · Altan Hacigumus
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configuredTCP_USER_TIMEOUT, the subtraction underflows and yields a large value.Handle this expiration case similarly to
tcp_clamp_rto_to_user_timeout().Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>--- net/ipv4/tcp_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/ipv4/tcp_timer.c +2
-1@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);net/ipv4/tcp_timer.c u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) · line 66
Quoted 5 lines
net/ipv4/tcp_timer.c +2
-0@@ -61,6 +62,8 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; +if (remaining <=0 ) +return 1 ;I do not think this chunk is needed ?
If @remaining is signed, then perhaps change the following line to:
Quoted 2 lines
remaining =
max_t(int, remaining, TCP_TIMEOUT_MIN);
The if (remaining <= 0) return 1 handles the already-expired case and mirrors the logic in tcp_clamp_rto_to_user_timeout().
max_t(s32, remaining, TCP_TIMEOUT_MIN) with remaining changed to s32 also fixes the underflow; I used the explicit early return for symmetry with the RTO helper, but I can switch that in v2 if you prefer.
Quoted 2 lines
Also, it would be great to have a new packetdrill test.
With packetdrill, AFAICS it would require a late ACK to be processed after TCP_USER_TIMEOUT has elapsed but before tcp_probe_timer() runs the abort check - i.e. a race between the RX softirq path and the timer. This is not purely an event/packet ordering problem, so it is not clear to me how a deterministic behavior can be simulated with packetdrill without tying it to exact probe timing.
Quoted 6 lines
Quoted 6 lines
net/ipv4/tcp_timer.c +0
-1remaining =max_t (u32, remaining,TCP_TIMEOUT_MIN );return min_t (u32, remaining, when); --2.43.0
Thanks
Quoted 42 lines · Altan Hacigumus
Quoted 40 lines · Eric Dumazet
Quoted 29 lines · Altan Hacigumus
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configuredTCP_USER_TIMEOUT, the subtraction underflows and yields a large value.Handle this expiration case similarly to
tcp_clamp_rto_to_user_timeout().Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>--- net/ipv4/tcp_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/ipv4/tcp_timer.c +2
-1@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);net/ipv4/tcp_timer.c u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) · line 66
Quoted 5 lines
net/ipv4/tcp_timer.c +2
-0@@ -61,6 +62,8 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; +if (remaining <=0 ) +return 1 ;I do not think this chunk is needed ?
If @remaining is signed, then perhaps change the following line to:
Quoted 5 lines
Quoted 2 lines
remaining =
max_t(int, remaining, TCP_TIMEOUT_MIN);The if (remaining <= 0) return 1 handles the already-expired case and mirrors the logic in
tcp_clamp_rto_to_user_timeout().
tcp_clamp_rto_to_user_timeout() has two conditionals.
if (remaining <= 0)
return 1;
return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(remaining));
First one was to avoid to call msecs_to_jiffies() with a negative number.
tcp_clamp_probe0_to_user_timeout() has 3 tests already, you want to add a fourth one...
I would prefer something less obscure.
We do not care if we return 1 or 2 (TCP_TIMEOUT_MIN) jiffies
Quoted 8 lines
max_t(s32, remaining, TCP_TIMEOUT_MIN)with remaining changed to s32 also fixes the underflow; I used the explicit early return for symmetry with the RTO helper, but I can switch that in v2 if you prefer.Quoted 2 lines
Also, it would be great to have a new packetdrill test.
Quoted 6 lines
With packetdrill, AFAICS it would require a late ACK to be processed after
TCP_USER_TIMEOUThas elapsed but beforetcp_probe_timer()runs the abort check - i.e. a race between the RX softirq path and the timer. This is not purely an event/packet ordering problem, so it is not clear to me how a deterministic behavior can be simulated with packetdrill without tying it to exact probe timing.
I was trying to sense if the bug was serious or not, considering last tcp_clamp_probe0_to_user_timeout()
statement is:
return min_t(u32, remaining, when);
Perhaps you should give more details in the changelog. What were the symptoms of this bug, for TCP_USER_TIMEOUT users.
Quoted 56 lines · Eric Dumazet
Quoted 42 lines · Altan Hacigumus
Quoted 40 lines · Eric Dumazet
Quoted 29 lines · Altan Hacigumus
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time already exceeds the configuredTCP_USER_TIMEOUT, the subtraction underflows and yields a large value.Handle this expiration case similarly to
tcp_clamp_rto_to_user_timeout().Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>--- net/ipv4/tcp_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/ipv4/tcp_timer.c +2
-1@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);net/ipv4/tcp_timer.c u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) · line 66
Quoted 5 lines
net/ipv4/tcp_timer.c +2
-0@@ -61,6 +62,8 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; +if (remaining <=0 ) +return 1 ;I do not think this chunk is needed ?
If @remaining is signed, then perhaps change the following line to:Quoted 5 lines
Quoted 2 lines
remaining =
max_t(int, remaining, TCP_TIMEOUT_MIN);The if (remaining <= 0) return 1 handles the already-expired case and mirrors the logic in
tcp_clamp_rto_to_user_timeout().
tcp_clamp_rto_to_user_timeout()has two conditionals.if (remaining <= 0)
return 1;
returnmin_t(u32, icsk->icsk_rto, msecs_to_jiffies(remaining));
Quoted 7 lines
First one was to avoid to call
msecs_to_jiffies()with a negative number.
tcp_clamp_probe0_to_user_timeout()has 3 tests already, you want to add a fourth one...
I would prefer something less obscure.
We do not care if we return 1 or 2 (TCP_TIMEOUT_MIN) jiffies
okay
Quoted 15 lines
Quoted 8 lines
max_t(s32, remaining, TCP_TIMEOUT_MIN)with remaining changed to s32 also fixes the underflow; I used the explicit early return for symmetry with the RTO helper, but I can switch that in v2 if you prefer.Quoted 2 lines
Also, it would be great to have a new packetdrill test.
Quoted 6 lines
With packetdrill, AFAICS it would require a late ACK to be processed after
TCP_USER_TIMEOUThas elapsed but beforetcp_probe_timer()runs the abort check - i.e. a race between the RX softirq path and the timer. This is not purely an event/packet ordering problem, so it is not clear to me how a deterministic behavior can be simulated with packetdrill without tying it to exact probe timing.
Quoted 8 lines
I was trying to sense if the bug was serious or not, considering last
tcp_clamp_probe0_to_user_timeout()
statement is:return
min_t(u32, remaining, when);Perhaps you should give more details in the changelog. What were the symptoms of this bug, for
TCP_USER_TIMEOUTusers.
Yes, it at least clamps to @when, but still caused connection teardowns to be intermittently delayed beyond the user's explicit timeout sockopt.
Will send a v2 accordingly.
Thanks.
PATCH v2 1/1 tcp: make probe0 timer handle expired user timeout
In reply to Altan Hacigumustcp_clamp_probe0_to_user_timeout() computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time exceeds the configured TCP_USER_TIMEOUT, the underflow yields a large value.
This ends up re-arming the probe timer for a full backoff interval instead of expiring immediately, delaying connection teardown beyond the configured timeout.
Fix this by preventing underflow so user-set timeout expiration is handled correctly without extending the probe timer.
---
v2:
- Use the existing TCP_TIMEOUT_MIN clamping along with signed @remaining
--- net/ipv4/tcp_timer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/tcp_timer.c +3 -2
@@ -50,7 +50,8 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)u32 tcp_clamp_probe0_to_user_timeout (const struct sock *sk,u32 when) {const struct inet_connection_sock *icsk =inet_csk (sk); -u32 remaining, user_timeout; +u32 user_timeout; +s32 remaining;s32 elapsed; user_timeout =READ_ONCE (icsk->icsk_user_timeout);
@@ -61,7 +62,7 @@ u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)if (unlikely (elapsed <0 )) elapsed =0 ; remaining =msecs_to_jiffies (user_timeout) - elapsed; - remaining =max_t (u32, remaining,TCP_TIMEOUT_MIN ); + remaining =max_t (int, remaining,TCP_TIMEOUT_MIN );return min_t (u32, remaining, when); }
Signature · 1 line
2.43.0
Quoted 10 lines · Altan Hacigumus
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time exceeds the configuredTCP_USER_TIMEOUT, the underflow yields a large value.This ends up re-arming the probe timer for a full backoff interval instead of expiring immediately, delaying connection teardown beyond the configured timeout.
Quoted 7 lines
Fix this by preventing underflow so user-set timeout expiration is handled correctly without extending the probe timer.
Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")Signed-off-by Altan Hacigumus <[email protected]>---
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 23 Apr 2026 18:46:38 -0700 you wrote:
tcp_clamp_probe0_to_user_timeout()computes remaining time in jiffies using subtraction with an unsigned lvalue. If elapsed probing time exceeds the configuredTCP_USER_TIMEOUT, the underflow yields a large value.This ends up re-arming the probe timer for a full backoff interval instead of expiring immediately, delaying connection teardown beyond the configured timeout.
[...]
Here is the summary with links:
- [net,v2] tcp: make probe0 timer handle expired user timeout
https://git.kernel.org/netdev/net/c/2b9f6f7065d4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html