mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
@ 2026-11-14 16:12 Yingjie Wang
  2026-11-14 16:12 ` [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yingjie Wang @ 2026-11-14 16:12 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

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout
  2026-11-14 16:12 [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
@ 2026-11-14 16:12 ` Yingjie Wang
  2026-11-16  5:21   ` netdev-bot+sashiko
  2026-11-14 16:12 ` [PATCH net v2 2/2] mptcp: avoid wrapping " Yingjie Wang
  2026-11-15  8:24 ` [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Eric Dumazet
  2 siblings, 1 reply; 6+ messages in thread
From: Yingjie Wang @ 2026-11-14 16:12 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, stable

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net v2 2/2] mptcp: avoid wrapping blackhole timeout
  2026-11-14 16:12 [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
  2026-11-14 16:12 ` [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
@ 2026-11-14 16:12 ` Yingjie Wang
  2026-11-16  5:21   ` netdev-bot+sashiko
  2026-11-15  8:24 ` [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Eric Dumazet
  2 siblings, 1 reply; 6+ messages in thread
From: Yingjie Wang @ 2026-11-14 16:12 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, stable, Gang Yan

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound
  2026-11-14 16:12 [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
  2026-11-14 16:12 ` [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
  2026-11-14 16:12 ` [PATCH net v2 2/2] mptcp: avoid wrapping " Yingjie Wang
@ 2026-11-15  8:24 ` Eric Dumazet
  2 siblings, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2026-11-15  8:24 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

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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout
  2026-11-14 16:12 ` [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
@ 2026-11-16  5:21   ` netdev-bot+sashiko
  0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16  5:21 UTC (permalink / raw)
  To: x-professor
  Cc: netdev, mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc,
	edumazet, ncardwell, gang.yan, kuniyu, davem, kuba, pabeni,
	horms, matttbe, martineau, geliang, ycheng, weiwan, stable,
	yangang

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net v2 2/2] mptcp: avoid wrapping blackhole timeout
  2026-11-14 16:12 ` [PATCH net v2 2/2] mptcp: avoid wrapping " Yingjie Wang
@ 2026-11-16  5:21   ` netdev-bot+sashiko
  0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16  5:21 UTC (permalink / raw)
  To: x-professor
  Cc: netdev, mptcp, linux-kernel, corbet, skhan, rdunlap, linux-doc,
	edumazet, ncardwell, gang.yan, kuniyu, davem, kuba, pabeni,
	horms, matttbe, martineau, geliang, ycheng, weiwan, stable,
	yangang

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-16  5:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 16:12 [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Yingjie Wang
2026-11-14 16:12 ` [PATCH net v2 1/2] tcp: avoid wrapping Fast Open blackhole timeout Yingjie Wang
2026-11-16  5:21   ` netdev-bot+sashiko
2026-11-14 16:12 ` [PATCH net v2 2/2] mptcp: avoid wrapping " Yingjie Wang
2026-11-16  5:21   ` netdev-bot+sashiko
2026-11-15  8:24 ` [PATCH net v2 0/2] tcp/mptcp: prevent blackhole timeout arithmetic wraparound Eric Dumazet

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®