Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Yingjie Wang
Sat, 14 Nov 2026 16:12
[PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout
Author: Yingjie Wang
Date: Sat, 14 Nov 2026 16:12
Date: Sat, 14 Nov 2026 16:12
70 lines
23216 bytes
23216 bytes
tcp_fastopen_active_should_disable() calculates the active-disable
interval as multiplier * tfo_bh_timeout * HZ. Since all operands are
32-bit, a large tcp_fastopen_blackhole_timeout_sec can wrap the delay
even on 64-bit kernels and re-enable active Fast Open too soon.
For example, with HZ=1000, a timeout of 6912213 seconds and the maximum
multiplier of 64 should produce 442,381,632,000 jiffies, but the current
calculation truncates it to 512 jiffies.
This issue was found using a static analysis tool. A loopback reproducer
induced 12 Fast Open blackholes and waited 1.2 seconds before opening
another connection. In the v1 arithmetic-only test, the unpatched kernel
retried active Fast Open, while the fixed kernel used a regular TCP
handshake. The reproducer required neither kernel modifications nor
fault injection. The input limit added here rejects that large setting.
Compute the interval in u64 and cap it at MAX_JIFFY_OFFSET before adding
it to the saved timestamp. Also limit the writable initial timeout to one
day, so the exponential backoff does not start from an impractically long
period. Even at this limit, a 64-fold backoff with HZ=1000 exceeds the
32-bit range, so the wider calculation and jiffies cap are still needed.
On the v2 kernel, the sysctl accepts 86400 seconds and rejects 86401,
leaving the previous value unchanged.
Fixes: cf1ef3f0719b ("net/tcp_fastopen: Disable active side TFO in certain scenarios")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
Documentation/networking/ip-sysctl.rst | 1 +
net/ipv4/sysctl_net_ipv4.c | 1 +
net/ipv4/tcp_fastopen.c | 12 +++++++++---
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index d3523c9064a2..d1e66feb0153 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1055,6 +1055,7 @@ tcp_fastopen_blackhole_timeout_sec - INTEGER
get detected right after Fastopen is re-enabled and will reset to
initial value when the blackhole issue goes away.
0 to disable the blackhole detection.
+ The maximum value is one day (86400 seconds).
By default, it is set to 0 (feature is disabled).
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index bf193e7ec516..5bc357e189bd 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -1152,6 +1152,7 @@ static const struct ctl_table ipv4_net_table[] = {
.mode = 0644,
.proc_handler = proc_tfo_blackhole_detect_timeout,
.extra1 = SYSCTL_ZERO,
+ .extra2 = &one_day_secs,
},
#ifdef CONFIG_IP_ROUTE_MULTIPATH
{
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 7f7eb3cc1c04..883f0f1e7e07 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -613,6 +613,7 @@ bool tcp_fastopen_active_should_disable(struct sock *sk)
unsigned long timeout;
int tfo_da_times;
int multiplier;
+ u64 delay;
if (!tfo_bh_timeout)
return false;
@@ -624,12 +625,17 @@ bool tcp_fastopen_active_should_disable(struct sock *sk)
/* Paired with smp_mb__before_atomic() in tcp_fastopen_active_disable() */
smp_rmb();
- /* Limit timeout to max: 2^6 * initial timeout */
+ /* Limit the backoff multiplier to 64. */
multiplier = 1 << min(tfo_da_times - 1, 6);
+ delay = (u64)multiplier * tfo_bh_timeout * HZ;
- /* Paired with the WRITE_ONCE() in tcp_fastopen_active_disable(). */
+ /*
+ * Cap the delay for safe jiffies comparisons on 32-bit systems.
+ * The timestamp read is paired with WRITE_ONCE() in
+ * tcp_fastopen_active_disable().
+ */
timeout = READ_ONCE(sock_net(sk)->ipv4.tfo_active_disable_stamp) +
- multiplier * tfo_bh_timeout * HZ;
+ min(delay, MAX_JIFFY_OFFSET);
if (time_before(jiffies, timeout))
return true;
--
2.43.0
Re: [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 05:21
Date: Mon, 16 Nov 2026 05:21
117 lines
12875 bytes
12875 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch adds a new upper bound, `.extra2 = &one_day_secs`
(86400), to `net.ipv4.tcp_fastopen_blackhole_timeout_sec` in…
- [Low] The commit body of "tcp: avoid wrapping Fast Open blackhole
timeout" refers to patch revisions: 'In the v1 arithmetic-only test,…
--
tcp: avoid wrapping Fast Open blackhole timeout
This commit computes the Fast Open active-disable interval in
tcp_fastopen_active_should_disable() as a u64 and caps it at
MAX_JIFFY_OFFSET, so the delay can no longer wrap. It also limits
tcp_fastopen_blackhole_timeout_sec to 86400 seconds and documents the new
limit in ip-sysctl.rst.
> This issue was found using a static analysis tool. A loopback reproducer
> induced 12 Fast Open blackholes and waited 1.2 seconds before opening
> another connection. In the v1 arithmetic-only test, the unpatched kernel
> retried active Fast Open, while the fixed kernel used a regular TCP
> handshake. The reproducer required neither kernel modifications nor
> fault injection. The input limit added here rejects that large setting.
[ ... ]
> On the v2 kernel, the sysctl accepts 86400 seconds and rejects 86401,
> leaving the previous value unchanged.
[Severity: Low]
This isn't a bug, but these sentences mention patch revisions (v1 and v2).
Could this revision history go below the --- line instead? Once the patch is
merged, v1 and v2 won't mean anything in git history.
The wording also suggests that the only functional test of the arithmetic
fix (the 6912213 second timeout) was run on v1. The submitted code now
rejects that input, and the only v2 test described is the sysctl range
check.
The arithmetic fix still matters within the new limit. At HZ=1000,
64 * 86400 * 1000 = 5,529,600,000. In 32-bit math that wraps to
1,234,632,704 jiffies, which is about 14.3 days instead of 64 days.
Could the changelog describe a test of the submitted code on that path?
The companion MPTCP patch in this series uses the same v1/v2 wording.
> diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
> index bf193e7ec5168..5bc357e189bde 100644
> --- a/net/ipv4/sysctl_net_ipv4.c
> +++ b/net/ipv4/sysctl_net_ipv4.c
> @@ -1152,6 +1152,7 @@ static const struct ctl_table ipv4_net_table[] = {
> .mode = 0644,
> .proc_handler = proc_tfo_blackhole_detect_timeout,
> .extra1 = SYSCTL_ZERO,
> + .extra2 = &one_day_secs,
> },
[Severity: Medium]
Is this new upper bound needed for the overflow fix? The patch is also
tagged Cc: stable.
proc_tfo_blackhole_detect_timeout() calls proc_dointvec_minmax(), so extra2
is enforced:
net/ipv4/sysctl_net_ipv4.c:proc_tfo_blackhole_detect_timeout() {
...
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
if (write && ret == 0)
atomic_set(&net->ipv4.tfo_active_disable_times, 0);
...
}
Before this patch, any non-negative int was accepted, such as 172800 or
604800. Now those writes fail with -EINVAL. The stored value stays as it
was, and the tfo_active_disable_times reset is skipped.
At boot, the stored value is the per-netns default of 0 from tcp_sk_init().
If sysctl.conf has a multi-day value, would Fast Open blackhole detection
stay disabled after a stable update?
The u64 calculation and the cap in tcp_fastopen_active_should_disable()
already seem to handle every int input:
delay = (u64)multiplier * tfo_bh_timeout * HZ;
...
min(delay, MAX_JIFFY_OFFSET);
tfo_bh_timeout is at most 2^31-1, multiplier is at most 64, and HZ is at
most a little over 1000. The product stays below 2^48, and the cap covers
both 32-bit and 64-bit kernels. So the one day limit looks like a policy
change, not part of the fix.
The commit message mentions the limit. It doesn't say that values accepted
before will now be rejected.
The companion patch in this series, "mptcp: avoid wrapping blackhole
timeout", makes the same arithmetic fix and says "Preserve the existing
sysctl input range". So the two patches treat the input range differently.
Could the bound be dropped here? Or could it move to a separate patch,
without Cc: stable, whose changelog describes the narrower range?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794672619.git.x-professor%40outlook.com
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