* [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
@ 2026-11-23 9:04 Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-11-23 9:04 UTC (permalink / raw)
To: netdev
Cc: mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc, edumazet,
ncardwell, gang.yan, kuniyu, davem, kuba, pabeni, horms, matttbe,
martineau, geliang, ycheng, weiwan, joel.granados
The TCP Fast Open and MPTCP blackhole timeout calculations can wrap in
32-bit unsigned arithmetic, even on 64-bit kernels. With HZ=1000 and a
64-fold backoff, 67109 seconds becomes 8.7 seconds instead of about
50 days.
Compute both delays in u64, cap them at MAX_JIFFY_OFFSET, and limit both
initial timeout sysctls to one day. The new input limits reject values
that were previously accepted, so this series remains for net-next and
is not intended for stable.
Changes since v3:
- Drop the Fixes tags from both patches.
- Leave the existing comments unchanged, as requested by Matthieu.
- Combine the MPTCP arithmetic fix and input limit into one patch.
- Name the MPTCP limit one_day_secs, as in TCP.
- Drop Gang Yan's Reviewed-by from the combined MPTCP patch because the
added input limit was outside the patch he reviewed. Keep Eric's
Suggested-by for the MPTCP input limit.
- Add Kuniyuki's Suggested-by for requesting a limit on the TCP sysctl.
- Move the test notes out of the commit messages, as requested by Eric.
- Rebase on net-next eb6d6c80d354.
v3: https://lore.kernel.org/r/cover.1794847474.git.x-professor@outlook.com
v2: https://lore.kernel.org/r/cover.1794672619.git.x-professor@outlook.com
v1: https://lore.kernel.org/r/cover.1794325665.git.x-professor@outlook.com
Testing on v4 and its unmodified base, x86-64, HZ=1000:
- Loopback reproducers induced 12 blackholes with a 67109 second timeout
and opened another connection 10 seconds later. The base kernel
retried active TFO and MP_CAPABLE; v4 kept both disabled. Both probes
completed using TCP on v4.
- Both sysctls accepted 0, 1, 3600, 86399 and 86400, and rejected negative
and above-limit values with EINVAL without changing the stored value.
These checks passed in the initial and a new network namespace, with
unchanged defaults and independent namespace values.
- The affected objects built at each commit on x86-64 and i386 with
W=1 and KCFLAGS=-Werror.
The 32-bit cap was checked by compilation and arithmetic, not at runtime.
The TCP and MPTCP selftests were not run locally.
Yingjie Wang (2):
tcp: avoid wrapping Fast Open blackhole timeout
mptcp: avoid wrapping blackhole timeout
Documentation/networking/ip-sysctl.rst | 1 +
Documentation/networking/mptcp-sysctl.rst | 1 +
net/ipv4/sysctl_net_ipv4.c | 1 +
net/ipv4/tcp_fastopen.c | 4 +++-
net/mptcp/ctrl.c | 6 +++++-
5 files changed, 11 insertions(+), 2 deletions(-)
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v4 1/2] tcp: avoid wrapping Fast Open blackhole timeout
2026-11-23 9:04 [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
@ 2026-11-23 9:04 ` Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 2/2] mptcp: avoid wrapping " Yingjie Wang
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-11-23 9:04 UTC (permalink / raw)
To: netdev
Cc: mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc, edumazet,
ncardwell, gang.yan, kuniyu, davem, kuba, pabeni, horms, matttbe,
martineau, geliang, ycheng, weiwan, joel.granados
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.
With HZ=1000 and the maximum multiplier of 64, any timeout above 67108
seconds wraps. For example, 67109 seconds should produce 4,294,976,000
jiffies (about 50 days), but the calculation truncates it to 8,704
jiffies (8.7 seconds).
This issue was found using a static analysis tool. It was confirmed with
a loopback reproducer that induces 12 Fast Open blackholes and opens
another connection 10 seconds later: with a 67109 second timeout, the
unpatched kernel retried active Fast Open. The reproducer needs neither
kernel modifications nor error injection.
Compute the interval in u64 and cap it at MAX_JIFFY_OFFSET before adding
it to the saved timestamp. On 32-bit kernels, the cap keeps the interval
within the range that time_before() can compare, which limits the longest
backoff there to about 12.4 days at HZ=1000.
Also limit the writable initial timeout to one day, so the exponential
backoff does not start from an impractically long period. Writes above
86400 seconds, which were previously accepted, now fail with -EINVAL and
leave the current value unchanged. The wider calculation is still needed
below that limit, as the 67109 second example shows.
Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
Changes since v3:
- Drop Fixes, as requested by Matthieu.
- Leave the existing comments unchanged, as requested by Matthieu.
- Add Kuniyuki's Suggested-by for requesting the input limit.
- Move the test notes below the separator, as requested by Eric.
- Rebase on current net-next.
Testing: the loopback reproducer kept active Fast Open disabled, and
the sysctl accepted 86400 and rejected 86401. The TCP selftests were
not run.
Documentation/networking/ip-sysctl.rst | 1 +
net/ipv4/sysctl_net_ipv4.c | 1 +
net/ipv4/tcp_fastopen.c | 4 +++-
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index 3cc80d9b024b..c2b05ca14ff8 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 9df93ad219db..fb0f3124836d 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..aeefd605414f 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;
@@ -626,10 +627,11 @@ bool tcp_fastopen_active_should_disable(struct sock *sk)
/* Limit timeout to max: 2^6 * initial timeout */
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(). */
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v4 2/2] mptcp: avoid wrapping blackhole timeout
2026-11-23 9:04 [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
@ 2026-11-23 9:04 ` Yingjie Wang
2026-11-23 9:57 ` [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Eric Dumazet
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-11-23 9:04 UTC (permalink / raw)
To: netdev
Cc: mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc, edumazet,
ncardwell, gang.yan, kuniyu, davem, kuba, pabeni, horms, matttbe,
martineau, geliang, ycheng, weiwan, joel.granados
mptcp_active_should_disable() calculates the active-disable interval as
multiplier * blackhole_timeout * HZ. Since all operands are 32-bit, a
large blackhole_timeout can wrap the delay, even on 64-bit kernels, and
make active MPTCP available again while the blackhole is still present.
With HZ=1000 and the maximum multiplier of 64, a timeout of 67109 seconds
should produce 4,294,976,000 jiffies (about 50 days), but the calculation
truncates it to 8,704 jiffies (8.7 seconds).
This issue was found using a static analysis tool. It was confirmed with
a loopback reproducer that induces 12 MPTCP blackholes and opens another
connection 10 seconds later: with a 67109 second timeout, the unpatched
kernel retried MP_CAPABLE. The reproducer needs neither kernel
modifications nor error injection.
Compute the interval in u64 and cap it at MAX_JIFFY_OFFSET before adding
it to the saved timestamp. On 32-bit kernels, the cap keeps the interval
within the range that time_before() can compare, limiting the longest
backoff to about 12.4 days at HZ=1000.
Also limit the writable initial timeout to one day, matching
tcp_fastopen_blackhole_timeout_sec. Writes above 86400 seconds, which
were previously accepted, now fail with -EINVAL and leave the current
value unchanged. The default remains 3600 seconds, and zero still
disables blackhole detection.
Suggested-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
Changes since v3:
- Combine the arithmetic fix and one-day input limit, as requested
by Matthieu; name the bound one_day_secs.
- Drop Fixes, as requested by Matthieu.
- Leave the existing comments unchanged, as requested by Matthieu.
- Drop Gang Yan's Reviewed-by because it covered only the arithmetic
fix; retain Eric's Suggested-by for the input limit.
- Move the test notes below the separator, as requested by Eric.
- Rebase on current net-next.
Testing: the loopback reproducer fell back to TCP without retrying
MP_CAPABLE, and the sysctl accepted 86400 and rejected 86401. The
MPTCP selftests were not run.
Documentation/networking/mptcp-sysctl.rst | 1 +
net/mptcp/ctrl.c | 6 +++++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/mptcp-sysctl.rst b/Documentation/networking/mptcp-sysctl.rst
index b9b5f58e0625..ca00253c8ae9 100644
--- a/Documentation/networking/mptcp-sysctl.rst
+++ b/Documentation/networking/mptcp-sysctl.rst
@@ -63,6 +63,7 @@ blackhole_timeout - INTEGER (seconds)
blackhole issue goes away.
0 to disable the blackhole detection. This is a per-namespace sysctl.
+ The maximum value is one day (86400 seconds).
Default: 3600
diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
index 164f79b9deb0..11472e20fa6f 100644
--- a/net/mptcp/ctrl.c
+++ b/net/mptcp/ctrl.c
@@ -20,6 +20,7 @@ static int mptcp_pernet_id;
#ifdef CONFIG_SYSCTL
static int mptcp_pm_type_max = __MPTCP_PM_TYPE_MAX;
+static int one_day_secs = 24 * 3600;
#endif
struct mptcp_pernet {
@@ -350,6 +351,7 @@ static struct ctl_table mptcp_sysctl_table[] = {
.mode = 0644,
.proc_handler = proc_blackhole_detect_timeout,
.extra1 = SYSCTL_ZERO,
+ .extra2 = &one_day_secs,
},
{
.procname = "syn_retrans_before_tcp_fallback",
@@ -487,6 +489,7 @@ bool mptcp_active_should_disable(struct sock *ssk)
unsigned long timeout;
int disable_times;
int multiplier;
+ u64 delay;
pernet = mptcp_get_pernet(net);
blackhole_timeout = READ_ONCE(pernet->blackhole_timeout);
@@ -503,10 +506,11 @@ bool mptcp_active_should_disable(struct sock *ssk)
/* Limit timeout to max: 2^6 * initial timeout */
multiplier = 1 << min(disable_times - 1, 6);
+ delay = (u64)multiplier * blackhole_timeout * HZ;
/* Paired with the WRITE_ONCE() in mptcp_active_disable(). */
timeout = READ_ONCE(pernet->active_disable_stamp) +
- multiplier * blackhole_timeout * HZ;
+ min(delay, MAX_JIFFY_OFFSET);
return time_before(jiffies, timeout);
}
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
2026-11-23 9:04 [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 2/2] mptcp: avoid wrapping " Yingjie Wang
@ 2026-11-23 9:57 ` Eric Dumazet
2026-11-23 10:15 ` Joel Granados
2026-11-23 10:18 ` Matthieu Baerts
4 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2026-11-23 9:57 UTC (permalink / raw)
To: Yingjie Wang
Cc: netdev, mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc,
ncardwell, gang.yan, kuniyu, davem, kuba, pabeni, horms, matttbe,
martineau, geliang, ycheng, weiwan, joel.granados
Le lun. 23 nov. 2026 à 10:34, Yingjie Wang <x-professor@outlook.com> a écrit :
>
> The TCP Fast Open and MPTCP blackhole timeout calculations can wrap in
> 32-bit unsigned arithmetic, even on 64-bit kernels. With HZ=1000 and a
> 64-fold backoff, 67109 seconds becomes 8.7 seconds instead of about
> 50 days.
>
> Compute both delays in u64, cap them at MAX_JIFFY_OFFSET, and limit both
> initial timeout sysctls to one day. The new input limits reject values
> that were previously accepted, so this series remains for net-next and
> is not intended for stable.
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
2026-11-23 9:04 [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
` (2 preceding siblings ...)
2026-11-23 9:57 ` [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Eric Dumazet
@ 2026-11-23 10:15 ` Joel Granados
2026-11-23 10:18 ` Matthieu Baerts
4 siblings, 0 replies; 6+ messages in thread
From: Joel Granados @ 2026-11-23 10:15 UTC (permalink / raw)
To: Yingjie Wang
Cc: netdev, mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc,
edumazet, ncardwell, gang.yan, kuniyu, davem, kuba, pabeni,
horms, matttbe, martineau, geliang, ycheng, weiwan
[-- Attachment #1: Type: text/plain, Size: 3244 bytes --]
On Mon, Nov 23, 2026 at 09:04:32AM +0000, Yingjie Wang wrote:
> The TCP Fast Open and MPTCP blackhole timeout calculations can wrap in
> 32-bit unsigned arithmetic, even on 64-bit kernels. With HZ=1000 and a
> 64-fold backoff, 67109 seconds becomes 8.7 seconds instead of about
> 50 days.
>
> Compute both delays in u64, cap them at MAX_JIFFY_OFFSET, and limit both
> initial timeout sysctls to one day. The new input limits reject values
> that were previously accepted, so this series remains for net-next and
> is not intended for stable.
>
> Changes since v3:
>
> - Drop the Fixes tags from both patches.
> - Leave the existing comments unchanged, as requested by Matthieu.
> - Combine the MPTCP arithmetic fix and input limit into one patch.
> - Name the MPTCP limit one_day_secs, as in TCP.
> - Drop Gang Yan's Reviewed-by from the combined MPTCP patch because the
> added input limit was outside the patch he reviewed. Keep Eric's
> Suggested-by for the MPTCP input limit.
> - Add Kuniyuki's Suggested-by for requesting a limit on the TCP sysctl.
> - Move the test notes out of the commit messages, as requested by Eric.
> - Rebase on net-next eb6d6c80d354.
>
> v3: https://lore.kernel.org/r/cover.1794847474.git.x-professor@outlook.com
> v2: https://lore.kernel.org/r/cover.1794672619.git.x-professor@outlook.com
> v1: https://lore.kernel.org/r/cover.1794325665.git.x-professor@outlook.com
>
> Testing on v4 and its unmodified base, x86-64, HZ=1000:
>
> - Loopback reproducers induced 12 blackholes with a 67109 second timeout
> and opened another connection 10 seconds later. The base kernel
> retried active TFO and MP_CAPABLE; v4 kept both disabled. Both probes
> completed using TCP on v4.
> - Both sysctls accepted 0, 1, 3600, 86399 and 86400, and rejected negative
> and above-limit values with EINVAL without changing the stored value.
> These checks passed in the initial and a new network namespace, with
> unchanged defaults and independent namespace values.
> - The affected objects built at each commit on x86-64 and i386 with
> W=1 and KCFLAGS=-Werror.
>
> The 32-bit cap was checked by compilation and arithmetic, not at runtime.
> The TCP and MPTCP selftests were not run locally.
>
> Yingjie Wang (2):
> tcp: avoid wrapping Fast Open blackhole timeout
> mptcp: avoid wrapping blackhole timeout
>
> Documentation/networking/ip-sysctl.rst | 1 +
> Documentation/networking/mptcp-sysctl.rst | 1 +
> net/ipv4/sysctl_net_ipv4.c | 1 +
> net/ipv4/tcp_fastopen.c | 4 +++-
> net/mptcp/ctrl.c | 6 +++++-
> 5 files changed, 11 insertions(+), 2 deletions(-)
>
>
> base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
> --
> 2.43.0
>
FYI: there is a fix for the conversion between jiffies and ms for sysctl
entries that just got merged [1] & [2]. It seems like what you are doing
here is orthogonal to that patch. I'm flagging it in case I have
misread.
Best
[1] https://lore.kernel.org/all/179531116414.1248683.10418563467755811748.pr-tracker-bot@kernel.org
[2] https://lore.kernel.org/all/20261118-lklm-sysctl-jiffie-ms-conv-v1-1-bb60e5101418@kernel.org
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
2026-11-23 9:04 [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
` (3 preceding siblings ...)
2026-11-23 10:15 ` Joel Granados
@ 2026-11-23 10:18 ` Matthieu Baerts
4 siblings, 0 replies; 6+ messages in thread
From: Matthieu Baerts @ 2026-11-23 10:18 UTC (permalink / raw)
To: Yingjie Wang
Cc: netdev, mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc,
edumazet, ncardwell, gang.yan, kuniyu, davem, kuba, pabeni,
horms, martineau, geliang, ycheng, weiwan, joel.granados
Hi Yingjie,
On 23/11/2026 10:04, Yingjie Wang wrote:
> The TCP Fast Open and MPTCP blackhole timeout calculations can wrap in
> 32-bit unsigned arithmetic, even on 64-bit kernels. With HZ=1000 and a
> 64-fold backoff, 67109 seconds becomes 8.7 seconds instead of about
> 50 days.
>
> Compute both delays in u64, cap them at MAX_JIFFY_OFFSET, and limit both
> initial timeout sysctls to one day. The new input limits reject values
> that were previously accepted, so this series remains for net-next and
> is not intended for stable.
Thank you for the v4, it looks good to me:
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> Changes since v3:
Note for next time: you can put the ChangeLog in a "notes" section, so
under "---"
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-23 10:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 9:04 [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
2026-11-23 9:04 ` [PATCH net-next v4 2/2] mptcp: avoid wrapping " Yingjie Wang
2026-11-23 9:57 ` [PATCH net-next v4 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Eric Dumazet
2026-11-23 10:15 ` Joel Granados
2026-11-23 10:18 ` Matthieu Baerts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®