[PATCH net-next v3 2/3] mptcp: avoid wrapping blackhole timeout

From
Yingjie Wang <hidden>
Date
2026-11-16 16:46:48
Also in
linux-doc, lkml, mptcp
Reply to
Yingjie Wang, 2026-11-16
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, 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 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. The sysctl input range
is unchanged; values whose interval exceeds the cap are shortened to it.

With this patch, the same reproducer fell back to TCP without retrying
MP_CAPABLE. The MPTCP selftests were not run; none of them sets this
sysctl.

Fixes: 27069e7cb3d1 ("mptcp: disable active MPTCP in case of blackhole")
Reviewed-by: Gang Yan <redacted>
Signed-off-by: Yingjie Wang <redacted>
---
 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
Thread (4 messages) 4 messages, 1 author, last reply 9h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help