Skip to contentSkip to conversation

tcp: make probe0 timer handle expired user timeout

PATCH Superseded Altan Hacigumus 4 participants 10 messages Apr 14 – Apr 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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().

Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")
---
 net/ipv4/tcp_timer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_timer.c +4 -1
index 5a14a53a3c9e..4a43356a4e06 100644
@@ -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
maintainer
#1 lore raw
Quoted 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 configured TCP_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")

Hi Eric, Neal, does this makes sense?

Quoted 23 lines
net/ipv4/tcp_timer.c +4 -1
index 5a14a53a3c9e..4a43356a4e06 100644
@@ -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);
#2 lore raw
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 configured TCP_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")

Hi Eric, Neal, does this makes sense?

I missed this patch. I will take a look asap.
Thanks.

#3 lore raw
In reply to Altan Hacigumus
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 configured TCP_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")
---
 net/ipv4/tcp_timer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_timer.c +2 -1
index 5a14a53a3c9e..4a43356a4e06 100644
@@ -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 -1
        remaining = max_t(u32, remaining, TCP_TIMEOUT_MIN);
 
        return min_t(u32, remaining, when);
--

2.43.0

#4 lore raw
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 configured TCP_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")
---
 net/ipv4/tcp_timer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_timer.c +2 -1
index 5a14a53a3c9e..4a43356a4e06 100644
@@ -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 -1
        remaining = max_t(u32, remaining, TCP_TIMEOUT_MIN);
 
        return min_t(u32, remaining, when);
--

2.43.0

Thanks

#5 lore raw
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 configured TCP_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")
---
 net/ipv4/tcp_timer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_timer.c +2 -1
index 5a14a53a3c9e..4a43356a4e06 100644
@@ -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_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.

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.

#6 lore raw
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 configured TCP_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")
---
 net/ipv4/tcp_timer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/tcp_timer.c +2 -1
index 5a14a53a3c9e..4a43356a4e06 100644
@@ -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));

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_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 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_TIMEOUT users.

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.

#7 lore raw

PATCH v2 1/1 tcp: make probe0 timer handle expired user timeout

In reply to 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 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.

Fixes 344db93ae3ee ("tcp: make TCP_USER_TIMEOUT accurate for zero window probes")

---
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
index 8d791a954cd6..322db13333c7 100644
@@ -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
Reviewed-by on v2 1/1
#8 lore raw
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 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.

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")

---

#9 lore raw
In reply to Altan Hacigumus
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 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.

[...]

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