Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Yingjie Wang
Sat, 14 Nov 2026 16:12
[PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
Author: Yingjie Wang
Date: Sat, 14 Nov 2026 16:12
Date: Sat, 14 Nov 2026 16:12
58 lines
22138 bytes
22138 bytes
The TCP Fast Open and MPTCP blackhole handlers multiply writable timeout
sysctl values before adding the result to a jiffies timestamp. The
multiplication is performed in 32-bit unsigned arithmetic, so a large
value can wrap into a short delay even on a 64-bit kernel.
With HZ=1000, a timeout of 6912213 seconds and the maximum multiplier of
64 should produce 442,381,632,000 jiffies, but the current calculations
truncate the result to 512 jiffies. Both patches compute the delay in u64
and cap it at MAX_JIFFY_OFFSET before adding it to the saved timestamp.
The issues were found using a static analysis tool. In the v1 arithmetic
A/B tests, loopback reproducers induced 12 blackholes, waited 1.2 seconds,
and then made a new connection:
TFO: base probe 1.026 s, TCPFastOpenActiveFail +1;
fixed probe 0.000 s, TCPFastOpenActiveFail +0.
MPTCP: base probe 3.087 s, MPCapableSYNTXDisabled +0;
fixed probe 0.000 s, MPCapableSYNTXDisabled +1.
The TFO counter records another failed active Fast Open attempt. The
MPTCP counter records a connection that skips MP_CAPABLE and falls back to
TCP while active MPTCP is disabled.
Changes since v1:
- Add a reasonable upper bound for the TCP Fast Open sysctl, as requested
by Kuniyuki Iwashima. This version proposes one day (86400 seconds),
using the existing IPv4 one_day_secs bound, and documents that limit.
Keep the existing MPTCP sysctl input range.
- Clarify that the multiplier is limited to 64 and the final delay is
separately capped for safe jiffies comparisons on 32-bit systems,
addressing Gang Yan's comment. Keep the READ_ONCE/WRITE_ONCE pairing
annotations next to the timestamp reads.
- Identify the original runtime results as v1 evidence in both commits.
- Retain Gang Yan's Reviewed-by tag on the unchanged MPTCP arithmetic fix.
v1: https://lore.kernel.org/r/cover.1794325665.git.x-professor@outlook.com
On the final v2 x86-64 HZ=1000 kernel, TCP accepts 86400 and rejects 86401;
MPTCP still accepts 86401 and INT_MAX. Boundary tests also cover zero,
negative and oversized values, failed-write preservation, defaults, and
network namespace isolation. The large timeout used in the v1 TFO test
is now rejected by the TCP sysctl limit.
The MPTCP blackhole test was rerun on this v2 kernel: all 12 clients
completed, and the probe used TCP fallback directly (0.000 s,
MPCapableSYNTXDisabled +1). The full x86-64 kernel build and affected
object builds on x86-64 and i386 passed. The upstream TCP and MPTCP
selftest suites were not run. Full allyesconfig/allmodconfig W=1 builds
stopped at warnings promoted to
errors in unchanged lockdep, coda, and x86 callthunks code;
the affected objects passed W=1 KCFLAGS=-Werror in both configurations.
The patches are independent and have separate Fixes tags.
Yingjie Wang (2):
tcp: avoid wrapping Fast Open blackhole timeout
mptcp: avoid wrapping blackhole timeout
Documentation/networking/ip-sysctl.rst | 1 +
net/ipv4/sysctl_net_ipv4.c | 1 +
net/ipv4/tcp_fastopen.c | 12 +++++++++---
net/mptcp/ctrl.c | 12 +++++++++---
4 files changed, 20 insertions(+), 6 deletions(-)
base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0
--
2.43.0
[PATCH net v2 2/2] mptcp: avoid wrapping blackhole timeout
Author: Yingjie Wang
Date: Sat, 14 Nov 2026 16:12
Date: Sat, 14 Nov 2026 16:12
49 lines
21627 bytes
21627 bytes
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.
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 MPTCP blackholes and waited 1.2 seconds before opening another
connection. In the v1 arithmetic-only test, the unpatched kernel retried
MP_CAPABLE, while the fixed kernel used TCP fallback directly. The
reproducer required neither kernel modifications nor fault injection.
Compute the interval in u64 and cap it at MAX_JIFFY_OFFSET before adding
it to the saved timestamp. The multiplier remains limited to 64, while
the separate cap keeps the delay within the safe jiffies comparison range
on 32-bit systems. Preserve the existing sysctl input range and backoff
for representable intervals.
On the v2 kernel, the loopback blackhole reproducer completed all 12
clients and the probe used TCP fallback directly instead of retrying
MP_CAPABLE.
Fixes: 27069e7cb3d1 ("mptcp: disable active MPTCP in case of blackhole")
Cc: stable@vger.kernel.org
Reviewed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
net/mptcp/ctrl.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
index 63c5747f0f63..0b10e94e7f43 100644
--- a/net/mptcp/ctrl.c
+++ b/net/mptcp/ctrl.c
@@ -487,6 +487,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);
@@ -501,12 +502,17 @@ bool mptcp_active_should_disable(struct sock *ssk)
/* Paired with smp_mb__before_atomic() in mptcp_active_disable() */
smp_rmb();
- /* Limit timeout to max: 2^6 * initial timeout */
+ /* Limit the backoff multiplier to 64. */
multiplier = 1 << min(disable_times - 1, 6);
+ delay = (u64)multiplier * blackhole_timeout * HZ;
- /* Paired with the WRITE_ONCE() in mptcp_active_disable(). */
+ /*
+ * Cap the delay for safe jiffies comparisons on 32-bit systems.
+ * The timestamp read is paired with 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
Re: [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
Author: Eric Dumazet
Date: Sun, 15 Nov 2026 08:24
Date: Sun, 15 Nov 2026 08:24
112 lines
13973 bytes
13973 bytes
Le sam. 14 nov. 2026 à 17:12, Yingjie Wang <x-professor@outlook.com> a écrit :
>
> The TCP Fast Open and MPTCP blackhole handlers multiply writable timeout
> sysctl values before adding the result to a jiffies timestamp. The
> multiplication is performed in 32-bit unsigned arithmetic, so a large
> value can wrap into a short delay even on a 64-bit kernel.
>
> With HZ=1000, a timeout of 6912213 seconds and the maximum multiplier of
> 64 should produce 442,381,632,000 jiffies, but the current calculations
> truncate the result to 512 jiffies. Both patches compute the delay in u64
> and cap it at MAX_JIFFY_OFFSET before adding it to the saved timestamp.
>
> The issues were found using a static analysis tool. In the v1 arithmetic
> A/B tests, loopback reproducers induced 12 blackholes, waited 1.2 seconds,
> and then made a new connection:
>
> TFO: base probe 1.026 s, TCPFastOpenActiveFail +1;
> fixed probe 0.000 s, TCPFastOpenActiveFail +0.
> MPTCP: base probe 3.087 s, MPCapableSYNTXDisabled +0;
> fixed probe 0.000 s, MPCapableSYNTXDisabled +1.
>
> The TFO counter records another failed active Fast Open attempt. The
> MPTCP counter records a connection that skips MP_CAPABLE and falls back to
> TCP while active MPTCP is disabled.
>
> Changes since v1:
>
> - Add a reasonable upper bound for the TCP Fast Open sysctl, as requested
> by Kuniyuki Iwashima. This version proposes one day (86400 seconds),
> using the existing IPv4 one_day_secs bound, and documents that limit.
> Keep the existing MPTCP sysctl input range.
The one day limit, the u64 computation and the clamp look fine to me
for the TCP side: with HZ=1000, 64 * 86400 * HZ still does not fit in
32 bits, and 32-bit kernels need the interval to stay below 2^31 jiffies
for time_before().
Why is MPTCP left alone? Kuniyuki's remark applies equally to
net.mptcp.blackhole_timeout: nobody needs a multi-day initial timeout
there either. I will let MPTCP maintainers decide, but having the two
sysctls behave differently looks odd.
> - Clarify that the multiplier is limited to 64 and the final delay is
> separately capped for safe jiffies comparisons on 32-bit systems,
> addressing Gang Yan's comment. Keep the READ_ONCE/WRITE_ONCE pairing
> annotations next to the timestamp reads.
> - Identify the original runtime results as v1 evidence in both commits.
Please do not do that. The changelog of each patch should describe the
problem and the fix. Version history and test notes ("In the v1
arithmetic-only test...", "On the v2 kernel...") belong in the cover
letter or after the --- marker, not in the commit message.
> - Retain Gang Yan's Reviewed-by tag on the unchanged MPTCP arithmetic fix.
>
> v1: https://lore.kernel.org/r/cover.1794325665.git.x-professor@outlook.com
>
> On the final v2 x86-64 HZ=1000 kernel, TCP accepts 86400 and rejects 86401;
> MPTCP still accepts 86401 and INT_MAX. Boundary tests also cover zero,
> negative and oversized values, failed-write preservation, defaults, and
> network namespace isolation. The large timeout used in the v1 TFO test
> is now rejected by the TCP sysctl limit.
>
> The MPTCP blackhole test was rerun on this v2 kernel: all 12 clients
> completed, and the probe used TCP fallback directly (0.000 s,
> MPCapableSYNTXDisabled +1). The full x86-64 kernel build and affected
> object builds on x86-64 and i386 passed. The upstream TCP and MPTCP
> selftest suites were not run. Full allyesconfig/allmodconfig W=1 builds
> stopped at warnings promoted to
> errors in unchanged lockdep, coda, and x86 callthunks code;
> the affected objects passed W=1 KCFLAGS=-Werror in both configurations.
>
> The patches are independent and have separate Fixes tags.
About the Fixes/stable tags:
This needs an admin to set a timeout nobody would use, and the only
consequence is that active TFO (or MPTCP) is retried sooner than
requested.
Also patch 1 now makes the TCP sysctl reject values that were accepted
before. I do not think we want that in stable trees.
Please drop the Cc: stable and target net-next.
Thanks.
>
> Yingjie Wang (2):
> tcp: avoid wrapping Fast Open blackhole timeout
> mptcp: avoid wrapping blackhole timeout
>
> Documentation/networking/ip-sysctl.rst | 1 +
> net/ipv4/sysctl_net_ipv4.c | 1 +
> net/ipv4/tcp_fastopen.c | 12 +++++++++---
> net/mptcp/ctrl.c | 12 +++++++++---
> 4 files changed, 20 insertions(+), 6 deletions(-)
>
>
> base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0
> --
> 2.43.0
>
Re: [PATCH net v2 2/2] mptcp: avoid wrapping blackhole timeout
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 05:21
Date: Mon, 16 Nov 2026 05:21
124 lines
12851 bytes
12851 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 commit message body refers to earlier revisions of this
patch: "In the v1 arithmetic-only test, the unpatched kernel retried…
- [Low] mptcp_active_should_disable() (net/mptcp/ctrl.c:514-515) now
silently clamps the disable interval to MAX_JIFFY_OFFSET.
--
mptcp: avoid wrapping blackhole timeout
This commit computes the active-disable interval in
mptcp_active_should_disable() in u64, so multiplier * blackhole_timeout *
HZ no longer wraps in 32-bit arithmetic. The result is capped at
MAX_JIFFY_OFFSET before it is added to active_disable_stamp.
> This issue was found using a static analysis tool. A loopback reproducer
> induced 12 MPTCP blackholes and waited 1.2 seconds before opening another
> connection. In the v1 arithmetic-only test, the unpatched kernel retried
> MP_CAPABLE, while the fixed kernel used TCP fallback directly. The
> reproducer required neither kernel modifications nor fault injection.
[ ... ]
> On the v2 kernel, the loopback blackhole reproducer completed all 12
> clients and the probe used TCP fallback directly instead of retrying
> MP_CAPABLE.
[Severity: Low]
This isn't a bug, but the changelog refers to earlier revisions of the
patch ("In the v1 arithmetic-only test" and "On the v2 kernel"). After the
patch is merged, v1 and v2 mean nothing in git log. This is also tagged
for stable, so backporters will read it without the mailing list thread.
Could the reproducer results be described once, against the final code,
with the per-version history moved below the --- line?
The numbers themselves check out. 64 * 6912213 * 1000 = 442,381,632,000,
which is 512 mod 2^32. With 12 blackholes the multiplier is
1 << min(11, 6) = 64, and a 1.2 second wait is longer than 512 jiffies at
HZ=1000.
> diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
> index 63c5747f0f63c..0b10e94e7f43c 100644
> --- a/net/mptcp/ctrl.c
> +++ b/net/mptcp/ctrl.c
[ ... ]
> @@ -501,12 +502,17 @@ bool mptcp_active_should_disable(struct sock *ssk)
> /* Paired with smp_mb__before_atomic() in mptcp_active_disable() */
> smp_rmb();
>
> - /* Limit timeout to max: 2^6 * initial timeout */
> + /* Limit the backoff multiplier to 64. */
> multiplier = 1 << min(disable_times - 1, 6);
> + delay = (u64)multiplier * blackhole_timeout * HZ;
>
> - /* Paired with the WRITE_ONCE() in mptcp_active_disable(). */
> + /*
> + * Cap the delay for safe jiffies comparisons on 32-bit systems.
> + * The timestamp read is paired with WRITE_ONCE() in
> + * mptcp_active_disable().
> + */
> timeout = READ_ONCE(pernet->active_disable_stamp) +
> - multiplier * blackhole_timeout * HZ;
> + min(delay, MAX_JIFFY_OFFSET);
[Severity: Low]
On 32-bit kernels MAX_JIFFY_OFFSET is ((LONG_MAX >> 1) - 1), which is
0x3ffffffe jiffies, or about 12.4 days at HZ=1000. Does this clamp
silently shorten blackhole_timeout values that the sysctl still accepts?
The sysctl entry only sets a lower bound:
net/mptcp/ctrl.c:mptcp_sysctl_table[] {
...
{
.procname = "blackhole_timeout",
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_blackhole_detect_timeout,
.extra1 = SYSCTL_ZERO,
},
...
}
So values up to INT_MAX are accepted. Anything above about 1,073,741
seconds is cut short even on the first blackhole (multiplier 1). Smaller
values stop doubling before they reach the 64x factor.
time_before() handles deltas up to LONG_MAX, so the cap is half of what
the comparison can take. The old code compared intervals between 2^30 and
2^31-1 jiffies correctly, and those are now shortened.
For example, take HZ=1000, blackhole_timeout = 2000000 and a first
blackhole. The old code disabled active MPTCP for 2e9 jiffies (about 23
days). The new code disables it for 1,073,741,822 jiffies (about 12.4
days).
The commit message says:
Preserve the existing sysctl input range and backoff
for representable intervals.
But this interval is representable and still gets shortened.
Documentation/networking/mptcp-sysctl.rst, and the zh_CN translation,
still describe blackhole_timeout as an initial period that will "grow
exponentially", with no upper bound mentioned.
Should the clamp be documented, or should the sysctl get an upper bound
that matches it?
64-bit kernels are not affected, because MAX_JIFFY_OFFSET there is far
above 64 * INT_MAX * HZ.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794672619.git.x-professor%40outlook.com
Re: [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
Author: Matthieu Baerts
Date: Mon, 16 Nov 2026 12:29
Date: Mon, 16 Nov 2026 12:29
53 lines
14089 bytes
14089 bytes
Hi Eric, Yingjie, On 15/11/2026 09:24, Eric Dumazet wrote: > Le sam. 14 nov. 2026 à 17:12, Yingjie Wang <x-professor@outlook.com> a écrit : >> >> The TCP Fast Open and MPTCP blackhole handlers multiply writable timeout >> sysctl values before adding the result to a jiffies timestamp. The >> multiplication is performed in 32-bit unsigned arithmetic, so a large >> value can wrap into a short delay even on a 64-bit kernel. >> >> With HZ=1000, a timeout of 6912213 seconds and the maximum multiplier of >> 64 should produce 442,381,632,000 jiffies, but the current calculations >> truncate the result to 512 jiffies. Both patches compute the delay in u64 >> and cap it at MAX_JIFFY_OFFSET before adding it to the saved timestamp. >> >> The issues were found using a static analysis tool. In the v1 arithmetic >> A/B tests, loopback reproducers induced 12 blackholes, waited 1.2 seconds, >> and then made a new connection: >> >> TFO: base probe 1.026 s, TCPFastOpenActiveFail +1; >> fixed probe 0.000 s, TCPFastOpenActiveFail +0. >> MPTCP: base probe 3.087 s, MPCapableSYNTXDisabled +0; >> fixed probe 0.000 s, MPCapableSYNTXDisabled +1. >> >> The TFO counter records another failed active Fast Open attempt. The >> MPTCP counter records a connection that skips MP_CAPABLE and falls back to >> TCP while active MPTCP is disabled. >> >> Changes since v1: >> >> - Add a reasonable upper bound for the TCP Fast Open sysctl, as requested >> by Kuniyuki Iwashima. This version proposes one day (86400 seconds), >> using the existing IPv4 one_day_secs bound, and documents that limit. >> Keep the existing MPTCP sysctl input range. > > The one day limit, the u64 computation and the clamp look fine to me > for the TCP side: with HZ=1000, 64 * 86400 * HZ still does not fit in > 32 bits, and 32-bit kernels need the interval to stay below 2^31 jiffies > for time_before(). > > Why is MPTCP left alone? Kuniyuki's remark applies equally to > net.mptcp.blackhole_timeout: nobody needs a multi-day initial timeout > there either. I will let MPTCP maintainers decide, but having the two > sysctls behave differently looks odd. I agree with Eric: these two "blackhole" sysctl knobs are similar, and the behaviour shouldn't differentiate then. Cheers, Matt -- Sponsored by the NGI0 Core fund.
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