* [PATCH mptcp-net v3 00/50] mptcp: misc fixes
@ 2026-11-24 21:59 Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
` (50 more replies)
0 siblings, 51 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason, Kyuwon Cho, Josef Bacik
Here are various fixes, some from Chris Mason and Josef Bacik:
- Patches 1-6: do not reset an orphan while it can still send its data,
also after a fallback, but limit it with a closed window, and count it
as TCP does, so that tcp_max_orphans limits it too. Also return EOF
after a DATA_FIN followed by a reset, and send a reset when aborting
after a fallback, as TCP does. Fixes for v5.11, v5.12, v6.1, and for
another fix introduced in v6.18 and targeting v6.1.
- Patches 7-9: wake up the senders blocked when the connection is closed
without subflows, after a subflow error, or when the initial subflow
is only shut down. Fixes for another fix introduced in v6.6 and
targeting v5.11, and for v5.12.
- Patches 10-14: process a DATA_FIN received with old data, and a
pending MP_FASTCLOSE or DATA_FIN before closing without subflows, also
at accept() time, instead of ignoring them, and report a reset
received before accept(): the reader could miss the end of file or
the reset. Fixes for v5.9, v6.6, v6.19 and v6.3.
- Patch 15: clear the socket error on connect(), as TCP does. A fix for
v5.17.
- Patches 16-17: with TCP_FASTOPEN_CONNECT, clear DEFER_CONNECT on
disconnect, and report the error of a first subflow aborted before the
first write(), instead of EINVAL or EISCONN. Fixes for v6.1, and for
another fix introduced in v7.4-rc3 and targeting v4.11.
- Patch 18: do not send a fastclose reset from a subflow in SYN_SENT, as
TCP does. A fix for another fix introduced in v6.18 and targeting
v6.1.
- Patches 19-20: keep listening, or keep the data to read, after a
failed sendmsg() with MSG_FASTOPEN, as TCP does, and do not let the
new sockets created meanwhile inherit a flag preventing their
disconnection. Fixes for another fix introduced in v6.2 and targeting
v6.1.
- Patch 21: drop the ACKs with a SYN cookie and no MP_JOIN on PM
listeners, which could stop accepting new subflows, and pin their
netns. A fix for v5.12.
- Patch 22: close a subflow reset because of a bad mapping, not to keep
the MPTCP socket established without subflows. A fix for v5.12.
- Patches 23-24: count MPTCP listeners correctly in /proc/net/protocols,
and send their creation event once. Fixes for another fix introduced
in v6.4 and targeting v5.17, and for v6.2.
- Patches 25-26: send the infinite mapping in a single segment, with
room for its DSS option, also after a fallback on reception: its
segments could be bigger than the MTU, and then dropped. Fixes for
v5.19.
- Patches 27-29: avoid data delivered twice around a fallback to TCP,
with old data in flight, or resent to a peer that fell back. Fixes for
v5.19, and for another fix introduced in v6.12 and targeting v5.13.
- Patches 30-31: do not count a signal+subflow ID 0 endpoint as used at
each re-creation, and validate it. A fix for another fix introduced in
v6.11 and targeting v6.0.
- Patches 32-35: reclaim the forward memory after coalescing skbs, and
do not overcharge the memcg at accept(). Fixes for v6.19.
- Patch 36: after a fallback, continue the last mapping. A fix for
v6.19.
- Patches 37-38: after a simultaneous connect, do not drop the first
received byte, and move to ESTABLISHED without waiting for the next
packet. Fixes for v6.19, and for another fix introduced in v6.19 and
targeting v6.2.
- Patch 39: with MSG_PEEK, do not skip data after a partly peeked skb:
the peeked data was corrupted. A fix for v6.18.
- Patch 40: send the DATA_ACK of the data moved from the backlog, to
avoid spurious MPTCP retransmissions, preventing a fallback after an
MP_FAIL. A fix for v6.15.
- Patches 41-42: in the selftests, avoid spurious MPTCP retransmissions
preventing the infinite fallback in the 'Infinite map' subtest, and
wait for the data to be acked before a fastclose. Fixes for v5.19,
only effective from v7.3, and for v6.1.
- Patches 43-44: order the write_seq and DATA_FIN flag updates, not to
send a DATA_FIN with the sequence number of the last byte, or a FIN
before this byte after a fallback, on weakly ordered CPUs. Fixes for
v5.9, and for another fix, now in net, and targeting v5.19.
- Patches 45-46: Squash-to patches for the BPF packet schedulers, in the
MPTCP tree only: stop pushing when they pick no subflow, or one that
cannot send, instead of spinning, and set the rtx timer interval
before calling them, not to fire the timer every jiffy.
- Patch 47: for mptcp-next: push the pending data, and the FIN, right
after a fallback on reception, not at the next retransmission timeout.
A non-urgent fix for v6.12.
- Patch 48: for mptcp-next: report the errors as TCP does when closing:
ETIMEDOUT after the close timeout or the last subflow's RTO, and the
reset errors when the last subflow is reset.
- Patch 49: for mptcp-next: name all the mapping statuses in a
tracepoint.
- Patch 50: RFC for mptcp-next: reset the subflow when the DSS
disappears after a DATA_ACK, instead of a fallback to TCP, as
suggested by RFC 8684.
The Packetdrill tests mptcp/regressions/close_mpj_timeout* will fail
because of patch 48: the Packetdrill patches adapting them will be
shared later.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Changes in v3:
- Patch 4: process the DATA_FIN before the disconnect of the first
subflow, which clears its FIN (Clashiko).
- Patch 5: stop passing data to the MPTCP socket before checking for
unread data (Clashiko).
- Patch 6: no second reset for the children of a closed listener, also
without fallback (Clashiko).
- Patch 11: commit msg: the flaky subtest is fixed by patch 7, and the
remaining issue (Clashiko).
- Patch 14: new, for an issue spotted by Clashiko.
- Patch 17: comment and commit msg: also after a disconnect, and what
write() does without the race (Clashiko).
- Patch 18: move the subflow to TCP_CLOSE at once (Clashiko).
- Patch 19: also skip the disconnect for a connected socket, not to
drop data to read (Clashiko).
- Patch 21: commit msg: the netns pinned by the queued children
(Clashiko).
- Patches 25-26: commit msg: why an MSS decrease before the infinite
mapping is acked is not handled (Clashiko).
- Patch 38: also check if MPTCP is blocked (Clashiko).
- Patch 43: new, for an issue spotted by Clashiko.
- Patch 44: only the acquire, the release being in patch 43.
- Patches 45-46: stop the push loop of __mptcp_push_pending() too, and
set the rtx timer interval when a subflow is already scheduled
(Clashiko).
- Patch 49: new, for an issue spotted by Clashiko.
- Patch 50: name the new mapping status in the tracepoint, and commit
msg: all invalid mappings (Clashiko).
- Other comments from Clashiko: notes under the "---" of the patches.
- Patches 1-11, 32-33, 35 and 45 from v2: dropped, applied in the MPTCP
tree, with the modifications of v3 for patches 6, 7 and 45.
- Link to v2: https://patch.msgid.link/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f@kernel.org
Changes in v2:
- Patches 1-2: on top of commit 342e62fd34c2 ("tcp: purge Fast Open RST
queue when listen() fails"), which purges the RST queue: only the
accept queue is left. Patch 2 is now reproduced, with MPTCP sockets.
- Patch 5: no netlink event for the dropped ids (Clashiko), but still
for the next pending ones (Sashiko).
- Patch 6: send the RM_ADDR at once (Clashiko).
- Patch 7: new, for an issue spotted by Clashiko.
- Patch 12: new, for issue #647 reported on GitHub.
- Patch 13: new, to limit the orphans kept by patch 12, as TCP does,
for an issue found by a review agent.
- Patch 14: new, spotted by a review agent.
- Patch 15: new, for issue #647 reported on GitHub.
- Patch 16: new, for a similar issue found by a review agent.
- Patch 17: new, for an issue found by a review agent.
- Patch 18: new, for issue #648 reported on GitHub.
- Patch 19: new, for a similar issue found by a review agent.
- Patch 20: new, for an issue found by a review agent and Sashiko.
- Patches 21-23: new, for issues causing flaky selftests.
- Patches 24-25: new, for issues found by a review agent.
- Patch 26: new, for an issue found by a review agent.
- Patch 27: new, for an issue spotted by Sashiko.
- Patch 28: new, for an issue found by a review agent.
- Patches 29-30: new, for issues found by a review agent.
- Patch 34: commit msg: the reset after a bad checksum too (Sashiko).
- Patch 36: count the listener once listen() succeeded, and restore
TCP_CLOSE otherwise (Sashiko, Kyuwon Cho).
- Patch 37: commit msg: explain the two Fixes tags.
- Patch 38: new, for an issue causing a flaky selftest.
- Patch 39: new, for an issue spotted by Sashiko.
- Patch 40: commit msg: the peer can still fall back alone (Clashiko),
and only clamp to one MSS when sending the infinite mapping (Sashiko).
- Patch 41: drop the segment if the push resets the subflow (Sashiko,
Clashiko).
- Patch 42: new, for an issue spotted by Clashiko.
- Patch 44: skip a part if the nft rule cannot be added (Clashiko).
- Patch 49: update a comment (Clashiko).
- Patch 50: commit msg: the sender now resets in the remaining case
(Clashiko).
- Patch 51: new, for an issue spotted by Sashiko.
- Patch 52: new, for an issue found by a review agent, after a Sashiko
review.
- Patch 53: new, for an issue causing a flaky selftest.
- Patch 54: new, for an issue causing a flaky selftest.
- Patches 55-56: new, for flaky selftests.
- Patch 57: new, for an issue spotted by Clashiko in a fix pending in
net.
- Patch 58: new, for an issue found by a review agent.
- Patch 59: new, for an issue spotted by Clashiko.
- Patch 60: new, for mptcp-next, for an issue spotted by Clashiko in a
fix pending in net.
- Patch 61: new, for mptcp-next, as suggested in the GitHub issue #648.
- Patch 62: also reset on an invalid mapping (Clashiko).
- Patches 11, 23-26 and 32 from v1: dropped, applied in the MPTCP tree.
- Link to v1: https://patch.msgid.link/20261113-mptcp-cmason-fixes-v1-0-9205b77e9a2f@kernel.org
---
Chris Mason (8):
mptcp: drop non-MP_JOIN cookie ACKs on PM listeners
mptcp: close a subflow reset for a bad mapping
mptcp: do not fallback while old data is in flight
mptcp: stop resending data to a peer that fell back
mptcp: reclaim forward memory after coalescing skbs
mptcp: don't charge a shared page twice at accept()
mptcp: don't charge the backlog twice at accept()
mptcp: continue the last mapping after a fallback
Josef Bacik (1):
mptcp: pm: kernel: don't count signal+subflow ID 0 endp
Matthieu Baerts (NGI0) (41):
mptcp: keep an orphan while it can send its data
mptcp: limit an orphan probing a zero window
mptcp: count orphans as TCP does
mptcp: return EOF after a DATA_FIN, as TCP does
mptcp: let TCP send orphan data after fallback
mptcp: reset the subflow on abort after fallback
mptcp: wake up blocked senders when no sf left
mptcp: set SEND_SHUTDOWN on close by an sf error
mptcp: start close timeout on initial sf shutdown
mptcp: process a DATA_FIN received with old data
mptcp: no sf left: process pending MP_FASTCLOSE
mptcp: no sf left: process pending DATA_FIN
mptcp: process pending close events at accept()
mptcp: report errors received before accept()
mptcp: clear sk_err on connect(), as TCP does
mptcp: clear DEFER_CONNECT on disconnect
mptcp: report sf aborts during deferred connect
mptcp: no fastclose reset from SYN_SENT subflows
mptcp: fastopen: keep listeners and connections
mptcp: don't inherit fastopening from a listener
mptcp: pm: kernel: count endpoint listeners as sockets in use
mptcp: count a listener once when listen() is called again
mptcp: send the infinite map in a single segment
mptcp: keep room for infinite map after fallback
mptcp: don't resend data acked without MPTCP opts
selftests: mptcp: join: check re-adding signal+subflow ID 0 endp
mptcp: don't charge a subflow twice when it joins during accept()
mptcp: keep the first byte after a simult connect
mptcp: move to ESTABLISHED after a simult connect
mptcp: fix MSG_PEEK after a partly peeked skb
mptcp: send the DATA_ACK after moving the backlog
selftests: mptcp: join: infinite map: no spurious rtx
selftests: mptcp: connect: trunc: wait for acks
mptcp: order write_seq and DATA_FIN flag
mptcp: order write_seq and DATA_FIN flag for fallback
Squash to "bpf: Add mptcp packet scheduler struct_ops"
Squash to "bpf: Export mptcp packet scheduler helpers"
[mptcp-next] mptcp: push pending data after a fallback on reception
[mptcp-next] mptcp: report errors as TCP does when closing
[mptcp-next] mptcp: trace: name all the mapping statuses
[RFC mptcp-next] mptcp: reset when the DSS disappears after a DATA_ACK
include/trace/events/mptcp.h | 5 +-
net/mptcp/mib.h | 2 +-
net/mptcp/options.c | 41 +-
net/mptcp/pm_kernel.c | 15 +-
net/mptcp/protocol.c | 456 ++++++++++++++++++----
net/mptcp/protocol.h | 30 +-
net/mptcp/sched.c | 5 +
net/mptcp/subflow.c | 90 ++++-
tools/testing/selftests/net/mptcp/mptcp_connect.c | 24 +-
tools/testing/selftests/net/mptcp/mptcp_join.sh | 19 +-
10 files changed, 577 insertions(+), 110 deletions(-)
---
base-commit: e1364181a6bba3b954d621abfd5f2e866128e32e
base-tree: https://github.com/multipath-tcp/mptcp_net-next.git t/upstream
change-id: 20261110-mptcp-cmason-fixes-eec0054c880a
Best regards,
--
Matthieu Baerts (NGI0) <matttbe@kernel.org>
^ permalink raw reply [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-25 1:16 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
` (49 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The close timeout of an orphaned MPTCP socket started at close(), and
its expiry reset the connection, while some data could still be waiting
for the peer to open its window: a peer reading slowly or pausing got a
reset 60 seconds after close(), and lost the end of the data, while TCP
delivers it.
This timeout is there for the DATA_FIN exchange, see commit d866ae9aaa43
("mptcp: add a new sysctl for make after break timeout"), and for an
orphan that can no longer send anything. So restart it when the DATA_FIN
is sent, and when it expires before, as long as a subflow can still send
the data, which is then pushed again: an established subflow, on which
the peer acked something recently, at least the window probes. Until
then, as for a TCP socket that is not orphaned, nothing limits how long
the peer can keep its window closed, while it acks the window probes.
The timeout still starts at close(): the subflows are not TCP orphans,
so its expiry is the only check that the orphan can still send.
This was reported on GitHub, with a reproducer: a server writes 2 MB,
then calls close(), while the client pauses before reading the rest.
After a pause of 90 seconds, the client got ECONNRESET, while TCP
delivered everything, as MPTCP now does. If the client vanishes instead,
the orphan is now reset as TCP does.
Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/647
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for issue #647 reported on GitHub
Note (Clashiko on v2): when the last subflow is closed in the same
worker run, before the DATA_FIN is sent, the destruction of the orphan
is delayed once, by the close timeout. Not restarting the timeout once
expired would reset an orphan sending its DATA_FIN after a long probing.
---
net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d64e04245963..944c9d11d211 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2871,6 +2871,28 @@ static bool mptcp_close_tout_expired(const struct sock *sk)
inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
}
+/* Before its DATA_FIN, keep an orphan while a subflow can send its data */
+static bool mptcp_orphan_keep(struct sock *sk)
+{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ struct mptcp_subflow_context *subflow;
+
+ if (!sock_flag(sk, SOCK_DEAD) || msk->snd_nxt == msk->write_seq)
+ return false;
+
+ mptcp_for_each_subflow(msk, subflow) {
+ struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+ /* a live peer acks at least the probes, every TCP_RTO_MAX */
+ if (__mptcp_subflow_active(subflow) &&
+ tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
+ 2 * TCP_RTO_MAX)
+ return true;
+ }
+
+ return false;
+}
+
static void mptcp_check_fastclose(struct mptcp_sock *msk)
{
struct mptcp_subflow_context *subflow, *tmp;
@@ -3208,6 +3230,11 @@ static void mptcp_worker(struct work_struct *work)
if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
__mptcp_close_subflow(sk);
+ if (mptcp_close_tout_expired(sk) && mptcp_orphan_keep(sk)) {
+ mptcp_start_tout_timer(sk);
+ __mptcp_push_pending(sk, 0);
+ }
+
if (mptcp_close_tout_expired(sk)) {
struct mptcp_subflow_context *subflow, *tmp;
@@ -3449,6 +3476,10 @@ static void mptcp_check_send_data_fin(struct sock *sk)
WRITE_ONCE(msk->snd_nxt, msk->write_seq);
+ /* an orphan's close timeout is for the DATA_FIN exchange */
+ if (sock_flag(sk, SOCK_DEAD))
+ mptcp_start_tout_timer(sk);
+
mptcp_for_each_subflow(msk, subflow) {
struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-25 1:19 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
` (48 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
Since the previous commit, an orphan with data to send is kept while
the peer acks something, at least the window probes: a peer keeping its
window closed, e.g. not reading, could then keep the orphan forever.
TCP limits this for its orphans: tcp_probe_timer() aborts them instead
of probing again after the max interval. The subflows of an MPTCP orphan
are not orphaned: they probe again then, and back off once more, up to
tcp_retries2. So check if TCP would have aborted them, when the close
timeout expires. Same with data in flight, when the peer has shrunk its
window to zero: tcp_retransmit_timer() only aborts orphans then.
Two corner cases needing non-default settings are not covered, which is
fine: an idle subflow refreshed by keepalives still keeps the orphan
when the stale detection is disabled, and tcp_orphan_retries is ignored.
This was found by an AI code review agent, while reviewing the previous
commit. With its reproducer and a long pause, the orphan was kept until
the end of the pause. It is now reset as TCP does, respecting
tcp_retries2.
Note for the backports: this patch is needed with the previous one, and
before v6.15, tcp_rto_max() can be replaced by TCP_RTO_MAX.
Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, to limit the orphans kept by the previous patch, with the same
Fixes tag to backport them together.
Note (Clashiko on v2): a peer acking the data at the TCP level only
keeps the orphan, but this is bounded by tcp_max_orphans and tcp_mem
since the next patch. With the stale detection, the probing subflow is
marked as stale, and its data is moved to the idle one.
---
net/mptcp/protocol.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 944c9d11d211..ff71f1954077 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2871,6 +2871,32 @@ static bool mptcp_close_tout_expired(const struct sock *sk)
inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
}
+/* Would TCP abort this subflow if it were an orphan probing a zero window? */
+static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
+{
+ u8 retries2 = READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_retries2);
+ struct inet_connection_sock *icsk = inet_csk(ssk);
+ const struct tcp_sock *tp = tcp_sk(ssk);
+ unsigned long limit;
+ bool slow, ret;
+ u64 when;
+
+ slow = lock_sock_fast_nested(ssk);
+ limit = tcp_rto_max(ssk);
+ if (tp->packets_out) {
+ ret = !tp->snd_wnd && icsk->icsk_rto >= limit;
+ } else {
+ if (icsk->icsk_backoff < retries2)
+ limit *= 2;
+ /* a shift of 32 already exceeds the limit */
+ when = (u64)icsk->icsk_rto << min_t(u8, icsk->icsk_backoff, 32);
+ ret = tcp_send_head(ssk) && when >= limit;
+ }
+ unlock_sock_fast(ssk, slow);
+
+ return ret;
+}
+
/* Before its DATA_FIN, keep an orphan while a subflow can send its data */
static bool mptcp_orphan_keep(struct sock *sk)
{
@@ -2886,7 +2912,8 @@ static bool mptcp_orphan_keep(struct sock *sk)
/* a live peer acks at least the probes, every TCP_RTO_MAX */
if (__mptcp_subflow_active(subflow) &&
tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
- 2 * TCP_RTO_MAX)
+ 2 * TCP_RTO_MAX &&
+ !mptcp_subflow_probe_timed_out(ssk))
return true;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-25 1:21 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
` (47 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The MPTCP sockets orphaned by close() were not counted in
tcp_orphan_count, contrary to TCP: tcp_max_orphans did not limit them,
and they were not visible in /proc/net/sockstat.
This is all the more needed since commit "mptcp: keep an orphan while it
can send its data": an orphan can then be kept longer than its close
timeout, e.g., as Sashiko noticed, by a peer acking the data at the TCP
level only, without moving the DATA_ACK.
Count them, and as TCP does, reset an orphan when there are too many
orphans, or when TCP uses too much memory: at close(), and when its
close timeout expires while it is kept to send its data. This is similar
to what tcp_out_of_resources() does from the TCP timers, without the
stricter limit for the stalled orphans. These resets are counted in
TCPAbortOnMemory, not in a new MPTCP counter: the MPTCP orphans now
share the TCP orphan count and limits.
This has been found by a review agent, and validated with a script
closing 8 connections whose peer doesn't read, with tcp_max_orphans set
to 4: the MPTCP orphans were all kept, without being counted, while
other orphans were reset. Now, only 5 or 6 are kept, vs 4 or 5 with TCP,
which also checks the limit from the timers of its orphans.
Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, spotted by a review agent
Note (Clashiko on v2): the reset reason stays TCP_ABORT_ON_CLOSE, as for
the other fastclose resets: only the tracepoint is affected.
---
net/mptcp/protocol.c | 24 ++++++++++++++++++++++--
net/mptcp/protocol.h | 1 +
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ff71f1954077..9e297fa08bfe 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2897,6 +2897,16 @@ static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
return ret;
}
+/* As TCP orphans: limited in number and memory */
+static bool mptcp_orphan_oom(struct sock *sk)
+{
+ if (!tcp_check_oom(sk, 0))
+ return false;
+
+ NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
+ return true;
+}
+
/* Before its DATA_FIN, keep an orphan while a subflow can send its data */
static bool mptcp_orphan_keep(struct sock *sk)
{
@@ -2914,7 +2924,7 @@ static bool mptcp_orphan_keep(struct sock *sk)
tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
2 * TCP_RTO_MAX &&
!mptcp_subflow_probe_timed_out(ssk))
- return true;
+ return !mptcp_orphan_oom(sk);
}
return false;
@@ -3547,6 +3557,9 @@ static void __mptcp_destroy_sock(struct sock *sk)
sk_stream_kill_queues(sk);
xfrm_sk_free_policy(sk);
+ if (test_and_clear_bit(MPTCP_ORPHAN_COUNTED, &msk->flags))
+ tcp_orphan_count_dec();
+
sock_put(sk);
}
@@ -3636,8 +3649,15 @@ bool __mptcp_close(struct sock *sk, long timeout)
/* all the subflows are closed, only timeout can change the msk
* state, let's not keep resources busy for no reasons
*/
- if (subflows_alive == 0)
+ if (subflows_alive == 0) {
mptcp_set_state(sk, TCP_CLOSE);
+ } else if (sk->sk_state != TCP_CLOSE) {
+ /* as TCP orphans: counted, and limited */
+ tcp_orphan_count_inc();
+ set_bit(MPTCP_ORPHAN_COUNTED, &msk->flags);
+ if (mptcp_orphan_oom(sk))
+ mptcp_do_fastclose(sk);
+ }
sock_hold(sk);
pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 2c9a442dacd6..888ee9d66967 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -117,6 +117,7 @@
#define MPTCP_FALLBACK_DONE 2
#define MPTCP_WORK_CLOSE_SUBFLOW 3
#define MPTCP_RTX_ENABLED 4
+#define MPTCP_ORPHAN_COUNTED 5
/* MPTCP socket release cb flags */
#define MPTCP_PUSH_PENDING 1
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (2 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 1:57 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 05/50] mptcp: let TCP send orphan data after fallback Matthieu Baerts (NGI0)
` (46 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
Once an MPTCP socket has received a DATA_FIN, recv() returns the
remaining data, then EOF. But if the connection was then reset, e.g. by
an MP_FASTCLOSE, recv() returned an error after the data, e.g. EPIPE,
instead of EOF as TCP does. A proxy resetting the other connection on
read errors then dropped the data it still had to forward.
As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and
check it before the socket error in recvmsg(). With an MP_FASTCLOSE, the
data still in the backlog is moved first, not to miss the DATA_FIN.
After a fallback, a DATA_FIN is also emulated after a reset: only set
SOCK_DONE after a FIN, not to hide a reset behind an EOF. This FIN is
cleared when the first subflow is disconnected: process this DATA_FIN
before.
This was reported on GitHub, and is validated with new Packetdrill
tests: data and a DATA_FIN are received, then an MP_FASTCLOSE; and
after a fallback, data, a FIN and a reset. Without this patch, the
second read() returned EPIPE in both cases:
receive_fastclose_after_data_fin.pkt:27: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
v1_connect_tcpfallback_fin_reset.pkt:19: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
Note for the backports: the issue with an MP_FASTCLOSE comes from commit
69800e516e96 ("mptcp: propagate fastclose error"), in v6.1. Before that,
the modifications in mptcp_check_fastclose() and mptcp_disconnect() are
not needed.
Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for issue #647 reported on GitHub
v3: process the DATA_FIN before disconnecting the first subflow, which
clears its FIN (Clashiko)
Note (Clashiko on v2): with a DATA_FIN, then an MP_FASTCLOSE in
FIN_WAIT2, the reset subflows are only released at close(): not a leak.
A DATA_FIN mapped on another CPU while an MP_FASTCLOSE is processed can
still lead to ECONNRESET: two subflows racing, and the connection reset
by the peer anyway.
---
net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 9e297fa08bfe..de6da0b6c4ca 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -714,6 +714,10 @@ static void mptcp_check_data_fin(struct sock *sk)
WRITE_ONCE(msk->rcv_data_fin, 0);
WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
+ /* on fallback, also emulated after a reset: check for a FIN */
+ if (!__mptcp_check_fallback(msk) ||
+ (msk->first && sock_flag(msk->first, SOCK_DONE)))
+ sock_set_flag(sk, SOCK_DONE);
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
switch (sk->sk_state) {
@@ -972,6 +976,9 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
* destroy the msk as needed.
*/
ssk_state = inet_sk_state_load(ssk);
+ /* a FIN received before still leads to EOF, as with TCP */
+ if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
+ sock_set_flag(sk, SOCK_DONE);
if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
mptcp_set_state(sk, ssk_state);
WRITE_ONCE(sk->sk_err, -err);
@@ -2494,6 +2501,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
!timeo)
break;
} else {
+ if (sock_flag(sk, SOCK_DONE))
+ break;
+
copied = sock_error(sk);
if (copied)
break;
@@ -2813,6 +2823,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
struct mptcp_subflow_context *subflow)
{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+
/* The first subflow can already be closed or disconnected */
if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
return;
@@ -2820,12 +2832,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
subflow->close_event_done = true;
if (sk->sk_state == TCP_ESTABLISHED)
- mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
+ mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
/* subflow aborted before reaching the fully_established status
* attempt the creation of the next subflow
*/
- mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
+ mptcp_pm_subflow_check_next(msk, subflow);
+
+ /* On fallback, the FIN of the first subflow is cleared when it is
+ * disconnected: process the DATA_FIN emulated from it before.
+ */
+ if (ssk == msk->first && __mptcp_check_fallback(msk) &&
+ READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
+ mptcp_move_skbs(sk);
+ mptcp_check_data_fin(sk);
+ }
__mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
}
@@ -2938,6 +2959,11 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
if (likely(!READ_ONCE(msk->rcv_fastclose)))
return;
+ /* a DATA_FIN received before still leads to EOF, as with TCP */
+ if (READ_ONCE(msk->rcv_data_fin))
+ mptcp_move_skbs(sk);
+ mptcp_check_data_fin(sk);
+
mptcp_token_destroy(msk);
mptcp_for_each_subflow_safe(msk, subflow, tmp) {
@@ -3797,6 +3823,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
atomic64_set(&msk->rcv_wnd_sent, 0);
WRITE_ONCE(sk->sk_shutdown, 0);
+ sock_reset_flag(sk, SOCK_DONE);
sk_error_report(sk);
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 05/50] mptcp: let TCP send orphan data after fallback
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (3 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort " Matthieu Baerts (NGI0)
` (45 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After a fallback to TCP, once an orphaned MPTCP socket has given all its
data and the FIN to the subflow, the rest of the transfer is in the
hands of TCP. But when the close timeout expired, the subflow was reset,
and the data it still had was lost, e.g. with a peer reading slowly,
while TCP sends it, within the limits set for its orphans.
Close the MPTCP socket without reset in this case: the subflow is then
closed as after a graceful close, and TCP sends the remaining data.
Unless data received after close() has not been read: as in
__mptcp_close(), a reset is then needed. Before checking that, the
subflows stop passing data to the MPTCP socket: what is received later
stays there, and TCP resets when closing them.
This issue has been found by an AI code review agent, while validating a
fix for a similar issue, and confirmed with the reproducer from the
linked GitHub issue, adapted to a fallback: the writer is an MPTCP
client connected to a TCP server. The server got ECONNRESET after its
pause, while it gets everything with a TCP client, and now with an MPTCP
one too.
Fixes: d21f83485518 ("mptcp: use fastclose on more edge scenarios")
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for a similar issue found by a review agent
v3: stop passing data to the msk before checking for unread data, not
to ack data received meanwhile without reset (Clashiko)
---
net/mptcp/protocol.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index de6da0b6c4ca..f28262f07282 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2951,6 +2951,30 @@ static bool mptcp_orphan_keep(struct sock *sk)
return false;
}
+/* On fallback, TCP can send what an orphan gave to the subflow. As in
+ * __mptcp_close(), unread data requires a reset, also in the backlog: stop
+ * passing data to the msk first, TCP resets on what is received later.
+ */
+static bool mptcp_orphan_handover(struct sock *sk)
+{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ struct mptcp_subflow_context *subflow;
+
+ if (!sock_flag(sk, SOCK_DEAD) || !__mptcp_check_fallback(msk) ||
+ msk->snd_nxt != msk->write_seq)
+ return false;
+
+ mptcp_for_each_subflow(msk, subflow) {
+ struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+ lock_sock(ssk);
+ subflow->closing = 1;
+ release_sock(ssk);
+ }
+
+ return !mptcp_data_avail(msk) && !READ_ONCE(msk->backlog_len);
+}
+
static void mptcp_check_fastclose(struct mptcp_sock *msk)
{
struct mptcp_subflow_context *subflow, *tmp;
@@ -3298,6 +3322,10 @@ static void mptcp_worker(struct work_struct *work)
__mptcp_push_pending(sk, 0);
}
+ /* TCP will close the subflow, as with its own orphans */
+ if (mptcp_close_tout_expired(sk) && mptcp_orphan_handover(sk))
+ mptcp_set_state(sk, TCP_CLOSE);
+
if (mptcp_close_tout_expired(sk)) {
struct mptcp_subflow_context *subflow, *tmp;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort after fallback
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (4 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 05/50] mptcp: let TCP send orphan data after fallback Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 07/50] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
` (44 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After a fallback to TCP, closing an MPTCP socket with unread data, or
with SO_LINGER and a zero timeout, did not reset the connection as TCP
does: the data still in the MPTCP send queue was dropped, and the
subflow was closed with a FIN. The peer then got a truncated stream,
followed by EOF, without error.
mptcp_do_fastclose() sends a reset on each subflow, except after a
fallback: send it in this case too. No MPTCP option is added after a
fallback: this is a plain TCP reset. Its other callers, on disconnect()
and when the close timeout of an orphan expires, were already resetting
the subflow after a fallback, via tcp_disconnect(), in most states: the
reset is now sent as without a fallback.
When a listener is closed, its MPTCP sockets not accepted yet then got a
second reset from tcp_disconnect(), as already without fallback since
the commit below: move their subflow to TCP_CLOSE after the first reset
too, as done for the other subflows. This has been found by an AI code
review agent (Clashiko), and confirmed with Packetdrill, by counting the
resets: two in both cases, one with TCP.
This issue has been found by an AI code review agent, while reviewing
another fix, and confirmed with a new Packetdrill test: an MPTCP client
falls back to TCP, receives data, and closes the socket without reading
it. Without this patch, a FIN was sent instead of a reset:
v1_connect_tcpfallback_close_unread_data.pkt:19: error handling packet: live packet field tcp_fin: expected: 0 (0x0) vs actual: 1 (0x1)
Fixes: ae155060247b ("mptcp: fix duplicate reset on fastclose")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
v3: no second reset for the children of a closed listener, also without
fallback (Clashiko)
Note (Clashiko on v2): with SO_LINGER set to 0, a subflow in LAST_ACK or
CLOSING gets a reset, while TCP would only drop the unacked data.
---
net/mptcp/protocol.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index f28262f07282..bbb28f778d81 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2738,6 +2738,10 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
subflow->lent_mem_frag = 0;
}
+ /* also before accept(), not to reset again in inet_child_forget() */
+ if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE)
+ tcp_set_state(ssk, TCP_CLOSE);
+
/* If the first subflow moved to a close state before accept, e.g. due
* to an incoming reset or listener shutdown, the subflow socket is
* already deleted by inet_child_forget() and the mptcp socket can't
@@ -2756,9 +2760,6 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
if (dispose_it)
list_del(&subflow->node);
- if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE)
- tcp_set_state(ssk, TCP_CLOSE);
-
need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
if (!dispose_it) {
__mptcp_subflow_disconnect(ssk, subflow, msk->fastclosing);
@@ -3268,10 +3269,7 @@ static void mptcp_do_fastclose(struct sock *sk)
mptcp_backlog_purge(sk);
msk->fastclosing = 1;
- /* Explicitly send the fastclose reset as need */
- if (__mptcp_check_fallback(msk))
- return;
-
+ /* Explicitly send the fastclose reset, a plain one after a fallback */
mptcp_for_each_subflow_safe(msk, subflow, tmp) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 07/50] mptcp: wake up blocked senders when no sf left
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (5 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort " Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 08/50] mptcp: set SEND_SHUTDOWN on close by an sf error Matthieu Baerts (NGI0)
` (43 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When an MPTCP socket moves to TCP_CLOSE because its last subflow is
closed, after the close timeout or not, sk_shutdown was not updated, and
no error was set in most cases. A thread blocked in send() was then
never woken up for good.
Set SEND_SHUTDOWN in these cases: no more data can be sent. The blocked
send() then returns EPIPE, as a send() called after the close timeout
already does. Reporting another error first, e.g. ETIMEDOUT as TCP does
after a timeout, would change the behaviour seen by the applications:
this is left for net-next.
This was reported on GitHub, with a reproducer: the only subflow dies by
RTO, and send() was never woken up, while it returned ETIMEDOUT after a
few seconds with TCP. With this patch, send() returns EPIPE after the
subflow timeout (like TCP) and the close timeout (by default at 60
seconds). This is also validated with new Packetdrill tests, with the
close timeout, and with a reset received in CLOSE_WAIT. Without this
patch, send() stayed blocked in both cases:
close_timeout_blocked_send.pkt:24: runtime error: exiting while a blocking system call is in progress
close_wait_reset_blocked_send.pkt:25: runtime error: exiting while a blocking system call is in progress
Fixes: 27e5ccc2d5a5 ("mptcp: fix dangling connection hang-up")
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/648
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for issue #648 reported on GitHub
---
net/mptcp/protocol.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index bbb28f778d81..d54ca367fc39 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2814,6 +2814,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
} else if (sk->sk_state != TCP_ESTABLISHED ||
msk->in_accept_queue) {
mptcp_set_state(sk, TCP_CLOSE);
+ WRITE_ONCE(sk->sk_shutdown,
+ sk->sk_shutdown | SEND_SHUTDOWN);
mptcp_close_wake_up(sk);
} else {
mptcp_start_tout_timer(sk);
@@ -3330,6 +3332,7 @@ static void mptcp_worker(struct work_struct *work)
mptcp_do_fastclose(sk);
mptcp_for_each_subflow_safe(msk, subflow, tmp)
__mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
+ WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
mptcp_close_wake_up(sk);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 08/50] mptcp: set SEND_SHUTDOWN on close by an sf error
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (6 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 07/50] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 09/50] mptcp: start close timeout on initial sf shutdown Matthieu Baerts (NGI0)
` (42 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After a fallback to TCP, or during the MPC connection, an error on a
subflow is propagated to the MPTCP socket, which moves to TCP_CLOSE.
But sk_shutdown was not updated, while tcp_done() does it. A thread
blocked in send() was then only woken up by the socket error: if
another thread consumed it first, the sender went back to sleep, for
good.
Set SEND_SHUTDOWN here too, after the error, as tcp_done_with_error()
does, not to have poll() reporting a close without error in between.
Setting RCV_SHUTDOWN, as tcp_done() does, would change what recv()
returns once the error has been consumed: this is left for net-next.
This issue has been found by an AI code review agent, while fixing a
similar issue, and confirmed with a reproducer: after a fallback to TCP,
a thread reads and another one writes on the same socket, until the peer
resets the connection. A part of the writers were then still blocked in
send(), and none with TCP or with this patch.
Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for a similar issue found by a review agent
Note (Clashiko on v2): the comment in mptcp_poll() names
__mptcp_error_report(), not __mptcp_subflow_error_report():
pre-existing, can be fixed in net-next.
---
net/mptcp/protocol.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d54ca367fc39..d1bbba582aa1 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -979,9 +979,13 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
/* a FIN received before still leads to EOF, as with TCP */
if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
sock_set_flag(sk, SOCK_DONE);
- if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
- mptcp_set_state(sk, ssk_state);
WRITE_ONCE(sk->sk_err, -err);
+ if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD)) {
+ /* This barrier is coupled with smp_rmb() in mptcp_poll() */
+ smp_wmb();
+ WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
+ mptcp_set_state(sk, ssk_state);
+ }
report = true;
propagated = true;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 09/50] mptcp: start close timeout on initial sf shutdown
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (7 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 08/50] mptcp: set SEND_SHUTDOWN on close by an sf error Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data Matthieu Baerts (NGI0)
` (41 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When the initial subflow is closed while it is not in TCP_CLOSE, e.g.
after a FIN without DATA_FIN from the peer, it is only shut down, and
stays in the connection list. The check for an MPTCP socket without
subflows then missed it: it only looks for an initial subflow in
TCP_CLOSE, and when this subflow reaches this state later on,
mptcp_close_ssk() ignores it, as it has already been processed. A
socket still owned by the application then stayed without any usable
subflow, without close timeout nor error, and with blocked send() or
recv() calls, for good.
When only this shut down initial subflow remains, start the close
timeout, if it is not running yet.
This issue has been found by an AI code review agent, while reviewing a
similar fix, and also reported by Sashiko. It has been confirmed with a
new Packetdrill test: the peer closes the only subflow with a FIN,
without DATA_FIN. Without this patch, send() stayed blocked:
subflow_fin_blocked_send.pkt:26: runtime error: exiting while a blocking system call is in progress
The check only looks at TCP_CLOSE since the commit below, and
mptcp_close_ssk() ignores this subflow in this state since commit
d82809b6c5f2 ("mptcp: avoid duplicated SUB_CLOSED events"), which is in
all the stable versions having the commit below.
Fixes: 27e5ccc2d5a5 ("mptcp: fix dangling connection hang-up")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent, and Sashiko
Note (Clashiko on v2): in the accept queue, a new subflow can still join
during the timeout, and the first subflow is then disconnected, as after
an MP_FASTCLOSE received before accept(): checked with Packetdrill, no
warning. In the other states, the subflow is only shut down: it can
still receive data and the DATA_FIN.
---
net/mptcp/protocol.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d1bbba582aa1..5d916c6b43f4 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2824,6 +2824,14 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
} else {
mptcp_start_tout_timer(sk);
}
+ } else if (list_is_singular(&msk->conn_list) && msk->first &&
+ mptcp_subflow_ctx(msk->first)->closing &&
+ !inet_csk(sk)->icsk_mtup.probe_timestamp &&
+ sk->sk_state != TCP_CLOSE) {
+ /* The initial subflow has only been shut down, and its later
+ * close will be ignored: start the close timeout now.
+ */
+ mptcp_start_tout_timer(sk);
}
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (8 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 09/50] mptcp: start close timeout on initial sf shutdown Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
` (40 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
A DATA_FIN received in a DSS option with a data mapping, or without data
in the middle of a mapping, is recorded by get_mapping_status(), but its
processing was left to the code moving the mapped data to the MPTCP
socket. If this data is old, e.g. the last data retransmitted at the
MPTCP level with the DATA_FIN, it is discarded at the subflow level, and
never moved to the MPTCP socket: the DATA_FIN is then not processed,
while ack_seq has already reached it. Later retransmissions of this
DATA_FIN are ignored too, as it has already been recorded: the peer
might then never get a DATA_ACK for it, and the reader the end of file.
This issue was causing a subtest from mptcp_connect_mmap.sh to fail,
after a spurious MPTCP-level retransmission from the client
(MPTCPRetrans on the client, DuplicateData on the server). The server
had received all the data, its ack_seq being at the DSN of the
DATA_FIN, which was retransmitted 9 times by the client, still in
FIN-WAIT-1:
26 ns2 MPTCP -> ns4 (dead:beef:3::1:10023) MPTCP timeout
(...)
mptcp ESTAB (...) rcv_nxt:17234557033099169620 (...)
(...)
mptcp FIN-WAIT-1 (...) write_seq:17234557033099169621 snd_una:17234557033099169620 (...) retransmits:9 (...)
(...)
(duration 61384ms) [FAIL] client exit code 143, server 143
The root cause has been confirmed with new Packetdrill tests: data is
received, then the same data again at the MPTCP level, with the DATA_FIN
in the same DSS option, or in a DSS option without data, in the middle
of this mapping. Without this patch, the DATA_FIN was never acked:
dss_fin_after_old_data_server.pkt:23: error handling packet: Timed out waiting for packet
dss_fin_mid_old_mapping_server.pkt:22: error handling packet: Timed out waiting for packet
To fix this, schedule the worker when this DATA_FIN is recorded, as it
is already done for a DATA_FIN without data outside a mapping:
mptcp_check_data_fin() then processes it if ack_seq has already reached
it. If not, it is still processed once the data before it is moved to
the MPTCP socket.
Fixes: 43b54c6ee382 ("mptcp: Use full MPTCP-level disconnect state machine")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue causing a flaky selftest
---
net/mptcp/subflow.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 054ee992904e..67a749643ad7 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1242,6 +1242,10 @@ static enum mapping_status get_mapping_status(struct sock *ssk,
bool updated = mptcp_update_rcv_data_fin(msk, mpext->data_seq,
mpext->dsn64);
pr_debug("DATA_FIN with no payload seq=%llu\n", mpext->data_seq);
+ /* The current mapping can be old, and then not moved */
+ if (updated)
+ mptcp_schedule_work((struct sock *)msk);
+
if (subflow->map_valid) {
/* A DATA_FIN might arrive in a DSS
* option before the previous mapping
@@ -1252,9 +1256,6 @@ static enum mapping_status get_mapping_status(struct sock *ssk,
return MAPPING_OK;
}
- if (updated)
- mptcp_schedule_work((struct sock *)msk);
-
return MAPPING_DATA_FIN;
}
@@ -1266,7 +1267,9 @@ static enum mapping_status get_mapping_status(struct sock *ssk,
if (!mpext->dsn64)
data_fin_seq &= GENMASK_ULL(31, 0);
- mptcp_update_rcv_data_fin(msk, data_fin_seq, mpext->dsn64);
+ /* The mapped data can be old, and then not moved to the msk */
+ if (mptcp_update_rcv_data_fin(msk, data_fin_seq, mpext->dsn64))
+ mptcp_schedule_work((struct sock *)msk);
pr_debug("DATA_FIN with mapping seq=%llu dsn64=%d\n",
data_fin_seq, mpext->dsn64);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (9 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
` (39 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When the last subflow is closed while the MPTCP socket is no longer in
the ESTABLISHED state, e.g. in CLOSE_WAIT after a DATA_FIN, the MPTCP
socket moves to TCP_CLOSE. But this subflow could have been closed by a
reset carrying an MP_FASTCLOSE, not processed yet: if this reset is
received while the worker is running, after mptcp_check_fastclose(), and
before __mptcp_close_subflow(). At the next run of the worker, the MPTCP
socket being closed, the MP_FASTCLOSE is ignored, and no error is
reported.
This issue has been observed with the "fastclose test" subtest from
mptcp_join.sh: after the DATA_FIN from the client, then its
MP_FASTCLOSE, the server, still having data to send, was killed after
the timeout:
[FAIL] client exit code 0, server 143
Since commit "mptcp: wake up blocked senders when no sf left", this
subtest no longer fails: SEND_SHUTDOWN is set in this case, and the
server gets EPIPE when writing, which is expected there. But the reset
is still not reported. This has been confirmed with a debug patch
keeping the worker busy until the subflow is closed, and Packetdrill
scripts sending an MP_FASTCLOSE in this window: in CLOSE_WAIT, SO_ERROR
was 0 instead of EPIPE, and poll() did not report EPOLLERR; in
FIN_WAIT2, read() returned ENOTCONN instead of ECONNRESET:
fastclose_close_wait_race_err.pkt:26: runtime error in getsockopt call: Bad getsockopt optval: expected: 32 actual: 0
fastclose_fin_wait2_race_read.pkt:28: runtime error in read call: Expected errno 104 (Connection reset by peer) but got 107 (Transport endpoint is not connected)
To fix this, process a pending MP_FASTCLOSE before the close, if the
socket is still in use.
Fixes: 27e5ccc2d5a5 ("mptcp: fix dangling connection hang-up")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue causing a flaky selftest
v3: msg: the subtest no longer fails since patch 7, and the remaining
issue, checked with Packetdrill (Clashiko)
---
net/mptcp/protocol.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 5d916c6b43f4..bcdad00d3573 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2705,6 +2705,8 @@ static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
mptcp_data_unlock(sk);
}
+static void mptcp_check_fastclose(struct mptcp_sock *msk);
+
/* subflow sockets can be either outgoing (connect) or incoming
* (accept).
*
@@ -2817,6 +2819,9 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
mptcp_schedule_work(sk);
} else if (sk->sk_state != TCP_ESTABLISHED ||
msk->in_accept_queue) {
+ /* After the close, an MP_FASTCLOSE would be ignored */
+ mptcp_check_fastclose(msk);
+
mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown,
sk->sk_shutdown | SEND_SHUTDOWN);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (10 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 22:33 ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
` (38 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When the last subflow is closed while the MPTCP socket is no longer in
the ESTABLISHED state, e.g. after a shutdown(SHUT_WR), the MPTCP socket
moves to TCP_CLOSE. But the peer's DATA_FIN -- or FIN, after a fallback
to TCP -- might not have been processed yet: e.g. if the last data was
received while the worker owned the MPTCP socket, this data is still in
the backlog, and the DATA_FIN can only be processed once the data before
it is in. When the backlog is spooled later on, mptcp_check_data_fin()
ignores the DATA_FIN, the socket being closed. RCV_SHUTDOWN is then
never set: after the remaining data, poll() reports EPOLLHUP, but
neither EPOLLIN nor EPOLLRDHUP, and recv() returns ENOTCONN instead of
EOF.
Before the commit using the MPTCP-level backlog for the RX path, the
data received while the MPTCP socket was owned was left in the subflow,
and a subflow with data in its receive queue was not closed.
This issue was causing the "Infinite map" subtest from mptcp_join.sh to
be flaky: the server only got EPOLLHUP after having received all the
data, and spun until the timeout:
timeout
(...)
tcp TIME-WAIT 0 0 [::ffff:10.0.1.1]:10123 [::ffff:10.0.1.2]:51790 (...)
mptcp UNCONN 0 0 [::ffff:10.0.1.1]:10123 [::ffff:10.0.1.2]:51790 (...)
(...) fallback (...) bytes_sent:131100 bytes_received:131100 (...)
(...)
[FAIL] client exit code 0, server 143
The same issue was causing the 'peek mode' and 'full disconnect'
subtests from mptcp_connect.sh to be flaky, in the MPTCP to TCP cases,
so after a fallback at the connection: the client never got the end of
file:
64 ns1 MPTCP -> ns1 (10.0.1.1:20002 ) TCP main_loop_s: timed out
(...)
mptcp UNCONN 0 0 10.0.1.1:35046 10.0.1.1:20002 (...) <--
(...) fallback (...) bytes_sent:714380 bytes_received:714380 (...)
(...) [FAIL] client exit code 143, server 2
The root cause has been confirmed with a debug patch keeping the worker
in FIN_WAIT2 after a fallback, until the subflow is closed: the same
failures have been seen in the "Infinite map" subtest, and in the 'peek
mode' and 'full disconnect' parts of mptcp_connect.sh, with the socket
closed before the DATA_FIN:
(...) closed with a pending DATA_FIN, state=5 ack_seq=11784643520213419601 data_fin_seq=11784643520213452397 backlog=35484
To fix this, spool the backlog and process the pending DATA_FIN before
the close, if the socket is still in use. This is done in a new helper,
mptcp_check_rcv_close(), also processing a pending MP_FASTCLOSE: the
next commit uses it at accept() time too. With the same debug patch,
these subtests no longer failed.
Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue causing flaky selftests
Note (Clashiko on v2): after a fallback, the FIN cleared when the first
subflow is disconnected is now handled by "mptcp: return EOF after a
DATA_FIN, as TCP does".
---
net/mptcp/protocol.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index bcdad00d3573..b57d0f82b416 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2707,6 +2707,18 @@ static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
static void mptcp_check_fastclose(struct mptcp_sock *msk);
+/* After the close, a pending DATA_FIN or MP_FASTCLOSE would be ignored */
+static void mptcp_check_rcv_close(struct sock *sk)
+{
+ /* process the DATA_FIN after the data still in the backlog */
+ if (READ_ONCE(mptcp_sk(sk)->rcv_data_fin)) {
+ mptcp_move_skbs(sk);
+ mptcp_check_data_fin(sk);
+ }
+
+ mptcp_check_fastclose(mptcp_sk(sk));
+}
+
/* subflow sockets can be either outgoing (connect) or incoming
* (accept).
*
@@ -2819,9 +2831,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
mptcp_schedule_work(sk);
} else if (sk->sk_state != TCP_ESTABLISHED ||
msk->in_accept_queue) {
- /* After the close, an MP_FASTCLOSE would be ignored */
- mptcp_check_fastclose(msk);
-
+ mptcp_check_rcv_close(sk);
mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown,
sk->sk_shutdown | SEND_SHUTDOWN);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept()
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (11 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept() Matthieu Baerts (NGI0)
` (37 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When the only subflow of a new MPTCP socket has been closed before
accept(), e.g. reset by the peer, mptcp_stream_accept() moves this
socket to the CLOSE state, then closes the subflow. A DATA_FIN or an
MP_FASTCLOSE received before, but not processed yet by the worker, was
then ignored: the code processing them before closing an MPTCP socket
without subflows, and the worker, skip a socket already closed.
recv() then returned ENOTCONN after the data, instead of EOF after a
DATA_FIN, or ECONNRESET after an MP_FASTCLOSE alone, as TCP does.
This race has been found by a review agent, and confirmed with
Packetdrill scripts and a debug patch delaying the worker of the MPTCP
sockets in the accept queue: data, a DATA_FIN or not, then a reset with
an MP_FASTCLOSE are received before accept(). Without this patch, the
second read() returned ENOTCONN in both cases:
With DATA_FIN: runtime error in read call: Expected result 0 but got -1 with errno 107 (Transport endpoint is not connected)
Without DATA_FIN: runtime error in read call: Expected errno 104 (Connection reset by peer) but got 107 (Transport endpoint is not connected)
To fix this, process them before moving to the CLOSE state, with
mptcp_check_rcv_close(), as done when closing the MPTCP socket without
subflows.
Note for the backports: before v6.19, this helper, added by the previous
commit, is not available, and mptcp_stream_accept() closes the subflow
before moving to the CLOSE state.
Fixes: 63740448a32e ("mptcp: fix accept vs worker race")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
Note (Clashiko on v2): after a fallback, a reset received before
accept() was not reported when the worker processed it before accept():
pre-existing, fixed by the next patch.
---
net/mptcp/protocol.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b57d0f82b416..8edff68ec650 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4703,8 +4703,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
* deal with bad peers not doing a complete shutdown.
*/
if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
- if (unlikely(list_is_singular(&msk->conn_list)))
+ if (unlikely(list_is_singular(&msk->conn_list))) {
+ mptcp_check_rcv_close(newsk);
mptcp_set_state(newsk, TCP_CLOSE);
+ }
mptcp_close_ssk(newsk, msk->first,
mptcp_subflow_ctx(msk->first));
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept()
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (12 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
` (36 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After a fallback to TCP, when the subflow of a new MPTCP socket has been
reset before accept(), and the worker processed it before accept() too,
the error was lost: read() returned EOF after the data, instead of
ECONNRESET, and after a FIN followed by a reset, SO_ERROR was not set to
EPIPE, as TCP does.
subflow_error_report() skips the MPTCP sockets in the accept queue,
without a socket attached. Before v6.19, the error was then reported
when accept() closed the subflow again. Since the commit below,
mptcp_close_ssk() is used there, which skips this subflow, already
disconnected, since commit 280d654324e3 ("mptcp: avoid dup SUB_CLOSED
events after disconnect").
At accept() time, when the subflow has already been closed, report its
error, after having processed the pending close events.
This issue has been found by an AI code review agent (Clashiko), while
reviewing the previous commit, and confirmed with a new Packetdrill
test: after a fallback, data and a reset are received before accept().
Without this patch, the second read() returned EOF:
v1_bind_tcpfallback_reset_before_accept.pkt:21: runtime error in read call: Expected result -1 but got 0 with errno 22 (Invalid argument)
Fixes: 48a395605e08 ("mptcp: do not miss early first subflow close event notification")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v3: new, for an issue spotted by Clashiko
---
net/mptcp/protocol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 8edff68ec650..ff1dcf306723 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4705,6 +4705,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
if (unlikely(list_is_singular(&msk->conn_list))) {
mptcp_check_rcv_close(newsk);
+ /* not reported in the accept queue */
+ __mptcp_error_report(newsk);
mptcp_set_state(newsk, TCP_CLOSE);
}
mptcp_close_ssk(newsk, msk->first,
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (13 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept() Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 6:40 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
` (35 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After a disconnect with connect(AF_UNSPEC), an error from the previous
connection, e.g. a reset not reported yet to the application, was still
reported for the next connection, by poll(), SO_ERROR, and the first
send() or recv(). TCP clears it in tcp_connect_init(): do the same,
once the subflow connect() succeeded, so an early failure keeps it.
This issue has been found by an AI code review agent, while reviewing
other fixes, and confirmed with a reproducer: the peer resets the
connection, the error is not read, then the socket is disconnected and
connected again. SO_ERROR then reported ECONNRESET each time, while TCP
reported no error, as MPTCP now does.
Fixes: 3d1d6d66e156 ("mptcp: implement support for user-space disconnect")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
---
net/mptcp/protocol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ff1dcf306723..6328815ad273 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4452,6 +4452,8 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
if (err < 0)
goto out;
+ /* as tcp_connect_init(): drop an error from a previous connection */
+ WRITE_ONCE(sk->sk_err, 0);
inet_assign_bit(DEFER_CONNECT, sk, inet_test_bit(DEFER_CONNECT, ssk));
out:
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (14 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 6:41 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect Matthieu Baerts (NGI0)
` (34 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
With TCP_FASTOPEN_CONNECT, mptcp_connect() copies the DEFER_CONNECT bit
of the first subflow to the msk. This bit is cleared on the first
write(), but not when the msk is disconnected, e.g. with
connect(AF_UNSPEC) before any write().
tcp_disconnect() clears this bit on the subflow, but mptcp_disconnect()
leaves it set on the msk. The next write() then goes through
mptcp_sendmsg_fastopen(), and tries to connect the msk again with a NULL
address: mptcp_connect() moves the msk back to SYN_SENT, possibly
allocates a token and increments the MPCapableActive counter, before the
subflow connect() fails. -EINVAL is then returned, instead of -EPIPE.
The stale bit is also reported by the diag interface.
Clear DEFER_CONNECT in mptcp_disconnect(), like tcp_disconnect() does.
This issue has been found by an AI code review agent, while fixing a
similar issue, and confirmed with a new Packetdrill test: a deferred
connect, then connect(AF_UNSPEC), then send(). Without this patch,
send() failed with EINVAL:
client-TCP_FASTOPEN_CONNECT-disconnect.pkt:35: runtime error in send call: Expected errno 32 (Broken pipe) but got 22 (Invalid argument)
Fixes: a42cf9d18278 ("mptcp: poll allow write call before actual connect")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
---
net/mptcp/protocol.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6328815ad273..257c851c8a76 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3828,6 +3828,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
mptcp_check_listen_stop(sk);
mptcp_set_state(sk, TCP_CLOSE);
+ inet_clear_bit(DEFER_CONNECT, sk);
/* The later subflow close can not kick again the tout timer,
* as the msk is already in closed status.
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (15 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
` (33 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
With TCP_FASTOPEN_CONNECT, connect() on an MPTCP socket only sets
DEFER_CONNECT on the first subflow and on the msk, and the first write()
sends the SYN with data via mptcp_sendmsg_fastopen().
If the first subflow is aborted by tcp_abort(), e.g. via a sock_diag
destroy request or the bpf_sock_destroy() kfunc, while mptcp_sendmsg()
already owns the msk socket and is waiting for the subflow lock:
- tcp_abort() clears DEFER_CONNECT on the subflow, and moves it to
TCP_CLOSE;
- subflow_error_report() can only set MPTCP_ERROR_REPORT, because the
msk is owned by the user: the msk stays in SYN_SENT, with
DEFER_CONNECT still set.
tcp_sendmsg_fastopen() then skips tcp_connect(), and calls
__inet_stream_connect() with the msk socket, the first subflow being
grafted to it. Because DEFER_CONNECT is set on the msk, -EISCONN is
returned to userspace, on a connection that has just been aborted.
Detect this case once the subflow lock is held: if DEFER_CONNECT is set
on the msk, but no longer on the subflow, the subflow has been aborted,
or disconnected. Propagate the subflow error to the msk directly,
instead of waiting for the msk release callback. mptcp_sendmsg() will
then report this error via sk_stream_wait_connect(), like plain TCP
after tcp_abort(), e.g. -ECONNABORTED. The deferred error report is then
a no-op, so the error is not reported twice.
Without the race, the msk is already in TCP_CLOSE with the error set:
the same check also avoids going through tcp_sendmsg_fastopen() and
__inet_stream_connect() in this case, except with MSG_FASTOPEN. As TCP
does, write() then reports the error without disconnecting the socket.
With MSG_FASTOPEN, the socket has to be disconnected, as with TCP, for
the next sendto() to connect again, and the race cannot happen:
__mptcp_nmpc_sk() requires an msk in TCP_CLOSE.
Clearing DEFER_CONNECT on the msk from tcp_abort_override() instead
would not be enough: tcp_abort() is called on the subflow without the
msk lock, and mptcp_sendmsg() checks the msk bit before taking the
subflow lock. The abort can then happen in between, and write() would
return -EALREADY, followed by a disconnect of the msk dropping the
deferred error. In this path, only mptcp_sendmsg_fastopen() holds both
the msk and the subflow locks, and sees a consistent state.
This issue has been reported by Sashiko, while reviewing the commit
below. It has not been reproduced: the abort has to happen while write()
owns the msk socket, and waits for the subflow lock.
Fixes: 93723db43e51 ("tcp: Clear DEFER_CONNECT before tcp_connect() and in tcp_abort().")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue spotted by Sashiko
v3: comment and msg: also after a disconnect, and what write() does
without the race (Clashiko)
---
net/mptcp/protocol.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 257c851c8a76..87f6da0f6cab 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1960,8 +1960,6 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
/* on flags based fastopen the mptcp is supposed to create the
* first subflow right now. Otherwise we are in the defer_connect
* path, and the first subflow must be already present.
- * Since the defer_connect flag is cleared after the first succsful
- * fastopen attempt, no need to check for additional subflow status.
*/
if (msg->msg_flags & MSG_FASTOPEN) {
ssk = __mptcp_nmpc_sk(msk);
@@ -1974,6 +1972,19 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
ssk = msk->first;
lock_sock(ssk);
+
+ /* subflow aborted or disconnected: its error report may be deferred.
+ * With MSG_FASTOPEN, the socket is disconnected below, as with TCP.
+ */
+ if (unlikely(!(msg->msg_flags & MSG_FASTOPEN) &&
+ inet_test_bit(DEFER_CONNECT, sk) &&
+ !inet_test_bit(DEFER_CONNECT, ssk))) {
+ inet_clear_bit(DEFER_CONNECT, sk);
+ __mptcp_subflow_error_report(sk, ssk);
+ release_sock(ssk);
+ return 0;
+ }
+
msg->msg_flags |= MSG_DONTWAIT;
msk->fastopening = 1;
ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (16 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 7:04 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections Matthieu Baerts (NGI0)
` (32 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
mptcp_do_fastclose() sends a reset with an MP_FASTCLOSE on each subflow
not in LISTEN or CLOSE, also on the ones in SYN_SENT, while TCP sends no
reset in this state, see tcp_need_reset() used by tcp_disconnect(). On a
disconnect in SYN_SENT, e.g. with connect(AF_UNSPEC), an MPTCP client
then sends a reset with an MP_FASTCLOSE carrying an unknown key, 0. With
TCP_FASTOPEN_CONNECT, this reset is even sent before any SYN.
Before the commit below, these resets were sent by tcp_disconnect(), so
not in SYN_SENT. Skip them again in this state, as TCP does, but move
the subflow to TCP_CLOSE at once, as tcp_disconnect() does: a SYN-ACK
received before the end of the close cannot complete the connection, and
a later one gets a reset from the stack.
This issue has been found by an AI code review agent, while reviewing
"mptcp: clear DEFER_CONNECT on disconnect", and confirmed with a new
Packetdrill test: a disconnect in SYN_SENT, then the SYN-ACK. Without
this patch, a reset with MPTCP options was sent at the disconnect,
before the one replying to the SYN-ACK:
disconnect_in_syn_sent.pkt:16: error handling packet: live packet field ipv4_total_length: expected: 40 (0x28) vs actual: 56 (0x38)
Fixes: ae155060247b ("mptcp: fix duplicate reset on fastclose")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
v3: move the subflow to TCP_CLOSE at once, not to complete the
connection with a SYN-ACK received in between (Clashiko)
---
net/mptcp/protocol.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 87f6da0f6cab..6c712f677220 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3321,6 +3321,12 @@ static void mptcp_do_fastclose(struct sock *sk)
subflow->send_fastclose = 1;
+ /* no reset in SYN_SENT, but a close at once, as TCP does */
+ if (ssk->sk_state == TCP_SYN_SENT) {
+ tcp_set_state(ssk, TCP_CLOSE);
+ goto unlock;
+ }
+
/* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
* issue in __tcp_select_window(), see tcp_disconnect().
*/
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (17 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 8:20 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
` (31 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
A sendmsg() with MSG_FASTOPEN on an MPTCP listener fails, e.g. with
EISCONN, as with TCP, but it also closes the listener: after any error,
mptcp_sendmsg_fastopen() retries the disconnect that could have failed
in __inet_stream_connect(), while there is nothing to retry for a
listener. On a connection closed by both sides, with data still to be
read, the same retry also drops this data and the end of the stream.
Skip this disconnect for a listener and for a connected socket:
__inet_stream_connect() returned without trying to disconnect them. They
are then kept as they are, as with TCP.
This issue has been found by an AI code review agent, while reviewing
"mptcp: report sf aborts during deferred connect", and confirmed with a
new Packetdrill test: sendto() with MSG_FASTOPEN on a listener, then a
SYN. Without this patch, the SYN got a reset instead of a SYN-ACK:
listen_sendto_fastopen.pkt:14: error handling packet: live packet field ipv4_total_length: expected: 60 (0x3c) vs actual: 40 (0x28)
The case of the closed connection has been found by an AI code review
agent (Clashiko), while reviewing a previous version of this patch, and
confirmed with another Packetdrill test: after a shutdown(), data and a
DATA_FIN are received, then sendto() with MSG_FASTOPEN fails with
EISCONN. Without this patch, the data could no longer be read:
closed_sendto_fastopen.pkt:30: runtime error in read call: Expected result 1000 but got -1 with errno 107 (Transport endpoint is not connected)
Fixes: 7d803344fdc3 ("mptcp: fix deadlock in fastopen error path")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
v3: also skip it for a connected socket, not to drop unread data
(Clashiko)
Note (Clashiko on v2): only retrying a disconnect that failed, with
SS_DISCONNECTING, would leave a deferred socket stuck after an early
error from tcp_sendmsg_fastopen(), DEFER_CONNECT being cleared on the
msk: then, the disconnect is still retried, as before.
---
net/mptcp/protocol.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 6c712f677220..d529cfb582a5 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2004,11 +2004,14 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
*/
if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
*copied_syn = 0;
- } else if (ret && ret != -EINPROGRESS) {
+ } else if (ret && ret != -EINPROGRESS && sk->sk_state != TCP_LISTEN &&
+ sk->sk_socket->state != SS_CONNECTED) {
/* The disconnect() op called by tcp_sendmsg_fastopen()/
* __inet_stream_connect() can fail, due to looking check,
* see mptcp_disconnect().
* Attempt it again outside the problematic scope.
+ * A listener or a connected socket is not disconnected there,
+ * as with TCP.
*/
if (!mptcp_disconnect(sk, 0)) {
sk->sk_disconnects++;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (18 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 7:07 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners Matthieu Baerts (NGI0)
` (30 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
A new msk is a copy of its listener, made without the listener's lock:
if the application calls sendmsg() with MSG_FASTOPEN on the listener at
the same time, the new msk can inherit msk->fastopening, only set during
tcp_sendmsg_fastopen(). mptcp_disconnect() then fails on this socket:
connect(AF_UNSPEC) returns EBUSY.
Clear this flag when creating a new msk.
This issue has been found by an AI code review agent, while reviewing
"mptcp: fastopen: keep listeners and connections": before this other
fix, these new sockets were mostly reset with the listener. It has been
confirmed with a Packetdrill test, and a debug delay added in
mptcp_sendmsg_fastopen(), during which the handshake completes. Without
this patch, connect(AF_UNSPEC) on the accepted socket failed:
runtime error in connect call: Expected result 0 but got -1 with errno 16 (Device or resource busy)
Fixes: 7d803344fdc3 ("mptcp: fix deadlock in fastopen error path")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
v3: msg: the new title of the previous patch
---
net/mptcp/protocol.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d529cfb582a5..b1072123397f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4005,6 +4005,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
WRITE_ONCE(msk->local_key, subflow_req->local_key);
WRITE_ONCE(msk->token, subflow_req->token);
msk->in_accept_queue = 1;
+ msk->fastopening = 0;
WRITE_ONCE(msk->fully_established, false);
if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD)
WRITE_ONCE(msk->csum_enabled, true);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (19 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
` (29 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
With SYN cookies enabled, a port-based MPTCP signal endpoint can stop
accepting new subflows until it is deleted.
Nobody calls accept() on the listener that the in-kernel path manager
opens for such an endpoint, so it must create only MP_JOIN subflows,
which never enter the accept queue. The listener is marked pm_listener,
and since commit 3d041393ea8c ("mptcp: prevent MPC handshake on
port-based signal endpoints") subflow_check_req() refuses a SYN with no
MP_JOIN option on it. But a SYN cookie does not record the MPTCP option
of the SYN, so mptcp_subflow_init_cookie_req() picks the kind of child
from the options of the ACK, without looking at pm_listener:
ACK with a valid cookie and no MP_JOIN option
creates a plain TCP child, or an MPTCP one if it has MP_CAPABLE
which stays on the accept queue until the endpoint is deleted
once the queue is full, the listener drops MP_JOIN SYNs too
These children also hold a reference on the netns: since commit "mptcp:
pm: don't let listeners pin their netns", they are what keeps it alive
for ever once its last process is gone, unless somebody deletes the
endpoint, as noted by Clashiko on that commit.
The fix used here is to refuse an ACK with no MP_JOIN option on such a
listener in mptcp_subflow_init_cookie_req(), so that the request sock is
freed and the ACK is dropped.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
a client sent 1025 ACKs with valid SYN cookies and no MP_JOIN to the
listener of such an endpoint. Without this patch, its accept queue
stayed full, and another client could not create its additional subflow,
even 130 seconds later:
TCP: request_sock_subflow_v4: Possible SYN flooding on port 10.9.0.2:6666. Sending cookies.
[...]
C2 4.007 [130 s after C1 has gone] RESULT: subflows established 1, in SYN_SENT 1, the service works
--- V, after that try of C2
listener 10.9.0.2:6666 Recv-Q 1025 Send-Q 1024
With the same reproducer, adapted to delete the namespace of the
listener after a few of these ACKs, this namespace was not freed:
srv: listener of the endpoint: Recv-Q 4
srv: deleted, then NOT taken down after 60 s
Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port")
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment, the details are in the commit message. Commit
message: how the issue was found, its symptoms, and the netns pinned
by the queued children. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v3: commit msg: the netns pinned by the queued children (Clashiko)
---
net/mptcp/subflow.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 67a749643ad7..91698d154c40 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -315,6 +315,11 @@ int mptcp_subflow_init_cookie_req(struct request_sock *req,
opt_mp_capable = !!(mp_opt.suboptions & OPTION_MPTCP_MPC_ACK);
opt_mp_join = !!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK);
+
+ /* PM listeners only take MP_JOIN, like in subflow_check_req() */
+ if (unlikely(listener->pm_listener) && !opt_mp_join)
+ return subflow_reset_req_endp(req, skb);
+
if (opt_mp_capable && listener->request_mptcp) {
if (mp_opt.sndr_key == 0)
return -EINVAL;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (20 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 23/50] mptcp: pm: kernel: count endpoint listeners as sockets in use Matthieu Baerts (NGI0)
` (28 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
An MPTCP socket can stay in the ESTABLISHED state after MPTCP has reset
its only subflow because of data with no valid mapping, and recv() and
send() then block with no error.
If data arrives with no valid mapping and a fallback to TCP is not
possible, subflow_check_data_avail() resets the subflow: it moves the
TCP socket to TCP_CLOSE with tcp_set_state() and sends a RST. The MPTCP
worker then has to close the subflow in __mptcp_close_subflow(), and
closing the last subflow starts a timer that moves the MPTCP socket to
TCP_CLOSE. But the worker only calls that function if the bit
MPTCP_WORK_CLOSE_SUBFLOW is set, and this reset neither sets the bit nor
schedules the worker.
The fix used here is to call subflow_sched_work_if_closed() after the
reset, which sets the bit and schedules the worker. This also covers
the reset done after a bad checksum, when MP_FAIL cannot be used.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch,
and with a new Packetdrill test: data without DSS while the fallback is
not possible, here because of out-of-order data at the MPTCP level.
Without this patch, the subflow was reset, but the MPTCP socket stayed
established, with no subflow: read() returned EAGAIN and send() timed
out, for good:
dss_drop_ooo_reset_server.pkt:30: runtime error in read call: Expected errno 107 (Transport endpoint is not connected) but got 11 (Resource temporarily unavailable)
Fixes: 40947e13997a ("mptcp: schedule worker when subflow is closed")
Signed-off-by: Chris Mason <mason@kernel.org>
[ Add a Fixes tag. Moved before "mptcp: continue the last mapping after
a fallback", which makes this reset path reachable in more cases.
Commit message: how the issue was found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: commit msg: the reset after a bad checksum too (Sashiko)
---
net/mptcp/subflow.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 91698d154c40..a216d88d35ee 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1505,8 +1505,8 @@ static bool subflow_check_data_avail(struct sock *ssk)
}
if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
- /* fatal protocol error, close the socket.
- * subflow_error_report() will introduce the appropriate barriers
+ /* fatal protocol error, reset the subflow and let the
+ * worker close it
*/
subflow->reset_transient = 0;
MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSRESET);
@@ -1521,6 +1521,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
sk_eat_skb(ssk, skb);
mptcp_send_active_reset_reason(ssk);
WRITE_ONCE(subflow->data_avail, false);
+ subflow_sched_work_if_closed(msk, ssk);
return false;
}
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 23/50] mptcp: pm: kernel: count endpoint listeners as sockets in use
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (21 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 24/50] mptcp: count a listener once when listen() is called again Matthieu Baerts (NGI0)
` (27 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Kyuwon Cho
The listener that the in-kernel path manager creates for a "signal"
endpoint with a port is not counted in the "sockets" column of the MPTCP
or MPTCPv6 row of /proc/net/protocols, but it is uncounted when it is
closed. Each removal of such an endpoint then hides one MPTCP socket of
the same family from this column, for the lifetime of the netns.
mptcp_check_listen_stop() decrements this counter for any MPTCP socket
closed in TCP_LISTEN state, and mptcp_listen() increments it when
listen() succeeds. But mptcp_pm_nl_create_listen_socket() sets its MPTCP
socket in TCP_LISTEN state without incrementing it. This socket is
closed when the endpoint is deleted or flushed, when adding the endpoint
fails after the creation of the listener, e.g. because its ID is already
used, and when the netns is dismantled.
Nothing depends on this counter, it is only displayed. But it is wrong
once such an endpoint has been added: its listener is not counted while
"ss -Ml" lists it, and after its removal, the total is one below the
number of MPTCP sockets of the same family in use, a negative total
being displayed as 0 by sock_prot_inuse_get().
The counter was introduced by commit c558246ee73e ("mptcp: add
statistics for mptcp socket in use"), when only the subflow of this
socket was in TCP_LISTEN state. Commit 57fc0f1ceaa4 ("mptcp: ensure
listener is unhashed before updating the sk status") then set this
socket in TCP_LISTEN state too, without counting it.
The fix used here is to increment the counter when __inet_listen_sk()
succeeds, as mptcp_listen() does. If it fails, the subflow is back in
TCP_CLOSE: move this socket back to this state too, also as
mptcp_listen() does. It was left in TCP_LISTEN, which triggered a
warning when it was released, e.g. after a socket in TCP repair mode
had been bound to the same address and port in between, as reported by
Sashiko:
WARNING: net/mptcp/protocol.c:3542 at mptcp_check_listen_stop.part.0+0x4f/0xb0, CPU#0: ip/2816
Call Trace:
__mptcp_close+0x2bf/0x310
mptcp_close+0x23/0x80
inet_release+0x43/0x80
sock_release+0x24/0x70
mptcp_pm_nl_add_addr_doit+0x266/0x3b0
This issue has been found by an AI code review agent, while reviewing
the code of the commit "mptcp: pm: don't let listeners pin their netns",
and confirmed with a new Packetdrill test, and with a shell script
adding and flushing such an endpoint 3 times in a new netns, then
creating 3 MPTCP listeners. Without this patch:
kernel_listener_inuse.pkt:15: error executing `test $(awk '/^MPTCP/ { n += $3 } END { print n }' /proc/net/protocols) -eq 2` command: non-zero status 1
inuse: endpoint 1 present: 0 (expected 1)
[...]
inuse: 3 user listeners: 0 (expected 3)
Fixes: 57fc0f1ceaa4 ("mptcp: ensure listener is unhashed before updating the sk status")
Reported-by: Kyuwon Cho <kyuwoncho18@gmail.com>
Closes: https://lore.kernel.org/mptcp/179502042942.2742790.17887994424282536144@gmail.com
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: count the listener once listen() succeeded, and restore TCP_CLOSE
otherwise, to avoid a warning (Sashiko, then reported by Kyuwon Cho)
---
net/mptcp/pm_kernel.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c
index 2680d4672d58..73261685ae4c 100644
--- a/net/mptcp/pm_kernel.c
+++ b/net/mptcp/pm_kernel.c
@@ -915,7 +915,14 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
if (!err)
mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED);
release_sock(ssk);
- return err;
+ if (err) {
+ /* the subflow is back in TCP_CLOSE: like in mptcp_listen() */
+ inet_sk_state_store(newsk, TCP_CLOSE);
+ return err;
+ }
+
+ sock_prot_inuse_add(sock_net(newsk), newsk->sk_prot, 1);
+ return 0;
}
static int mptcp_pm_kernel_get_local_id(struct mptcp_sock *msk,
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 24/50] mptcp: count a listener once when listen() is called again
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (22 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 23/50] mptcp: pm: kernel: count endpoint listeners as sockets in use Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment Matthieu Baerts (NGI0)
` (26 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
listen() on a listening MPTCP socket only updates its backlog, as with
TCP. But mptcp_listen() then counts this socket once more in the
"sockets" column of the MPTCP or MPTCPv6 row of /proc/net/protocols, and
sends a new MPTCP_EVENT_LISTENER_CREATED event, while only one decrement
and one MPTCP_EVENT_LISTENER_CLOSED event are done when it is closed.
Each extra listen() call then leaves the counter one above the number of
MPTCP sockets in use, for the lifetime of the netns, and a userspace
path manager can see two listeners created for one closed.
With TCP, the socket is only counted when it is hashed, which is not
done again for a listening socket.
The fix used here is to only count the socket, and send the event, if it
was not already listening.
This issue has been found by an AI code review agent, while reviewing
the code of the commit "mptcp: pm: kernel: count endpoint listeners as
sockets in use", and confirmed with a new Packetdrill test, and with a
script calling listen() twice. Without this patch:
listen_listen.pkt:12: error executing `test $(awk '/^MPTCP/ { n += $3 } END { print n }' /proc/net/protocols) -eq 1` command: non-zero status 1
inuse: relisten: listening: 2 (expected 1)
inuse: relisten: closed: 1 (expected 0)
The extra event comes from the commit below, and the extra count from
commit c558246ee73e ("mptcp: add statistics for mptcp socket in use"),
which is in all the stable versions having the commit below.
Fixes: f8c9dfbd875b ("mptcp: add pm listener events")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: commit message: explain the two Fixes tags
---
net/mptcp/protocol.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b1072123397f..c57bfedc86a8 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4568,6 +4568,7 @@ static int mptcp_listen(struct socket *sock, int backlog)
struct mptcp_sock *msk = mptcp_sk(sock->sk);
struct sock *sk = sock->sk;
struct sock *ssk;
+ bool listening;
int err;
pr_debug("msk=%p\n", msk);
@@ -4584,6 +4585,7 @@ static int mptcp_listen(struct socket *sock, int backlog)
goto unlock;
}
+ listening = sk->sk_state == TCP_LISTEN;
set_bit(MPTCP_RTX_ENABLED, &msk->flags);
mptcp_set_state(sk, TCP_LISTEN);
sock_set_flag(sk, SOCK_RCU_FREE);
@@ -4598,7 +4600,8 @@ static int mptcp_listen(struct socket *sock, int backlog)
release_sock(ssk);
mptcp_set_state(sk, inet_sk_state_load(ssk));
- if (!err) {
+ /* only the backlog changes when listening already */
+ if (!err && !listening) {
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
mptcp_copy_inaddrs(sk, ssk);
mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (23 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 24/50] mptcp: count a listener once when listen() is called again Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
` (25 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After an MP_FAIL with a single subflow, mptcp_sendmsg_frag() puts the
infinite mapping on the next skb with new data, then falls back to TCP.
This skb can be bigger than one MSS: it is sized with the size goal
computed before the fallback, from an MSS reserving the space for the
DSS option.
After the fallback, this space is no longer reserved when the MSS is
computed, but this skb still carries a DSS option, which is copied to
each of its segments: with the new MSS, they are bigger than the MTU.
The new MSS is used for the next transmissions, e.g. when only a part of
the skb can be sent at first, or for a retransmission, and it can also
be used for the first one, when more data is pushed in the same batch.
The IP layer drops such segments, as DF is set, and sends an ICMP
"Fragmentation Needed" to the local host, which doesn't change the PMTU:
the transfer stalls.
This issue was causing the "Infinite map" subtest from mptcp_join.sh to
be flaky, with the client counting these ICMPs as OutOfWindowIcmps, and
its subflow stuck with unsent data:
copyfd_io_poll: poll timed out (events: POLLIN 1, POLLOUT 0)
(...)
TcpExtOutOfWindowIcmps 134
(...)
tcp FIN-WAIT-1 (...) timer:(persist,21sec,7) (...) notsent:98333 (...)
(...)
infi rx server [FAIL] got 0 infinite map[s] RX expected 1
The root cause has been confirmed with a Packetdrill script, a variant
of the new dss_infinite_map_mss_server.pkt test from the MPTCP
Packetdrill tests, with an MP_FAIL received before any data, and a cwnd
of 1: without this fix, the rest of the infinite mapping, after the
first MSS, was never sent:
IpFragFails 2 0.0
(...) timer:(persist,305ms,1) (...) cwnd:2 (...) notsent:1564 (...)
infinite_map_stall-v4.pkt:27: error handling packet: Timed out waiting for packet
To fix this issue, limit the skb carrying the infinite mapping to one
MSS, as computed before the fallback. The segments of this skb can still
be too big if the MSS decreases before it is acked, e.g. after a PMTU
drop, but this is unlikely right after an MP_FAIL, and this connection
would then stall as with a PMTU black hole.
A side effect: when the last unsent skb is bigger than one MSS, the
infinite mapping is now put on a new skb. This unsent skb is then sent
without DSS after the fallback, as it was already the case for the ones
before it, and the peer falls back before receiving the infinite
mapping.
Fixes: 1e39e5a32ad7 ("mptcp: infinite mapping sending")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue causing a flaky selftest
v3: commit msg: why an MSS decrease before the infinite mapping is
acked is not handled (Clashiko)
---
net/mptcp/protocol.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index c57bfedc86a8..39490ff40aa4 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1483,6 +1483,12 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
info->mss_now = tcp_send_mss(ssk, &info->size_goal, info->flags);
copy = info->size_goal;
+ /* After the fallback, the MSS no longer includes the DSS option of the
+ * infinite mapping: send it in a single segment.
+ */
+ if (unlikely(mptcp_subflow_ctx(ssk)->send_infinite_map))
+ copy = info->mss_now;
+
skb = tcp_write_queue_tail(ssk);
if (skb && copy > skb->len) {
/* Limit the write to the size available in the
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (24 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 27/50] mptcp: do not fallback while old data is in flight Matthieu Baerts (NGI0)
` (24 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After an MP_FAIL, the infinite mapping is sent with the next data. If
the MPTCP socket falls back to TCP in the meantime, e.g. after having
received data without DSS, the size of the next skb is computed without
room for the DSS option, as no MPTCP options are sent after a fallback.
But this skb still carries the infinite mapping, with its DSS option:
its segments are then bigger than the MTU, and dropped, while the next
ones wait for them. The connection then stalls.
Keep room for the DSS option while the infinite mapping is still to be
sent, when computing the MSS. This room is only kept until the skb
carrying the infinite mapping is created, not until it is acked: an MSS
decrease in between, e.g. after a PMTU drop, is unlikely right after an
MP_FAIL, and this connection would then stall as with a PMTU black hole.
This issue has been found by Sashiko, while reviewing "mptcp: send the
infinite map in a single segment", and confirmed with a new Packetdrill
test: an MP_FAIL is received before any data, then data without DSS.
Without this patch, the infinite mapping was never sent:
dss_infinite_map_after_fallback_server.pkt:27: error handling packet: Timed out waiting for packet
Fixes: 1e39e5a32ad7 ("mptcp: infinite mapping sending")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue spotted by Sashiko
v3: commit msg: why an MSS decrease before the infinite mapping is
acked is not handled (Clashiko)
---
net/mptcp/options.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 736e55532296..6b1a3994fb49 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -891,9 +891,11 @@ int mptcp_established_options(struct sock *sk, struct sk_buff *skb,
opts->suboptions = 0;
/* Force later mptcp_write_options(), but do not use any actual
- * option space.
+ * option space, except for an infinite mapping still to be sent.
*/
- if (unlikely(__mptcp_check_fallback(msk) && !mptcp_check_infinite_map(skb)))
+ if (unlikely(__mptcp_check_fallback(msk) &&
+ !mptcp_check_infinite_map(skb) &&
+ (skb || !subflow->send_infinite_map)))
return 0;
if (unlikely(skb && TCP_SKB_CB(skb)->tcp_flags & TCPHDR_RST)) {
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 27/50] mptcp: do not fallback while old data is in flight
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (25 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 28/50] mptcp: stop resending data to a peer that fell back Matthieu Baerts (NGI0)
` (23 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
If an established MPTCP connection falls back to TCP while a zero window
probe or reinjected data is queued or in flight, recv() can return data
twice with no error, so the stream is silently corrupted.
After a fallback mptcp_established_options() writes a DSS option only
for an infinite mapping, so an skb that mptcp_sendmsg_frag() queued with
a mapping to data sequence numbers (DSN) is sent without that mapping.
The receiver treats the bytes of the subflow, in sequence order, as the
rest of the stream, so a fallback is only correct if the subflow carries
each byte of the stream once. But allow_infinite_fallback, the flag that
permits a fallback, stays set in two cases in which old data is queued
again on the only subflow.
First, a zero window probe is a copy of the next unsent byte, mapped to
the last acknowledged DSN so that the peer drops it as a duplicate.
Second, when a subflow whose MP_JOIN handshake has failed is closed,
__mptcp_retransmit_pending_data() marks all data that has no DATA_ACK
yet as unsent, although no second subflow has joined. If the sender
falls back while such bytes are queued, they are sent without their
mapping and the receiver delivers them as new data, as here for a probe:
sender receiver
====== ========
queue a probe, a copy of byte N
get data with no DSS, fall back
read, open the window
send the probe with no DSS
no DSS: fall back
deliver byte N
send byte N as data
deliver byte N again /* corrupt */
The fix used here is to refuse the fallback while old data is in flight:
- when mptcp_sendmsg_frag() maps bytes to a DSN below snd_nxt of the
MPTCP socket, set the new bit old_data_pending of the subflow, and
store the TCP sequence number after these bytes in its new member
old_data_end
- clear the bit in mptcp_incoming_options() when a segment with a DSS,
other than an infinite mapping, acknowledges that sequence number
- make mptcp_try_fallback() fail while the bit is set, so that its
callers reset the subflow
- delay the infinite mapping that answers an MP_FAIL, and the fallback
that comes with it, to the first data that is queued with the bit
clear, and send plain mappings until then
- after a fallback, skip data below snd_nxt in mptcp_sendmsg_frag(): a
reinjection that has not reached the subflow yet does not set the bit
This only prevents a fallback of this side: if a middlebox removes the
DSS of these old bytes, the peer can still fall back on its own, and
deliver them as new data, as it cannot tell that they are old. The next
commits limit this case, but cannot prevent it entirely.
A consequence: if the old data reached the peer with its mapping, but
the DSS acknowledging it is still on its way back, or lost its options,
a fallback attempted meanwhile resets the subflow, although it would
have been safe. This window lasts about one round trip, or as long as
the acknowledgments lose their options.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
between two unmodified Linux hosts, nftables removing the MPTCP options,
e.g. while a zero window probe is pending, or after a failed MP_JOIN.
Without this patch, the reader got some data twice, with a regular end
of file: the stream was silently corrupted:
receiver 4.692: READ-TOTAL outcome iii-repeat-or-gap bytes 8388609 of 8388608 missing 0 twice 1 [...] end: eof
[...]
receiver 8.611: READ-TOTAL outcome iii-repeat-or-gap bytes 26000 of 14000 missing 0 twice 12000 [...] end: eof
Note for the backports: this patch depends on commit 119d51e225fe
("mptcp: fallback when MPTCP opts are dropped after 1st data") and
commit f8a1d9b18c5e ("mptcp: make fallback action and fallback decision
atomic"), two fixes which may have already been backported: they allowed
the fallback in the reproduced cases, once data has been acknowledged
without checksums, and after a failed MP_JOIN.
Fixes: 1e39e5a32ad7 ("mptcp: infinite mapping sending")
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comments. Move old_data_end to an existing hole, after
subflow_id. Commit message: mention the reset that can now replace a
safe fallback + how the issue was found, and its symptoms + note for
the backports. Moved before "mptcp: continue the last mapping after a
fallback". Commit message: the peer can still fall back alone. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: commit message: the peer can still fall back alone (Clashiko). Only
clamp to one MSS when sending the infinite mapping (Sashiko)
Note (Sashiko on v1): an infinite mapping can stay pending, but nothing
waits for it: an MP_FAIL is only accepted before any join or MPTCP-level
retransmission, so TCP retransmits the data in flight.
---
net/mptcp/options.c | 6 ++++++
net/mptcp/protocol.c | 20 ++++++++++++++++++--
net/mptcp/protocol.h | 9 ++++++++-
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 6b1a3994fb49..9133e3d6e5d9 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -1333,6 +1333,12 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
return true;
}
+ /* DSS acking the old data, not an infinite map: no peer fallback */
+ if (unlikely(subflow->old_data_pending) &&
+ !(mp_opt.use_map && !mp_opt.data_len) &&
+ !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end))
+ subflow->old_data_pending = 0;
+
/* we can't wait for recvmsg() to update the ack_seq, otherwise
* monodirectional flows will stuck
*/
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 39490ff40aa4..7df5a2863555 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1486,9 +1486,16 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
/* After the fallback, the MSS no longer includes the DSS option of the
* infinite mapping: send it in a single segment.
*/
- if (unlikely(mptcp_subflow_ctx(ssk)->send_infinite_map))
+ if (unlikely(mptcp_subflow_ctx(ssk)->send_infinite_map &&
+ !mptcp_subflow_ctx(ssk)->old_data_pending))
copy = info->mss_now;
+ /* after a fallback, the subflow got all data below snd_nxt already */
+ if (unlikely(__mptcp_check_fallback(msk) &&
+ before64(data_seq, msk->snd_nxt)))
+ return min_t(u64, msk->snd_nxt - data_seq,
+ info->limit - info->sent);
+
skb = tcp_write_queue_tail(ssk);
if (skb && copy > skb->len) {
/* Limit the write to the size available in the
@@ -1569,6 +1576,12 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
TCP_SKB_CB(skb)->end_seq += copy;
tcp_skb_pcount_set(skb, 0);
+ /* old data mapped again: no fallback until acked with a DSS */
+ if (unlikely(before64(data_seq, msk->snd_nxt))) {
+ mptcp_subflow_ctx(ssk)->old_data_end = tcp_sk(ssk)->write_seq;
+ mptcp_subflow_ctx(ssk)->old_data_pending = 1;
+ }
+
/* on skb reuse we just need to update the DSS len */
if (reuse_skb) {
TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH;
@@ -1599,7 +1612,10 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
out:
if (READ_ONCE(msk->csum_enabled))
mptcp_update_data_checksum(skb, copy);
- if (mptcp_subflow_ctx(ssk)->send_infinite_map)
+
+ /* the infinite map implies a fallback: wait for old data acks */
+ if (mptcp_subflow_ctx(ssk)->send_infinite_map &&
+ !mptcp_subflow_ctx(ssk)->old_data_pending)
mptcp_update_infinite_map(msk, ssk, mpext);
trace_mptcp_sendmsg_frag(mpext);
mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 888ee9d66967..6dbd912e08d8 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -605,7 +605,8 @@ struct mptcp_subflow_context {
is_mptfo : 1, /* subflow is doing TFO */
mpc_drop : 1, /* the MPC option has been dropped in a rtx */
resetting : 1, /* subflow is resetting */
- __unused : 9;
+ old_data_pending : 1, /* old_data_end not acked with a DSS */
+ __unused : 8;
bool data_avail;
bool scheduled;
bool pm_listener; /* a listener managed by the kernel PM? */
@@ -633,6 +634,7 @@ struct mptcp_subflow_context {
*/
u32 subflow_id;
+ u32 old_data_end; /* TCP write_seq after the last old data */
unsigned long fail_tout;
@@ -1346,6 +1348,11 @@ static inline bool mptcp_try_fallback(struct sock *ssk, int fb_mib)
struct mptcp_sock *msk;
msk = mptcp_sk(sk);
+
+ /* queued old data would be sent without mapping after a fallback */
+ if (subflow->old_data_pending && !__mptcp_check_fallback(msk))
+ return false;
+
if (!__mptcp_try_fallback(msk, fb_mib))
return false;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 28/50] mptcp: stop resending data to a peer that fell back
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (26 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 27/50] mptcp: do not fallback while old data is in flight Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
` (22 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
recv() on an established MPTCP connection can silently return data that
it has returned before, again and again, if the receiver falls back to
TCP and the sender does not.
While no DATA_ACK arrives, the MPTCP retransmit timer makes
mptcp_sendmsg_frag() queue old data on the subflow again: either
fragments from __mptcp_retrans(), or a zero window probe. That is only
correct while the receiver reads the DSS mapping of these bytes and
drops them as duplicates: a receiver that has fallen back to TCP
delivers them as new data. But mptcp_incoming_options() ignores a bare
ACK, one with no MPTCP option, on a fully established subflow, so a
sender that gets only bare ACKs from that receiver stays in MPTCP mode:
sender receiver
====== ========
send bytes N to M
(a middlebox removes the DSS)
no DSS: fall back
deliver N to M, send a bare ACK
no DATA_ACK, the timer expires
send bytes N to M again
deliver N to M again <-- wrong
send a bare ACK
The fix used here is to:
- reset the subflow, with the reason "middlebox interference", when
mptcp_sendmsg_frag() has more old data to queue and only bare ACKs
have acknowledged the old data queued so far. The test reads
old_data_pending, which the earlier commit "mptcp: do not fallback
while old data is in flight" sets when old data is queued. That commit
clears it when a segment with a DSS, other than an infinite mapping,
acknowledges old_data_end, the TCP sequence number after that data.
The reset is counted in FallbackFailed: the peer has likely fallen
back, but this side cannot
- clear old_data_pending for a segment with any other MPTCP option too,
in mptcp_incoming_options(). An infinite mapping stays the exception
- skip a zero window probe while the TCP retransmit queue of the subflow
holds data: the MPTCP retransmit timer, armed when a push leaves data
behind, tries again later
- drop the segment in mptcp_incoming_options() if the push done when
processing its DATA_ACK resets the subflow: it is not queued on the
closed subflow then, as with a reset done earlier
This limits the repeats, but does not prevent the first one: data that
was new when it was first sent does not set old_data_pending, so its
first MPTCP-level retransmission is still delivered twice by a peer that
has fallen back. After a failed MP_JOIN, more of the reinjected data can
be. The same is true for a zero window probe whose DSS is removed: a
peer falling back on it delivers it as the next byte, then this byte
again, when it is sent as new data.
A consequence: a peer still in MPTCP mode, whose options are removed on
the way back for a while only, recovered once the options came back.
Its subflow is now reset as soon as more old data is due.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
between two unmodified Linux hosts, nftables removing the MPTCP options
in the middle of the transfer, so that only the receiver falls back.
Without this patch, the reader got the same data again and again, here
65 MB more than once in 120 seconds:
receiver 127.514: READ-TOTAL outcome iii-repeat-or-gap bytes 68255744 of 8388608 missing 0 twice 65650688 [...]
[...] took 120.0 s end: limit: still data after 120 s
Fixes: 119d51e225fe ("mptcp: fallback when MPTCP opts are dropped after 1st data")
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comments, also in struct mptcp_subflow_context. No timer
arming when a probe is skipped: "mptcp: arm the rtx timer if a push
leaves data behind" already does it. Commit message: the first repeat
is still delivered, and a peer that loses its options for a while only
is now reset + how the issue was found, and its symptoms. Count the
reset in MPTCP_MIB_FALLBACKFAILED. Drop the segment if the push resets
the subflow, update comments, and commit message: the zero window probe
whose DSS is removed. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: drop the segment if the push resets the subflow, update comments,
and mention the probe case (Sashiko, Clashiko)
---
net/mptcp/mib.h | 2 +-
net/mptcp/options.c | 16 ++++++++++------
net/mptcp/protocol.c | 21 ++++++++++++++++++++-
net/mptcp/protocol.h | 2 +-
4 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/net/mptcp/mib.h b/net/mptcp/mib.h
index 1ebdb55e9534..34a065b9e8dd 100644
--- a/net/mptcp/mib.h
+++ b/net/mptcp/mib.h
@@ -93,7 +93,7 @@ enum linux_mptcp_mib_field {
MPTCP_MIB_DSSFALLBACK, /* Bad or missing DSS */
MPTCP_MIB_DSSRESET, /* MP_RST: bad data mapping */
MPTCP_MIB_SIMULTCONNFALLBACK, /* Simultaneous connect */
- MPTCP_MIB_FALLBACKFAILED, /* Can't fallback due to msk status */
+ MPTCP_MIB_FALLBACKFAILED, /* Can't fallback: msk/subflow status */
MPTCP_MIB_WINPROBE, /* MPTCP-level zero window probe */
MPTCP_MIB_BACKLOGDROP, /* Backlog over memory limit */
MPTCP_MIB_RCVPRUNED, /* Dropped due to memory constraints */
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 9133e3d6e5d9..f9b65d0c6290 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -1287,6 +1287,12 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
return sk->sk_state != TCP_CLOSE;
+ /* MPTCP opt acking the old data, not an infinite map: no fallback */
+ if (unlikely(subflow->old_data_pending) && mp_opt.suboptions &&
+ !(mp_opt.use_map && !mp_opt.data_len) &&
+ !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end))
+ subflow->old_data_pending = 0;
+
if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
READ_ONCE(msk->local_key) == mp_opt.fc_recv_key) {
@@ -1333,12 +1339,6 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
return true;
}
- /* DSS acking the old data, not an infinite map: no peer fallback */
- if (unlikely(subflow->old_data_pending) &&
- !(mp_opt.use_map && !mp_opt.data_len) &&
- !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end))
- subflow->old_data_pending = 0;
-
/* we can't wait for recvmsg() to update the ack_seq, otherwise
* monodirectional flows will stuck
*/
@@ -1359,6 +1359,10 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
return true;
}
+ /* the push from ack_update_msk() can reset the subflow */
+ if (unlikely(sk->sk_state == TCP_CLOSE))
+ return false;
+
mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
if (!mpext)
return false;
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 7df5a2863555..61cc4ae2a7b8 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1455,6 +1455,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
struct mptcp_data_frag *dfrag,
struct mptcp_sendmsg_info *info)
{
+ struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
u64 data_seq = dfrag->data_seq + info->sent;
int offset = dfrag->offset + info->sent;
struct mptcp_sock *msk = mptcp_sk(sk);
@@ -1545,11 +1546,29 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
return 0;
}
+ /* a new probe would move old_data_end: one at a time */
+ if (!tcp_rtx_queue_empty(ssk)) {
+ tcp_remove_empty_skb(ssk);
+ return 0;
+ }
+
zero_window_probe = true;
data_seq = snd_una - 1;
copy = 1;
}
+ /* old data acked without MPTCP opts: the peer may have fallen back */
+ if (unlikely(before64(data_seq, msk->snd_nxt) &&
+ subflow->old_data_pending &&
+ !before(tcp_sk(ssk)->snd_una, subflow->old_data_end))) {
+ tcp_remove_empty_skb(ssk);
+ MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
+ subflow->reset_transient = 0;
+ subflow->reset_reason = MPTCP_RST_EMIDDLEBOX;
+ mptcp_subflow_reset(ssk);
+ return -EAGAIN;
+ }
+
copy = min_t(size_t, copy, info->limit - info->sent);
/* like TCP, allow some progress up to tcp_wmem[0] */
@@ -1576,7 +1595,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
TCP_SKB_CB(skb)->end_seq += copy;
tcp_skb_pcount_set(skb, 0);
- /* old data mapped again: no fallback until acked with a DSS */
+ /* old data mapped again: no fallback until acked with MPTCP opts */
if (unlikely(before64(data_seq, msk->snd_nxt))) {
mptcp_subflow_ctx(ssk)->old_data_end = tcp_sk(ssk)->write_seq;
mptcp_subflow_ctx(ssk)->old_data_pending = 1;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 6dbd912e08d8..dfeabe03180b 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -605,7 +605,7 @@ struct mptcp_subflow_context {
is_mptfo : 1, /* subflow is doing TFO */
mpc_drop : 1, /* the MPC option has been dropped in a rtx */
resetting : 1, /* subflow is resetting */
- old_data_pending : 1, /* old_data_end not acked with a DSS */
+ old_data_pending : 1, /* old data not acked with MPTCP opts */
__unused : 8;
bool data_avail;
bool scheduled;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (27 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 28/50] mptcp: stop resending data to a peer that fell back Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 22:36 ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 30/50] mptcp: pm: kernel: don't count signal+subflow ID 0 endp Matthieu Baerts (NGI0)
` (21 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The previous commit resets the subflow, instead of resending data that
has been acked without MPTCP options, but only if this data had already
been resent. Data acked without these options the first time was still
resent once: a peer that had fallen back to TCP alone, e.g. because a
middlebox removed the DSS of new data after a zero window probe,
delivered it a second time to the application, without error.
Track the TCP sequence number acked with MPTCP options, to also catch
data acked without them the first time. Only before any MP_JOIN subflow
has been established: after that, the peer can no longer fall back to
TCP, and the Data ACK can be omitted when its value does not advance,
see RFC 8684, sections 3.7 and 3.3.2. On a single subflow, a peer
omitting the Data ACK like this can then see its subflow reset if this
Data ACK is lost, as before at the next resend, or if it drops data
after having acked it at the TCP level.
This issue has been reported by Clashiko, and reproduced with a new
Packetdrill test: data acked without MPTCP options was resent at the
MPTCP level, instead of a reset:
dss_resend_after_bare_ack_reset_server.pkt:28: error handling packet: live packet payload: expected 0 bytes vs actual 1000 bytes
Two other new tests check that this data is still resent after a join,
but not after a join rejected by the peer.
Fixes: 119d51e225fe ("mptcp: fallback when MPTCP opts are dropped after 1st data")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue spotted by Clashiko
---
net/mptcp/options.c | 19 ++++++++++++++-----
net/mptcp/protocol.c | 11 ++++++++---
net/mptcp/protocol.h | 2 ++
net/mptcp/subflow.c | 2 ++
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index f9b65d0c6290..05b9c66aaed6 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -1055,6 +1055,10 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
WARN_ONCE(1, "bogus mpc option on established client sk");
set_fully_established:
+ /* the peer can no longer fall back to TCP */
+ if (subflow->request_join)
+ set_bit(MPTCP_JOINED, &msk->flags);
+
if (mp_opt->deny_join_id0)
WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
@@ -1287,11 +1291,16 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
return sk->sk_state != TCP_CLOSE;
- /* MPTCP opt acking the old data, not an infinite map: no fallback */
- if (unlikely(subflow->old_data_pending) && mp_opt.suboptions &&
- !(mp_opt.use_map && !mp_opt.data_len) &&
- !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end))
- subflow->old_data_pending = 0;
+ /* MPTCP opts, not an infinite map: the peer did not fall back */
+ if (mp_opt.suboptions && !(mp_opt.use_map && !mp_opt.data_len)) {
+ u32 ack_seq = TCP_SKB_CB(skb)->ack_seq;
+
+ if (after(ack_seq, subflow->opt_ack_seq))
+ subflow->opt_ack_seq = ack_seq;
+ if (unlikely(subflow->old_data_pending) &&
+ !before(ack_seq, subflow->old_data_end))
+ subflow->old_data_pending = 0;
+ }
if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 61cc4ae2a7b8..f3dd15293bc8 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1090,6 +1090,9 @@ static void mptcp_subflow_joined(struct mptcp_sock *msk, struct sock *ssk)
{
mptcp_subflow_ctx(ssk)->map_seq = READ_ONCE(msk->ack_seq);
msk->allow_infinite_fallback = false;
+ /* an active join is added once fully established, see options.c */
+ if (!mptcp_subflow_ctx(ssk)->request_join)
+ set_bit(MPTCP_JOINED, &msk->flags);
mptcp_event(MPTCP_EVENT_SUB_ESTABLISHED, msk, ssk, GFP_ATOMIC);
}
@@ -1557,10 +1560,12 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
copy = 1;
}
- /* old data acked without MPTCP opts: the peer may have fallen back */
+ /* data acked without MPTCP opts: the peer may have fallen back, only
+ * possible before a join, see RFC 8684
+ */
if (unlikely(before64(data_seq, msk->snd_nxt) &&
- subflow->old_data_pending &&
- !before(tcp_sk(ssk)->snd_una, subflow->old_data_end))) {
+ !test_bit(MPTCP_JOINED, &msk->flags) &&
+ after(tcp_sk(ssk)->snd_una, subflow->opt_ack_seq))) {
tcp_remove_empty_skb(ssk);
MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
subflow->reset_transient = 0;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index dfeabe03180b..d0ae782c9ade 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -118,6 +118,7 @@
#define MPTCP_WORK_CLOSE_SUBFLOW 3
#define MPTCP_RTX_ENABLED 4
#define MPTCP_ORPHAN_COUNTED 5
+#define MPTCP_JOINED 6
/* MPTCP socket release cb flags */
#define MPTCP_PUSH_PENDING 1
@@ -648,6 +649,7 @@ struct mptcp_subflow_context {
int cached_sndbuf; /* sndbuf size when last synced with the msk sndbuf,
* protected by the msk socket lock
*/
+ u32 opt_ack_seq; /* highest TCP ack_seq with MPTCP opts */
struct sock *tcp_sock; /* tcp sk backpointer */
struct sock *conn; /* parent mptcp_sock */
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index a216d88d35ee..3590c1207e88 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -587,6 +587,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
msk = mptcp_sk(parent);
subflow->rel_write_seq = 1;
+ subflow->opt_ack_seq = tcp_sk(sk)->snd_una;
subflow->conn_finished = 1;
subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
pr_debug("subflow=%p synack seq=%x\n", subflow, subflow->ssn_offset);
@@ -2161,6 +2162,7 @@ static void subflow_ulp_clone(const struct request_sock *req,
new_ctx->tcp_state_change = old_ctx->tcp_state_change;
new_ctx->tcp_error_report = old_ctx->tcp_error_report;
new_ctx->rel_write_seq = 1;
+ new_ctx->opt_ack_seq = tcp_rsk(req)->snt_isn + 1;
if (subflow_req->mp_capable) {
/* see comments in subflow_syn_recv_sock(), MPTCP connection
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 30/50] mptcp: pm: kernel: don't count signal+subflow ID 0 endp
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (28 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 31/50] selftests: mptcp: join: check re-adding " Matthieu Baerts (NGI0)
` (20 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Josef Bacik
From: Josef Bacik <josef@toxicpanda.com>
local_addr_used must not be incremented for the endpoint of the initial
subflow, because __mark_subflow_endp_available() does not decrement it
for ID 0. mptcp_pm_create_subflow_or_signal_addr() tells that endpoint
by local.addr.id == msk->mpc_endpoint_id, in the loop that creates the
subflows and after it.
For an endpoint with both the signal and the subflow flag that
comparison comes too late: the part that announces the address has
replaced local.addr.id by 0 already. So the counter goes up each time
such an endpoint is removed and added again while a connection that
started from its address is alive, and never comes down. When it has
reached the number of subflow endpoints, the connection does not use any
new endpoint: after four rounds local_addr_used was 5 instead of 1, and
an endpoint added then got no subflow.
ID 0 can't be the ID of any other endpoint: look at that, after the
replacement.
This issue has been found with the help of an LLM. It has been
reproduced with the modified "delete and re-add" subtest of
mptcp_join.sh, from the next commit: without this patch, the subflow of
the ID 0 endpoint was not created again at the third round,
local_addr_used being above local_addr_max:
# 002 delete and re-add
[...]
# after re-add id 0 (3) [FAIL] got 2:2 subflows expected 3
[...]
[...] subflows:2 [...] local_addr_used:4 local_addr_max:3 [...]
The check after the loop comes from commit 579a752464a6 ("mptcp: pm:
in-kernel: always mark signal+subflow endp as used"), which is in all
the stable versions having the commit below.
Fixes: 9366922adc6a ("mptcp: pm: fix ID 0 endp usage after multiple re-creations")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
[ Keep the original one-line comment. Commit message: 'behind it' ->
'after it' + how the issue was found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/pm_kernel.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c
index 73261685ae4c..47c6ccb0a29e 100644
--- a/net/mptcp/pm_kernel.c
+++ b/net/mptcp/pm_kernel.c
@@ -411,7 +411,9 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
/* Special case for ID0: set the correct ID */
if (local.addr.id == msk->mpc_endpoint_id)
local.addr.id = 0;
- else /* local_addr_used is not decr for ID 0 */
+
+ /* local_addr_used is not decr for ID 0 */
+ if (local.addr.id)
msk->pm.local_addr_used++;
nr = fill_remote_addresses_vec(msk, &local.addr, fullmesh,
@@ -432,7 +434,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
* case. This avoids issues later when removing the endpoint and calling
* __mark_subflow_endp_available(), which expects the increment here.
*/
- if (signal_and_subflow && local.addr.id != msk->mpc_endpoint_id)
+ if (signal_and_subflow && local.addr.id)
msk->pm.local_addr_used++;
mptcp_pm_nl_check_work_pending(msk);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 31/50] selftests: mptcp: join: check re-adding signal+subflow ID 0 endp
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (29 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 30/50] mptcp: pm: kernel: don't count signal+subflow ID 0 endp Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 32/50] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
` (19 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
This test extends "delete and re-add" to validate the previous commit:
when the endpoint linked to the initial subflow (ID 0) had both the
signal and subflow flags, it was counted as used each time it was
re-added, while this counter is not decremented for this special
endpoint. Once the counter reached the number of subflow endpoints, no
more subflows were created.
From the second round, this endpoint is now re-added with the signal
flag too: without the previous commit, the subflow is not re-created at
the third round.
The ADD_ADDR sent at these two rounds are dropped, and not
retransmitted: if the server received them before the new subflow, it
would try to connect back to the address and port of the client, and
fail, which would change the counters. If they cannot be dropped, e.g.
with an older version of nft, the signal flag is not added, and the
subtest is marked as skipped.
The 'Fixes' tag here below is the same as the one from the previous
commit: this patch here is not fixing anything wrong in the selftests,
but it validates the previous fix for an issue introduced by this commit
ID.
Fixes: 9366922adc6a ("mptcp: pm: fix ID 0 endp usage after multiple re-creations")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: skip the signal part if the nft rule cannot be added (Clashiko)
---
tools/testing/selftests/net/mptcp/mptcp_join.sh | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index c3ccce96b45b..4c045532f137 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -4387,17 +4387,26 @@ endpoint_tests()
ip netns exec "${ns2}" nft insert rule ip filter OUTPUT \
ip saddr 10.0.1.2 meta l4proto tcp \
"${RM_ADDR_OFFSETS}" drop || nft=0
- local i
+ # No ADD_ADDR to ns1: it could try to connect back to ns2's port
+ local i flags="subflow" signal="signal,subflow"
+ ip netns exec "${ns2}" sysctl -q net.mptcp.add_addr_timeout=0
+ if ! ip netns exec "${ns2}" nft insert rule ip filter OUTPUT \
+ meta l4proto tcp \
+ tcp option mptcp subtype add-addr drop; then
+ mark_as_skipped "unable to set the 'add addr' rule"
+ signal="subflow"
+ fi
for i in $(seq 3); do
pm_nl_del_endpoint $ns2 1 10.0.1.2
sleep 0.5
chk_subflow_nr "after delete id 0 ($i)" 2
chk_mptcp_info subflows 2 subflows 2 # only decr for additional sf
- pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags subflow
+ pm_nl_add_endpoint $ns2 10.0.1.2 id 1 dev ns2eth1 flags "${flags}"
wait_mpj $((3 + i))
chk_subflow_nr "after re-add id 0 ($i)" 3
chk_mptcp_info subflows 3 subflows 3
+ flags="${signal}" # ID 0 not counted as used either
done
[ "${nft}" = 1 ] && ip netns exec "${ns2}" nft flush chain ip filter OUTPUT
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 32/50] mptcp: reclaim forward memory after coalescing skbs
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (30 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 31/50] selftests: mptcp: join: check re-adding " Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
` (18 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
If MPTCP sockets receive many small segments whose data stays queued,
TCP can stall on the whole host, and an MPTCP server can be OOM killed
in its memory cgroup, although almost no memory is in use.
When the MPTCP socket (msk) takes over an skb from a subflow,
mptcp_borrow_fwdmem() adds skb->truesize to the sk_forward_alloc of the
msk, and the subflow reserves new memory for the next skb. Both
sk_forward_alloc and sk_rmem_alloc count against tcp_mem and the memory
cgroup, but only sk_rmem_alloc has a limit, sk_rcvbuf, so what queueing
the skb does not move to sk_rmem_alloc has to be released. But
mptcp_try_coalesce() moves only the increase in truesize of the skb that
receives the data, and skb_condense() in mptcp_data_queue_ofo() can
lower skb->truesize, so the rest piles up in sk_forward_alloc.
The fix used here is to return every whole page of sk_forward_alloc with
sk_mem_reclaim(), in mptcp_try_coalesce() once the merged skb is freed,
and in mptcp_data_queue_ofo() once the skb is queued.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
a remote peer sends 33000 segments of one byte after a hole in the data
sequence, which are merged in the out-of-order queue. Without this
patch, the memory forward-allocated by the MPTCP socket -- msk_f -- grew
with each merged segment, above 29 MB, versus 3200 bytes with it:
SNAP label=stage1-1-connections tcp_mem_pages=7168 [...] msk_f=29445248 [...]
[...] OFOQueue=33000 OFOMerge=32862 [...]
With more connections, the original version of this patch reported that
the TCP memory went above tcp_mem[2], stalling the other TCP
connections, or that the memory cgroup went above its limit.
Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow")
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment. Commit message: the rest of the borrowed amount has
to be released + how the issue was found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Note (Clashiko on v2): with an owned skb, the new reclaim is a no-op,
sock_rfree() having already reclaimed: the comment is for the borrowed
skbs, the ones needing it.
---
net/mptcp/protocol.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index f3dd15293bc8..f8cb585da0b3 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -197,6 +197,9 @@ static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
sk_mem_charge(sk, delta);
kfree_skb_partial(from, fragstolen);
+ /* release what is left of the borrowed 'from' truesize */
+ sk_mem_reclaim(sk);
+
return true;
}
@@ -422,6 +425,9 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
end:
skb_condense(skb);
skb_set_owner_r(skb, sk);
+
+ /* skb_condense() can shrink the truesize borrowed from the subflow */
+ sk_mem_reclaim(sk);
}
static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept()
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (31 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 32/50] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 2:20 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
` (17 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
accept() of an MPTCP connection that has already received data can leak
one page of memory cgroup charge, and the leaked charges can get the
server OOM killed.
At accept(), __inet_accept() charges the MPTCP socket (msk) for the
memory that it holds, rounded up to whole pages, and
mptcp_graft_subflows() does the same for each subflow. A page is
uncharged only once, when the socket that holds it releases it, so
rounding up each socket on its own is only correct while each page
belongs to one socket. But for each skb that the msk takes over from a
subflow, it borrows skb->truesize bytes from the pages that the subflow
reserved, so the two can share a page:
reserved by the subflow 4096 bytes 1 page
now held by the msk 896 bytes charged for 1 page
still held by the subflow 3200 bytes charged for 1 page
The fix used here is to keep a running sum of what the msk and its
subflows hold, and to let the new mptcp_charge_subflow() charge each
subflow only for the pages that it adds to the rounded-up sum.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
an MPTCP server in a memory cgroup, the first byte of the client
arriving before accept(). Without this patch, 4096 bytes stayed charged
to the memory cgroup for each connection, after its end:
SNAP label=after-1000 rounds=1000 sockets_left_in_srv=0 [...] c_sock=4096000 [...]
SNAP label=after-5000 rounds=5000 sockets_left_in_srv=0 [...] c_sock=20480000 [...]
With a memory limit, the original version of this patch reported that
the server was killed by the OOM killer after about 14,400 connections.
Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow")
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Note (Clashiko on v2): the backlog can still be charged twice here: this
is fixed by the next patch.
---
net/mptcp/protocol.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index f8cb585da0b3..504fe4a9954f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4664,10 +4664,26 @@ static int mptcp_listen(struct socket *sock, int backlog)
return err;
}
+/* The msk and its subflows share pages: charge their rounded-up sum */
+static int mptcp_charge_subflow(struct sock *sk, struct sock *ssk, int mem)
+{
+ int new_mem = mem + ssk->sk_forward_alloc +
+ atomic_read(&ssk->sk_rmem_alloc);
+ int amt = sk_mem_pages(new_mem) - sk_mem_pages(mem);
+ gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
+
+ mem_cgroup_sk_inherit(sk, ssk);
+ if (amt > 0)
+ mem_cgroup_sk_charge(ssk, amt, gfp);
+ kmem_cache_charge(ssk, gfp);
+ return new_mem;
+}
+
static void mptcp_graft_subflows(struct sock *sk)
{
struct mptcp_subflow_context *subflow;
struct mptcp_sock *msk = mptcp_sk(sk);
+ int mem;
if (mem_cgroup_sockets_enabled) {
LIST_HEAD(join_list);
@@ -4685,6 +4701,9 @@ static void mptcp_graft_subflows(struct sock *sk)
__mptcp_flush_join_list(sk, &join_list);
}
+ /* What __inet_accept() just charged for the msk, before rounding up. */
+ mem = sk->sk_forward_alloc + atomic_read(&sk->sk_rmem_alloc);
+
mptcp_for_each_subflow(msk, subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
@@ -4700,7 +4719,7 @@ static void mptcp_graft_subflows(struct sock *sk)
goto unlock;
__mptcp_inherit_cgrp_data(sk, ssk);
- __mptcp_inherit_memcg(sk, ssk, GFP_KERNEL);
+ mem = mptcp_charge_subflow(sk, ssk, mem);
unlock:
release_sock(ssk);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog twice at accept()
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (32 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-26 2:43 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 35/50] mptcp: don't charge a subflow twice when it joins during accept() Matthieu Baerts (NGI0)
` (16 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
accept() can permanently overcharge the memory cgroup of an MPTCP
server, so the server can be OOM killed, if the new connection received
data while its MPTCP socket was locked.
The sockets of an MPTCP connection have no memory cgroup before
accept(), which then charges the sk_forward_alloc and the sk_rmem_alloc
of the MPTCP socket (msk) and of each subflow. mptcp_graft_subflows()
also charges msk->backlog_unaccounted: the truesize of the skbs that
__mptcp_add_backlog() queued while the socket lock of the msk was held
and their subflow had no memory cgroup. But the first charge already
covers each of these skbs that has not been freed, in the sk_rmem_alloc
of its subflow or of the msk, so no later uncharge matches the extra
charge.
The fix used here is to remove msk->backlog_unaccounted, its charge in
mptcp_graft_subflows() and the warning that tests it in
mptcp_can_spool_backlog(). An RFC patch [1] removes the same lines, as
part of another approach.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch,
on a kernel with the previous patch: 100,000 connections to an MPTCP
server in a memory cgroup. Without this patch, about 63 MB stayed
charged to this memory cgroup once all the connections were closed, and
to its parent after its removal:
SNAP label=after-100000 rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 [...] c_sock=63295488 [...]
[...]
SNAP label=c-removed rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 c=removed [...] p_sock=63295488 [...]
And about 12 MB with only 50 connections, each getting 20,000 duplicates
of a byte before accept(), beside bare ACKs with RM_ADDR, which make the
MPTCP worker take the socket lock:
SNAP label=after-50 rounds=50 sockets_left_in_srv=0 tcp_mem_pages=256 [...] c_sock=12881920 [...]
Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
Link: https://lore.kernel.org/all/20260924080219.1036588-4-caixinchen1@huawei.com/ [1]
Signed-off-by: Chris Mason <mason@kernel.org>
[ No comment change: the commit message explains why the backlog is
covered. Commit message: refer to the RFC [1] removing the same lines
+ how the issue was found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/protocol.c | 35 +----------------------------------
net/mptcp/protocol.h | 1 -
2 files changed, 1 insertion(+), 35 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 504fe4a9954f..c9ef23276399 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -802,12 +802,6 @@ static void __mptcp_add_backlog(struct sock *sk,
account:
WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
-
- /* Possibly not accept()ed yet, keep track of memory not CG
- * accounted, mptcp_graft_subflows() will handle it.
- */
- if (!mem_cgroup_from_sk(ssk))
- msk->backlog_unaccounted += delta;
}
static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
@@ -2456,12 +2450,6 @@ static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
{
struct mptcp_sock *msk = mptcp_sk(sk);
- /* After CG initialization, subflows should never add skb before
- * gaining the CG themself.
- */
- DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket &&
- mem_cgroup_from_sk(sk));
-
if (list_empty(&msk->backlog_list))
return false;
@@ -4691,8 +4679,7 @@ static void mptcp_graft_subflows(struct sock *sk)
/* Subflows joining after __inet_accept() will get the
* mem CG properly initialized at mptcp_finish_join() time,
* but subflows pending in join_list need explicit
- * initialization before flushing `backlog_unaccounted`
- * or MPTCP can later unexpectedly observe unaccounted memory.
+ * initialization by the loop below.
*/
mptcp_data_lock(sk);
list_splice_init(&msk->join_list, &join_list);
@@ -4724,26 +4711,6 @@ static void mptcp_graft_subflows(struct sock *sk)
unlock:
release_sock(ssk);
}
-
- if (mem_cgroup_sk_enabled(sk)) {
- gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
- int amt;
-
- /* Account the backlog memory; prior accept() is aware of
- * fwd and rmem only.
- */
- mptcp_data_lock(sk);
- amt = sk_mem_pages(sk->sk_forward_alloc +
- msk->backlog_unaccounted +
- atomic_read(&sk->sk_rmem_alloc)) -
- sk_mem_pages(sk->sk_forward_alloc +
- atomic_read(&sk->sk_rmem_alloc));
- msk->backlog_unaccounted = 0;
- mptcp_data_unlock(sk);
-
- if (amt)
- mem_cgroup_sk_charge(sk, amt, gfp);
- }
}
static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index d0ae782c9ade..9a9dbab672af 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -394,7 +394,6 @@ struct mptcp_sock {
struct list_head backlog_list; /* protected by the data lock */
u32 backlog_len;
- u32 backlog_unaccounted;
};
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 35/50] mptcp: don't charge a subflow twice when it joins during accept()
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (33 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback Matthieu Baerts (NGI0)
` (15 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
A subflow that joins an MPTCP connection while accept() runs can be
charged twice to the memory cgroup of the server, for the memory that
it already holds when accept() charges it. Nothing removes this extra
charge.
At accept(), __inet_accept() gives the MPTCP socket (msk) the memory
cgroup of the caller, then sets its sk_socket. From then on,
mptcp_finish_join() gives this memory cgroup to a joining subflow, via
mptcp_sock_check_graft(), and each page that the subflow reserves is
charged. Because accept() owns the msk, such a subflow is added to the
join list, which mptcp_graft_subflows() moves to the subflow list
before charging each subflow for the memory that it holds. A subflow
that joined in between is then charged a second time for this memory,
which will be uncharged only once.
The window is short: from the end of __inet_accept() to the start of
mptcp_graft_subflows(). And the extra charge is not zero only if data
was received on the new subflow before mptcp_graft_subflows() gets to
it, while a peer must not send data on it before the fourth ACK
(RFC 8684, section 3.2).
The fix used here is to skip, in mptcp_graft_subflows(), the subflows
that already have a memory cgroup: they got it when they joined, and
their memory has been charged since then.
This issue has been found by an AI code review agent, while reviewing
the code of the commit "mptcp: don't charge a shared page twice at
accept()". It cannot be triggered on demand: the window is too narrow.
It has been reproduced with a 500 ms sleep added after __inet_accept(),
to widen it, and a Packetdrill script sending 1000 bytes on a subflow
joining during accept(). Without this patch, a page stayed charged to
the memory cgroup once all the sockets were freed, and none with it:
memcg sock: 4096 bytes
Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: update a comment (Clashiko)
---
net/mptcp/protocol.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index c9ef23276399..8017f8775728 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4678,8 +4678,8 @@ static void mptcp_graft_subflows(struct sock *sk)
/* Subflows joining after __inet_accept() will get the
* mem CG properly initialized at mptcp_finish_join() time,
- * but subflows pending in join_list need explicit
- * initialization by the loop below.
+ * even if pending in join_list. The ones that joined before
+ * need explicit initialization by the loop below.
*/
mptcp_data_lock(sk);
list_splice_init(&msk->join_list, &join_list);
@@ -4702,7 +4702,8 @@ static void mptcp_graft_subflows(struct sock *sk)
if (!ssk->sk_socket)
mptcp_sock_graft(ssk, sk->sk_socket);
- if (!mem_cgroup_sk_enabled(sk))
+ /* Got the memcg when joining: its memory is already charged */
+ if (!mem_cgroup_sk_enabled(sk) || mem_cgroup_from_sk(ssk))
goto unlock;
__mptcp_inherit_cgrp_data(sk, ssk);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (34 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 35/50] mptcp: don't charge a subflow twice when it joins during accept() Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
` (14 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0), Chris Mason
From: Chris Mason <mason@kernel.org>
An established MPTCP connection that falls back to TCP after a zero
window probe or a reinjection can stall in one direction, so that recv()
returns neither the remaining data nor end of file.
After a fallback, subflow_check_data_avail() gives each skb a dummy
mapping, at the data sequence number (DSN) iasn + SSN - 1, where iasn is
the DSN of the peer's first byte and SSN is the subflow sequence number.
This is right only as long as DSNs and SSNs advance together, but a zero
window probe or a reinjection maps old data a second time, which takes
new SSNs and no new DSN. Each later dummy mapping is then too high, so
__mptcp_move_skb() treats all further data as out of order:
data SSN 1 to 1000 DSN iasn to iasn + 999
probe SSN 1001 DSN iasn + 999, dropped
ack_seq iasn + 1000, the next DSN expected
dummy SSN 1002 DSN iasn + 1001
The fix used here is to:
- keep in the new member dsn_base of the subflow context the first DSN
of the peer's last mapping, minus its first SSN, plus 1
- compute the DSN of a dummy mapping as dsn_base + SSN - 1
- keep in the new member dsn_end the highest end of a mapping of the
peer so far
- make mptcp_try_fallback() fail while the peer's last mapping ends
below dsn_end, so that the caller resets the subflow
32 bits are enough for both: the dummy mapping only takes the lower 32
bits of its DSN, see __mptcp_expand_seq(), and the end of a mapping
stays within a window of dsn_end.
One case is left: if only the receiver falls back after a zero window
probe or a reinjection, it now delivers data resent at the MPTCP level
as new data, unless the sender resets the subflow before, as it does
since "mptcp: don't resend data acked without MPTCP opts". Without this
patch, the receiver stalled instead.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch,
and with a new Packetdrill test: between two unmodified Linux hosts,
nftables removing the MPTCP options after a zero window probe, a DSS
checksum failure, or a failed MP_JOIN. Without this patch, the reader
stalled for good, the data staying in the out-of-order queue:
receiver 22.764: READ-TOTAL outcome ii-right-so-far-then-nothing bytes 2670592 of 8388608 [...]
[...] end: hang: no data and no end of file for 20 s
RESULT [...] R: DssFallback=1 [...] OFOQueue=204 NoDSSInWindow=145 [...]
And with the Packetdrill test:
dss_fallback_after_probe_server.pkt:25: runtime error in read call: Expected result 2000 but got 1000 with errno 22 (Invalid argument)
Fixes: 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation")
Signed-off-by: Chris Mason <mason@kernel.org>
[ dsn_base and dsn_end on 32 bits: struct mptcp_subflow_context grows by
8 bytes instead of 16, and lent_mem_frag stays in the same cacheline.
Shorter comments. Moved after "mptcp: stop resending data to a peer
that fell back": alone, this patch turns a stall into data delivered
twice, when only the receiver falls back after a probe or a
reinjection. Commit message: mention the remaining case + how the
issue was found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: msg: the sender now resets in the remaining case (Clashiko)
Note (Sashiko): the remaining case, when only the receiver falls back,
needs a sender not resetting the subflow, e.g. with an older kernel: the
data is then delivered twice, instead of a stall before this patch. The
RFC at the end of this series resets instead of falling back.
Note (Clashiko on v2): a reinjection of old data with a bad checksum is
reset one RTT later, after the MP_FAIL: theoretical, it needs DSS
checksums, a reinjection and a corruption.
---
net/mptcp/protocol.h | 9 ++++++++-
net/mptcp/subflow.c | 21 ++++++++++++++++++---
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 9a9dbab672af..7cdd0a7e8296 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -582,6 +582,8 @@ struct mptcp_subflow_context {
__wsum map_data_csum;
u32 map_csum_len;
u32 prev_rtt_seq;
+ u32 dsn_base; /* MPC: DSN - SSN + 1 of peer's last map */
+ u32 dsn_end; /* MPC: highest end of the peer's maps */
u32 request_mptcp : 1, /* send MP_CAPABLE */
request_join : 1, /* send MP_JOIN */
request_bkup : 1,
@@ -606,7 +608,8 @@ struct mptcp_subflow_context {
mpc_drop : 1, /* the MPC option has been dropped in a rtx */
resetting : 1, /* subflow is resetting */
old_data_pending : 1, /* old data not acked with MPTCP opts */
- __unused : 8;
+ map_old : 1, /* MPC: peer's last map is below dsn_end */
+ __unused : 7;
bool data_avail;
bool scheduled;
bool pm_listener; /* a listener managed by the kernel PM? */
@@ -1350,6 +1353,10 @@ static inline bool mptcp_try_fallback(struct sock *ssk, int fb_mib)
msk = mptcp_sk(sk);
+ /* the peer might still be resending old data */
+ if (subflow->map_old && !__mptcp_check_fallback(msk))
+ return false;
+
/* queued old data would be sent without mapping after a fallback */
if (subflow->old_data_pending && !__mptcp_check_fallback(msk))
return false;
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 3590c1207e88..f73e4b8deca4 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -540,6 +540,8 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,
/* for fallback's sake */
subflow->map_seq = subflow->iasn;
+ subflow->dsn_base = subflow->iasn;
+ subflow->dsn_end = subflow->iasn;
WRITE_ONCE(msk->remote_key, subflow->remote_key);
WRITE_ONCE(msk->ack_seq, subflow->iasn);
@@ -1438,6 +1440,17 @@ static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk)
return true;
}
+/* Fallback: dummy maps go on from the last valid one, unless it is old */
+static void subflow_update_dsn_base(struct mptcp_subflow_context *subflow)
+{
+ u32 end = subflow->map_seq + subflow->map_data_len;
+
+ subflow->dsn_base = subflow->map_seq - subflow->map_subflow_seq + 1;
+ subflow->map_old = before(end, subflow->dsn_end);
+ if (!subflow->map_old)
+ subflow->dsn_end = end;
+}
+
static bool subflow_check_data_avail(struct sock *ssk)
{
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
@@ -1471,6 +1484,8 @@ static bool subflow_check_data_avail(struct sock *ssk)
if (unlikely(!READ_ONCE(msk->can_ack)))
goto fallback;
+ subflow_update_dsn_base(subflow);
+
old_ack = READ_ONCE(msk->ack_seq);
ack_seq = mptcp_subflow_get_mapped_dsn(subflow);
pr_debug("msk ack_seq=%llx subflow ack_seq=%llx\n", old_ack,
@@ -1501,6 +1516,7 @@ static bool subflow_check_data_avail(struct sock *ssk)
subflow->reset_reason = MPTCP_RST_EMIDDLEBOX;
goto reset;
}
+ subflow_update_dsn_base(subflow);
WRITE_ONCE(subflow->data_avail, true);
return true;
}
@@ -1532,9 +1548,8 @@ static bool subflow_check_data_avail(struct sock *ssk)
subflow->map_data_len = skb->len;
subflow->map_subflow_seq = TCP_SKB_CB(skb)->seq - subflow->ssn_offset;
subflow->map_seq = __mptcp_expand_seq(subflow->map_seq,
- subflow->iasn +
- TCP_SKB_CB(skb)->seq -
- subflow->ssn_offset - 1);
+ subflow->dsn_base +
+ subflow->map_subflow_seq - 1);
WRITE_ONCE(subflow->data_avail, true);
return true;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (35 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 22:45 ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 38/50] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
` (13 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
A simultaneous connect leads to a fallback to TCP, decided when sending
the SYN-ACK from the SYN_RECV state. The received data is then mapped
with dummy mappings, based on ssn_offset, the peer's ISN, normally set
by subflow_finish_connect() when receiving the SYN-ACK. But here, it is
only called on the next packet, received in ESTABLISHED: its sequence
number was then used as ssn_offset, and the first received byte was
dropped.
Set ssn_offset when sending the SYN-ACK after a simultaneous connect,
and only take it from a SYN in subflow_finish_connect().
This issue has been reported by Sashiko, while reviewing another fix,
and confirmed with a new Packetdrill test: after a simultaneous connect,
10 bytes are received. Without this patch, only 9 were read:
simult_connect_data.pkt:24: runtime error in read call: Expected result 10 but got 9 with errno 115 (Operation now in progress)
Fixes: 2834f8edd74d ("mptcp: cleanup fallback dummy mapping generation")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue spotted by Sashiko
Note (Clashiko on v2): ssn_offset is not set if the crossed SYN-ACK
cannot be built: theoretical, it needs a simultaneous connect and an
allocation failure.
---
net/mptcp/options.c | 5 +++++
net/mptcp/subflow.c | 4 +++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 05b9c66aaed6..41eb39968a9a 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -474,6 +474,11 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
* in mptcp_established_options_mp()
*/
subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
+
+ /* simult connect: the peer's SYN-ACK will not set ssn_offset */
+ if (unlikely(sk->sk_state == TCP_SYN_RECV))
+ subflow->ssn_offset = tcp_sk(sk)->rcv_nxt - 1;
+
if (subflow->request_mptcp) {
if (unlikely(subflow_simultaneous_connect(sk))) {
WARN_ON_ONCE(!mptcp_try_fallback(sk, MPTCP_MIB_SIMULTCONNFALLBACK));
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index f73e4b8deca4..439a11d92281 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -591,7 +591,9 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
subflow->rel_write_seq = 1;
subflow->opt_ack_seq = tcp_sk(sk)->snd_una;
subflow->conn_finished = 1;
- subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
+ /* simult connect: not a SYN-ACK, see mptcp_syn_options() */
+ if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)
+ subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
pr_debug("subflow=%p synack seq=%x\n", subflow, subflow->ssn_offset);
mptcp_get_options(skb, &mp_opt);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 38/50] mptcp: move to ESTABLISHED after a simult connect
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (36 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 39/50] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
` (12 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
After a simultaneous connect, the subflow moves from SYN_RECV to
ESTABLISHED when it receives the peer's SYN-ACK. Since the commit
mentioned below, the MPTCP socket only follows when
subflow_finish_connect() is called, on the next received packet. Until
then, it stays in SYN_SENT: POLLOUT is not reported, write() returns
EAGAIN, and a blocking connect() waits, until the peer sends something.
As it was done before this commit, propagate the state from
subflow_state_change() in this case. subflow_finish_connect() then
returns early: also check there if MPTCP is blocked, as it does.
This issue has been found by an AI code review agent, while checking a
review from Sashiko, and confirmed with a new Packetdrill test: after a
simultaneous connect, poll() is called. Without this patch, POLLOUT was
not reported:
simult_connect_write.pkt:18: runtime error in poll call: Expected result 1 but got 0 with errno 115 (Operation now in progress)
Fixes: 71154bbe4942 ("mptcp: fallback earlier on simult connection")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent, after a Sashiko review
v3: also check if MPTCP is blocked, as subflow_finish_connect() did
(Clashiko)
---
net/mptcp/subflow.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 439a11d92281..190c75311ff6 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1988,6 +1988,19 @@ static void subflow_state_change(struct sock *sk)
__subflow_state_change(sk);
+ /* simult connect: not finished by subflow_finish_connect() */
+ if (unlikely(!subflow->conn_finished &&
+ sk->sk_state == TCP_ESTABLISHED &&
+ inet_sk_state_load(parent) == TCP_SYN_SENT &&
+ mptcp_check_fallback(sk))) {
+ subflow->rel_write_seq = 1;
+ subflow->conn_finished = 1;
+ /* It looks like MPTCP is blocked, while TCP is not */
+ if (subflow->mpc_drop)
+ mptcp_active_disable(parent);
+ mptcp_propagate_state(parent, sk, subflow, NULL);
+ }
+
/* Rx queue processing is unneeded, error reporting will take place at
* __mptcp_close_ssk() time and subflow reset can't happen in case of
* fallback: subflow_sched_work_if_closed() would be a no-op.
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 39/50] mptcp: fix MSG_PEEK after a partly peeked skb
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (37 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 38/50] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
` (11 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When recvmsg() with MSG_PEEK needs another pass, e.g. after having moved
the data from the backlog, the data already peeked is skipped. If this
data ends in the middle of an skb, e.g. the last one peeked, extended
since then by coalescing, the following skbs were skipped too, entirely
or partly, because the length of the data skipped in the first skb was
not counted: the peeked data was then corrupted.
This issue was likely causing a subtest from mptcp_connect_sendfile.sh
to fail, e.g. on NIPA, with a debug kernel. In the "saveWithPeek" mode,
the client saves the data peeked before reading it: the received file
had the same size, but not the same content.
# 46 ns1 MPTCP -> ns1 (10.0.1.1:10043 ) TCP (duration 264ms) [FAIL] file received by client does not match (in, out):
The root cause has been confirmed with a debug patch holding the MPTCP
socket lock for 200ms after the first MSG_PEEK pass in recvmsg(): 1000
bytes are peeked, then 1000 bytes are received and coalesced with them,
and 60000 more bytes in other skbs. Without this patch, only 60000 bytes
were peeked instead of 62000, and they were different from the data read
after:
peek repro: peeked 60000 bytes, DIFFERENT data
To fix this, count the data skipped in the first skb, so that the next
ones are not skipped.
Fixes: 8e04ce45a8db ("mptcp: fix MSG_PEEK stream corruption")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue causing a flaky selftest
---
net/mptcp/protocol.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 8017f8775728..0ff84d9684f1 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2301,6 +2301,7 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
delta = copied_total - total_data_len;
offset += delta;
data_len -= delta;
+ total_data_len += delta;
}
count = min_t(size_t, len - copied, data_len);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (38 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 39/50] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 41/50] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
` (10 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The data received while the MPTCP socket is owned by the user is put in
the backlog, and only moved to the MPTCP socket later. The TCP ACK sent
for this data then carries the previous DATA_ACK, and after having moved
the data, an updated DATA_ACK was only sent if a TCP ACK was still
pending, for more than one MSS.
If the peer had nothing else to send, it then didn't get the new
DATA_ACK, until another ACK was sent, e.g. when the reader frees enough
space in the receive buffer. Its MPTCP retransmission timer could then
fire, and the data was retransmitted for nothing at the MPTCP level.
Such a retransmission also prevents a later fallback to TCP, after an
MP_FAIL: this was causing the "Infinite map" subtest from mptcp_join.sh
to fail from time to time, with an unexpected MP_RST.
This behaviour has been introduced by commit bc68b0efa1bf ("mptcp: move
the whole rx path under msk socket lock protection"): before, this data
was moved to the MPTCP socket right away, even if it was owned by the
user.
To fix this, schedule a delayed ACK on the subflow of the last skb taken
from the backlog, if no ACK is pending there: the new DATA_ACK is then
sent with the next ACK on this subflow, or when the delayed ACK timer
expires. TCP sends its ACK when processing its own backlog, possibly
delayed too.
The root cause has been confirmed with a Packetdrill script and a debug
patch keeping the MPTCP socket lock in recvmsg() while data is received.
Without this patch, the DATA_ACK was not updated after having read the
data:
error handling packet: Timed out waiting for packet
Fixes: bc68b0efa1bf ("mptcp: move the whole rx path under msk socket lock protection")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue causing a flaky selftest
Note (Clashiko on v2): with several subflows, no DATA_ACK is scheduled
if the last subflow cannot send ACKs: only a spurious retransmission, as
before.
---
net/mptcp/protocol.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 0ff84d9684f1..2f89719e8454 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2417,10 +2417,21 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)
msk->rcvq_space.time = mstamp;
}
+/* The ACKs of the data put in the backlog carried the previous DATA_ACK */
+static void mptcp_subflow_schedule_ack(struct sock *ssk)
+{
+ bool slow = lock_sock_fast(ssk);
+
+ if (tcp_can_send_ack(ssk) && !inet_csk_ack_scheduled(ssk))
+ tcp_send_delayed_ack(ssk);
+ unlock_sock_fast(ssk, slow);
+}
+
static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delta)
{
struct sk_buff *skb = list_first_entry(skbs, struct sk_buff, list);
struct mptcp_sock *msk = mptcp_sk(sk);
+ struct sock *ssk = NULL;
bool moved = false;
while (1) {
@@ -2428,6 +2439,9 @@ static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delt
list_del(&skb->list);
*delta += skb->truesize;
+ /* NULL if the subflow has been closed */
+ if (skb->sk)
+ ssk = skb->sk;
moved |= __mptcp_move_skb(sk, skb);
if (list_empty(skbs))
break;
@@ -2439,6 +2453,9 @@ static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delt
if (!moved)
return false;
+ if (ssk && !__mptcp_check_fallback(msk))
+ mptcp_subflow_schedule_ack(ssk);
+
/* Only the worker can close an orphan, as it must then destroy it */
if (!sock_flag(sk, SOCK_DEAD))
mptcp_check_data_fin(sk);
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 41/50] selftests: mptcp: join: infinite map: no spurious rtx
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (39 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 42/50] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
` (9 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The "Infinite map" subtest sometimes failed with a reset instead of a
fallback to TCP, and the transfer was then stuck:
[FAIL] client exit code 2, server 2
(...)
MPTcpExtMPTCPRetrans 1
(...)
MPTcpExtDuplicateData 1
(...)
reset tx server [FAIL] got 1 MP_RST[s] TX expected 0
infi tx client [FAIL] got 0 infinite map[s] TX expected 1
Once some data has been retransmitted at the MPTCP level, a fallback
with an infinite mapping is no longer allowed: a checksum failure then
leads to a reset. Here, the retransmission is spurious: in the 'fast'
mode used by this subtest, each side writes 100 bytes, then waits
200ms. The 100 bytes from the server can be received while the client
socket is owned, e.g. when it is writing its own data: the TCP ACK is
then sent with the previous DATA_ACK, and the next one is only sent with
the next data, 200ms later. Meanwhile, the MPTCP retransmission timer
of the server, armed with the minimum RTO of its MPTCP socket, 200ms by
default, can expire.
This has been confirmed by setting tcp_rto_min_us to 20ms in both
netns, with a capture showing the stale DATA_ACK, then the
retransmission of the same data 20ms later, with a new subflow sequence
number:
S>C [P.], seq 1:101, ack 1, [mptcp 24 dss ack 3936022471 seq 1159191301011008422 subseq 1 len 100 (...)], length 100
C>S [.], ack 101, [mptcp 12 dss ack 1159191301011008422], length 0
(...)
S>C [P.], seq 101:201, ack 101, [mptcp 28 dss ack (...) seq 1159191301011008422 subseq 101 len 100 (...)], length 100
These MPTCP retransmissions are expected here. To avoid them, increase
the minimum RTO to 1 second in this subtest: the corrupted packet is
the next one sent by the client, after its 200ms pause. The MPTCP socket
only uses this sysctl since commit ea4eb2adb0d3 ("mptcp: honour
configured min/max RTO in retransmit paths"), in v7.3: before, this
change only increases the minimum RTO of the subflows. Errors are
ignored on kernels without this sysctl.
Fixes: b6e074e171bc ("selftests: mptcp: add infinite map testcase")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for a flaky selftest
---
tools/testing/selftests/net/mptcp/mptcp_join.sh | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 4c045532f137..3d48b02ee8c9 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -3828,6 +3828,12 @@ fail_tests()
# single subflow
if reset_with_fail "Infinite map" 1; then
MPTCP_LIB_SUBTEST_FLAKY=1
+ # MPTCP retransmissions prevent the fallback: avoid spurious
+ # ones during the 200ms pause of the 'fast' mode
+ ip netns exec $ns1 sysctl -q net.ipv4.tcp_rto_min_us=1000000 \
+ 2>/dev/null || true
+ ip netns exec $ns2 sysctl -q net.ipv4.tcp_rto_min_us=1000000 \
+ 2>/dev/null || true
test_linkfail=128 \
run_tests $ns1 $ns2 10.0.1.1
join_csum_ns1=+1 join_csum_ns2=+0 \
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 42/50] selftests: mptcp: connect: trunc: wait for acks
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (40 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 41/50] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
@ 2026-11-24 21:59 ` Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag Matthieu Baerts (NGI0)
` (8 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 21:59 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The "fastclose server test" subtest from mptcp_join.sh was still failing
from time to time, because the client output file didn't have the
expected size, e.g. on NIPA:
[FAIL] file received by client output file has wrong size (866, 1024)
Server ns stats (...)
(...)
TcpExtTCPOrigDataSent 3
TcpExtTCPDelivered 2
Here, the server sent 3 data segments only, the last one not acked yet,
and the client received all the data from these segments. The rest of
the data, already written by the server, was still queued, e.g. held by
Nagle, waiting for the last segment to be acked. But the server then
closed its socket, with data from the client still to read, as expected
here: an MP_FASTCLOSE is then sent, and the data still queued is
discarded, as with a TCP reset.
To fix this, wait for the written data to be acked, with SIOCOUTQ,
before stopping in the truncate mode, so before closing the socket. A
timeout is reported: it would look like this issue otherwise.
This issue has been confirmed on a debug kernel, where this subtest
failed a few times: each time, the client didn't have any data left in
its queues, and the data received matched the data in the segments sent
by the server. With this patch, it no longer failed.
Fixes: 6bf41020b72b ("selftests: mptcp: update and extend fastclose test-cases")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for a flaky selftest
---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 24 ++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index 8c788977e594..861fa2bd70d0 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -643,6 +643,26 @@ static void shut_wr(int fd)
shutdown(fd, SHUT_WR);
}
+/* the data still queued would be dropped by a reset: wait for its ack */
+static void wait_for_ack(int fd)
+{
+ struct pollfd pfd = { .fd = fd };
+ int i, queued;
+
+ for (i = 0; poll_timeout < 0 || i < poll_timeout; i += 10) {
+ if (quit || ioctl(fd, SIOCOUTQ, &queued) < 0 || queued <= 0)
+ return;
+
+ /* e.g. reset: the data will not be acked */
+ if (poll(&pfd, 1, 0) > 0 && (pfd.revents & POLLERR))
+ return;
+
+ usleep(10000);
+ }
+
+ fprintf(stderr, "timeout while waiting for the data to be acked\n");
+}
+
static int copyfd_io_poll(int infd, int peerfd, int outfd,
bool *in_closed_after_out, struct wstate *winfo)
{
@@ -768,8 +788,10 @@ static int copyfd_io_poll(int infd, int peerfd, int outfd,
}
if (cfg_truncate > 0 && total_wlen >= cfg_truncate &&
- total_rlen >= cfg_truncate)
+ total_rlen >= cfg_truncate) {
+ wait_for_ack(peerfd);
break;
+ }
}
/* leave some time for late join/announce */
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (41 preceding siblings ...)
2026-11-24 21:59 ` [PATCH mptcp-net v3 42/50] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 44/50] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
` (7 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
mptcp_data_fin_enabled() can be called from the subflow TX path, e.g.
when an ACK is sent from BH, without the msk socket lock. But
__mptcp_wr_shutdown() sets write_seq and snd_data_fin_enable without
ordering them: on a weakly ordered CPU, the TX path could see the flag
with the old write_seq. After all the data had been sent, the DATA_FIN
could then be sent with the sequence number of the last byte of data,
before the right one.
Use a release/acquire pair, to read the new write_seq with the flag.
This issue has been found by an AI code review agent (Clashiko), while
reviewing "mptcp: order write_seq and DATA_FIN flag for fallback". It is
theoretical: it has not been reproduced, and it needs a shutdown racing
with a packet sent from another CPU, after all the data has been sent.
Still, it is fine to fix it like that, without real impact: the
release/acquire pair is cheap -- plain accesses on x86 -- with the
release done once at shutdown time, and the acquire when sending a
packet, as the plain accesses before.
Fixes: 43b54c6ee382 ("mptcp: Use full MPTCP-level disconnect state machine")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v3: new, for an issue spotted by Clashiko
---
net/mptcp/protocol.c | 3 ++-
net/mptcp/protocol.h | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 2f89719e8454..e0f39931493e 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3694,7 +3694,8 @@ static void __mptcp_wr_shutdown(struct sock *sk)
/* will be ignored by fallback sockets */
WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
- WRITE_ONCE(msk->snd_data_fin_enable, 1);
+ /* pairs with the acquire in mptcp_data_fin_enabled() */
+ smp_store_release(&msk->snd_data_fin_enable, 1);
mptcp_check_send_data_fin(sk);
}
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 7cdd0a7e8296..a9daa047203c 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1028,7 +1028,8 @@ void __mptcp_error_report(struct sock *sk);
bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit);
static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk)
{
- return READ_ONCE(msk->snd_data_fin_enable) &&
+ /* pairs with the release in __mptcp_wr_shutdown() */
+ return smp_load_acquire(&msk->snd_data_fin_enable) &&
READ_ONCE(msk->write_seq) == READ_ONCE(msk->snd_nxt);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 44/50] mptcp: order write_seq and DATA_FIN flag for fallback
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (42 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
` (6 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
mptcp_try_fallback() can run in BH, without the msk socket lock. Since
the commit mentioned below, it reads write_seq after
snd_data_fin_enable, not to send a FIN before new data. But it reads the
flag without ordering it with write_seq: on a weakly ordered CPU,
mptcp_try_fallback() could see the flag with the old write_seq, and send
a FIN before the last byte of data.
Read the flag with an acquire, pairing with the release used by
__mptcp_wr_shutdown() since the previous commit, to read the new
write_seq with the flag.
This issue has been found by Clashiko, while reviewing the commit
mentioned below. It is theoretical: it has not been reproduced, and it
needs a shutdown racing with a fallback, with exactly one byte not sent
yet. Still, it is fine to fix it like that, without real impact: the
release/acquire pair is cheap -- plain accesses on x86 -- with the
release done once at shutdown time, and the acquire only when falling
back.
Fixes: d0e88ecfae68 ("mptcp: don't send a FIN before the pending data on fallback")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue spotted by Clashiko
v3: only the acquire, the release being in the new previous commit,
fixing an older issue
---
net/mptcp/protocol.c | 4 +++-
net/mptcp/protocol.h | 6 ++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index e0f39931493e..f361cd40a8e4 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3694,7 +3694,9 @@ static void __mptcp_wr_shutdown(struct sock *sk)
/* will be ignored by fallback sockets */
WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
- /* pairs with the acquire in mptcp_data_fin_enabled() */
+ /* pairs with the acquires in mptcp_data_fin_enabled() and
+ * mptcp_try_fallback()
+ */
smp_store_release(&msk->snd_data_fin_enable, 1);
mptcp_check_send_data_fin(sk);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index a9daa047203c..59ddf3dafeba 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1365,8 +1365,10 @@ static inline bool mptcp_try_fallback(struct sock *ssk, int fb_mib)
if (!__mptcp_try_fallback(msk, fb_mib))
return false;
- /* no FIN before new data: see mptcp_check_send_data_fin() */
- if (READ_ONCE(msk->snd_data_fin_enable) &&
+ /* no FIN before new data: see mptcp_check_send_data_fin(), and the
+ * release in __mptcp_wr_shutdown()
+ */
+ if (smp_load_acquire(&msk->snd_data_fin_enable) &&
!before64(READ_ONCE(msk->snd_nxt) + 1, READ_ONCE(msk->write_seq)) &&
!(ssk->sk_shutdown & SEND_SHUTDOWN)) {
gfp_t saved_allocation = ssk->sk_allocation;
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops"
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (43 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-net v3 44/50] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
` (5 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
A BPF scheduler can return 0 from get_send() without picking any
subflow, e.g. the bkup one from the BPF selftests, when all the subflows
are backup on both sides. With data to send, a DATA_ACK received while
the msk is not owned by the user then makes the push loop of
__mptcp_subflow_push_pending() spin forever, in softirq:
watchdog: BUG: soft lockup - CPU#2 stuck for 49s! [python3:182]
(...)
RIP: 0010:bpf_iter_mptcp_subflow_next+0xf/0x40
(...)
Call Trace:
<IRQ>
bpf_prog_bf2471f1d206d5cc_bpf_bkup_get_send+0x78/0xd7
bpf__mptcp_sched_ops_get_send+0x4c/0xb0
__mptcp_subflow_push_pending+0x148/0x390
mptcp_incoming_options+0x836/0xba0
tcp_data_queue+0x6da/0x10c0
tcp_rcv_established+0x2d5/0xce0
tcp_v4_do_rcv+0x13f/0x300
tcp_v4_rcv+0xbff/0x1200
(...)
Stop this loop when the current subflow is not picked: if another one
is, the loop already stops after delegating the push to it. The default
scheduler always picks a subflow when returning 0: not affected.
This issue has been found by an AI code review agent, while reviewing a
patch for the BPF schedulers, and confirmed with a reproducer: the bkup
scheduler on the client side, its only subflow marked as backup on both
sides, data queued by the client, then data sent by the server, carrying
the DATA_ACK causing the soft lockup above.
Similarly, the push loop of __mptcp_push_pending() spins forever, with
the msk and subflow locks held, when a BPF scheduler keeps picking a
subflow that cannot send, e.g. a new subflow in SYN_SENT picked by the
bkup scheduler before its backup flag is set: mptcp_sendmsg_frag() then
returns -EAGAIN, which does not decrease push_count in this state.
Decrease it after any failure: -EAGAIN is only returned for a subflow
that cannot send, or that has just been reset. The default scheduler
does not pick such subflows: not affected.
This second issue has been found by an AI code review agent (Clashiko),
while reviewing a previous version of this patch.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue found by a review agent
v3: also stop the push loop of __mptcp_push_pending() when the picked
subflow cannot send (Clashiko)
---
net/mptcp/protocol.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index f361cd40a8e4..a3c2d8f93bd7 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1901,10 +1901,7 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)
ret = __subflow_push_pending(sk, ssk, &info);
if (ret <= 0) {
- if (ret != -EAGAIN ||
- (1 << ssk->sk_state) &
- (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | TCPF_CLOSE))
- push_count--;
+ push_count--;
continue;
}
copied = true;
@@ -1961,6 +1958,9 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool
keep_pushing = false;
else
copied += ret;
+ } else {
+ /* a BPF scheduler might not pick any subflow */
+ keep_pushing = false;
}
mptcp_for_each_subflow(msk, subflow) {
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers"
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (44 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:45 ` sashiko-bot
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 47/50] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
` (4 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
With a BPF scheduler, the rtx timer interval, msk->timer_ival, is only
set if the scheduler calls the mptcp_set_timeout() kfunc: only the
burst one does. This interval is 0 once all the data has been acked, and
the rtx timer can then be armed with it, e.g. by the next push: it then
fires every jiffy, retransmitting the data in flight until it is acked.
Since "mptcp: arm the rtx timer if a push leaves data behind", this also
happens when a push sends nothing, e.g. in a memory shortage: the
timer then fires every jiffy, until a push succeeds.
Set this interval before calling a BPF scheduler, as the default one
does when picking a subflow, also when a subflow is already scheduled,
as the scheduler is then not called.
This issue has been found by Clashiko, while reviewing "mptcp: arm the
rtx timer if a push leaves data behind". Not reproduced.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for an issue spotted by Clashiko
v3: also set the interval when a subflow is already scheduled (Clashiko)
Note: when squashing, the commit message could mention that
mptcp_sched_get_send() now sets the rtx timer interval with a BPF
scheduler, as the default one does.
---
net/mptcp/sched.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c
index 1e59072d478c..01500f9f9f8a 100644
--- a/net/mptcp/sched.c
+++ b/net/mptcp/sched.c
@@ -182,6 +182,10 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)
return -EINVAL;
}
+ /* as the default scheduler: the rtx timer needs an interval */
+ if (msk->sched && msk->sched != &mptcp_sched_default)
+ mptcp_set_timeout((struct sock *)msk);
+
mptcp_for_each_subflow(msk, subflow) {
if (READ_ONCE(subflow->scheduled))
return 0;
@@ -189,6 +193,7 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)
if (msk->sched == &mptcp_sched_default || !msk->sched)
return mptcp_sched_default_get_send(msk);
+
return msk->sched->get_send(msk);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-next mptcp-net v3 47/50] mptcp: push pending data after a fallback on reception
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (45 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
` (3 subsequent siblings)
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When received data without DSS makes the MPTCP socket fall back to TCP,
the data not sent yet is not pushed: on fallback, this is done by
mptcp_incoming_options(), which already processed this packet before
the fallback. This data, and the FIN of an earlier shutdown, then wait
for the next packet from the peer, or for the MPTCP retransmission
timer armed before the fallback: up to one RTO.
Push it from mptcp_data_ready(), which follows these fallbacks, also
the ones after a DSS corruption. For the next packets, this push comes
after the one from mptcp_incoming_options(), which already sent what it
could.
This issue has been found by Clashiko, while reviewing "mptcp: don't
send a FIN before the pending data on fallback", and confirmed with a
new Packetdrill test: after a shutdown, with data still in the MPTCP
socket, the peer sends data without MPTCP options. Without this patch,
with an RTO of one second, the data is sent about one second later:
dss_fallback_push_pending_server.pkt:27: error handling packet: timing error: expected outbound packet at 0.312538 sec but happened at 1.274089 sec; tolerance 0.100000 sec
With this patch, the data and the FIN are sent right after the fallback.
Note for the backports: the fallback after receiving data without DSS
comes from commit 119d51e225fe ("mptcp: fallback when MPTCP opts are
dropped after 1st data"), also in v6.12, and backported down to v5.15.
Fixes: e32d262c89e2 ("mptcp: handle consistently DSS corruption")
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for mptcp-next, for an issue spotted by Clashiko in a fix
pending in net
---
net/mptcp/protocol.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index a3c2d8f93bd7..016b16b3cc92 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1083,6 +1083,10 @@ void mptcp_data_ready(struct sock *sk, struct sock *ssk)
} else {
__mptcp_move_skbs_from_subflow(msk, ssk, false);
}
+
+ /* mptcp_incoming_options() can't push if this data caused a fallback */
+ if (__mptcp_check_fallback(msk) && sk_stream_memory_free(ssk))
+ __mptcp_check_push(sk, ssk);
mptcp_data_unlock(sk);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (46 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 47/50] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:52 ` sashiko-bot
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 49/50] mptcp: trace: name all the mapping statuses Matthieu Baerts (NGI0)
` (2 subsequent siblings)
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
When the close timeout expires, or when the last subflow is closed in
another state than ESTABLISHED, the MPTCP socket moves to TCP_CLOSE
without error, and recv() then reports ENOTCONN instead of EOF. In
these cases, TCP sets SHUTDOWN_MASK and an error depending on the
state: ETIMEDOUT after a timeout, and ECONNRESET, EPIPE or ECONNREFUSED
after a reset.
Do the same, as tcp_done_with_error() does, also in the late cleanup
done by accept(), when the first subflow has been closed before: with
the error of the last subflow, e.g. ETIMEDOUT after its RTO. After a
reset, or without error, the error depends on the MPTCP-level state,
e.g. EPIPE after a DATA_FIN. When a subflow error closes the socket,
SHUTDOWN_MASK is now set too, as tcp_done() does.
This changes the errors seen by the applications: after the close
timeout, reading or writing now reports ETIMEDOUT once, instead of
ENOTCONN or EPIPE, then EOF and EPIPE, as with TCP after a timeout. The
tests checking these errors in the MPTCP Packetdrill repository have to
be adapted.
With the reproducer from the GitHub issue, where the only subflow dies
by RTO, send() now returns ETIMEDOUT after the subflow timeout and the
close timeout, instead of EPIPE.
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/648
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: new, for mptcp-next, as suggested in issue #648 on GitHub
Note (Clashiko on v2): the FIN cleared by the disconnect of the first
subflow is now handled by "mptcp: return EOF after a DATA_FIN, as TCP
does", and a reset received before accept() after a fallback by "mptcp:
report errors received before accept()". In FIN_WAIT2, the subflow error
is still reported by __mptcp_error_report(), deferred to the release of
the socket.
---
net/mptcp/protocol.c | 88 +++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 67 insertions(+), 21 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 016b16b3cc92..0a7600aea181 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -518,6 +518,56 @@ static void mptcp_close_wake_up(struct sock *sk)
sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
}
+/* Mirror the tcp_reset() error propagation */
+static int mptcp_reset_err(const struct sock *sk)
+{
+ int err;
+
+ switch (sk->sk_state) {
+ case TCP_SYN_SENT:
+ err = ECONNREFUSED;
+ break;
+ case TCP_CLOSE_WAIT:
+ err = EPIPE;
+ break;
+ default:
+ err = ECONNRESET;
+ }
+
+ return err;
+}
+
+/* No more data can be exchanged: report it, as tcp_done_with_error() does */
+static void mptcp_close_err(struct sock *sk, int err)
+{
+ WRITE_ONCE(sk->sk_err, err);
+ /* This barrier is coupled with smp_rmb() in mptcp_poll() */
+ smp_wmb();
+ WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
+ mptcp_set_state(sk, TCP_CLOSE);
+ if (sock_flag(sk, SOCK_DEAD))
+ return;
+
+ mptcp_close_wake_up(sk);
+ sk_error_report(sk);
+}
+
+/* As TCP: the error of the last subflow, e.g. ETIMEDOUT, but after a reset
+ * (EBADMSG: by MPTCP) or without error, it depends on the msk state
+ */
+static void mptcp_close_last_err(struct sock *sk, int err)
+{
+ switch (err) {
+ case 0:
+ case ECONNREFUSED:
+ case ECONNRESET:
+ case EPIPE:
+ case EBADMSG:
+ err = mptcp_reset_err(sk);
+ }
+ mptcp_close_err(sk, err);
+}
+
static void mptcp_shutdown_subflows(struct mptcp_sock *msk)
{
struct mptcp_subflow_context *subflow;
@@ -983,7 +1033,7 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD)) {
/* This barrier is coupled with smp_rmb() in mptcp_poll() */
smp_wmb();
- WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
+ WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
mptcp_set_state(sk, ssk_state);
}
report = true;
@@ -2809,7 +2859,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
{
struct mptcp_sock *msk = mptcp_sk(sk);
bool dispose_it, need_push = false;
- int fwd_remaining;
+ int fwd_remaining, ssk_err;
/* Do not pass RX data to the msk, even if the subflow socket is not
* going to be freed (i.e. even for the first subflow on graceful
@@ -2817,6 +2867,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
*/
lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
subflow->closing = 1;
+ /* in case it is the last subflow: before its disconnect or dispose */
+ ssk_err = READ_ONCE(ssk->sk_err);
if (flags & MPTCP_CF_PUSH)
mptcp_cleanup_ssk_backlog(sk, ssk);
@@ -2905,13 +2957,15 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
mptcp_set_close_tout(sk, tcp_jiffies32 -
(mptcp_close_timeout(sk) + 1));
mptcp_schedule_work(sk);
+ } else if (sk->sk_state == TCP_CLOSE) {
+ mptcp_close_wake_up(sk);
} else if (sk->sk_state != TCP_ESTABLISHED ||
msk->in_accept_queue) {
mptcp_check_rcv_close(sk);
- mptcp_set_state(sk, TCP_CLOSE);
- WRITE_ONCE(sk->sk_shutdown,
- sk->sk_shutdown | SEND_SHUTDOWN);
- mptcp_close_wake_up(sk);
+ if (sk->sk_state == TCP_CLOSE)
+ mptcp_close_wake_up(sk);
+ else
+ mptcp_close_last_err(sk, ssk_err);
} else {
mptcp_start_tout_timer(sk);
}
@@ -3108,20 +3162,10 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
unlock_sock_fast(tcp_sk, slow);
}
- /* Mirror the tcp_reset() error propagation */
- switch (sk->sk_state) {
- case TCP_SYN_SENT:
- WRITE_ONCE(sk->sk_err, ECONNREFUSED);
- break;
- case TCP_CLOSE_WAIT:
- WRITE_ONCE(sk->sk_err, EPIPE);
- break;
- case TCP_CLOSE:
+ if (sk->sk_state == TCP_CLOSE)
return;
- default:
- WRITE_ONCE(sk->sk_err, ECONNRESET);
- }
+ WRITE_ONCE(sk->sk_err, mptcp_reset_err(sk));
mptcp_set_state(sk, TCP_CLOSE);
WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
@@ -3441,8 +3485,7 @@ static void mptcp_worker(struct work_struct *work)
mptcp_do_fastclose(sk);
mptcp_for_each_subflow_safe(msk, subflow, tmp)
__mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
- WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
- mptcp_close_wake_up(sk);
+ mptcp_close_err(sk, ETIMEDOUT);
}
if (sock_flag(sk, SOCK_DEAD) && sk->sk_state == TCP_CLOSE) {
@@ -4795,10 +4838,13 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
*/
if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
if (unlikely(list_is_singular(&msk->conn_list))) {
+ int err = READ_ONCE(msk->first->sk_err);
+
mptcp_check_rcv_close(newsk);
/* not reported in the accept queue */
__mptcp_error_report(newsk);
- mptcp_set_state(newsk, TCP_CLOSE);
+ if (newsk->sk_state != TCP_CLOSE)
+ mptcp_close_last_err(newsk, err);
}
mptcp_close_ssk(newsk, msk->first,
mptcp_subflow_ctx(msk->first));
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH mptcp-next mptcp-net v3 49/50] mptcp: trace: name all the mapping statuses
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (47 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
2026-11-25 0:39 ` [PATCH mptcp-net v3 00/50] mptcp: misc fixes MPTCP CI
50 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
The subflow_check_data_avail tracepoint prints the status returned by
get_mapping_status() with its name, except for MAPPING_BAD_CSUM and
MAPPING_NODSS, added later: they were printed as numbers.
This has been found by an AI code review agent (Clashiko), while
reviewing a patch adding another status.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v3: new, for an issue spotted by Clashiko
---
include/trace/events/mptcp.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/trace/events/mptcp.h b/include/trace/events/mptcp.h
index c47fa2672b84..ebc7408c1fa6 100644
--- a/include/trace/events/mptcp.h
+++ b/include/trace/events/mptcp.h
@@ -19,7 +19,9 @@
{ 1, "MAPPING_INVALID" }, \
{ 2, "MAPPING_EMPTY" }, \
{ 3, "MAPPING_DATA_FIN" }, \
- { 4, "MAPPING_DUMMY" })
+ { 4, "MAPPING_DUMMY" }, \
+ { 5, "MAPPING_BAD_CSUM" }, \
+ { 6, "MAPPING_NODSS" })
TRACE_EVENT(mptcp_subflow_get_send,
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (48 preceding siblings ...)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 49/50] mptcp: trace: name all the mapping statuses Matthieu Baerts (NGI0)
@ 2026-11-24 22:00 ` Matthieu Baerts (NGI0)
2026-11-24 22:36 ` sashiko-bot
2026-11-25 0:39 ` [PATCH mptcp-net v3 00/50] mptcp: misc fixes MPTCP CI
50 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-24 22:00 UTC (permalink / raw)
To: MPTCP Linux; +Cc: Matthieu Baerts (NGI0)
RFC 8684, section 3.7, describes a fallback to TCP for the case where
the MPTCP options get through on the SYN, but not on the next packets.
A sender includes a DSS option in each segment "until one of the sent
segments has been acknowledged with a DSS option containing a Data
ACK": it then has "the confirmation that the DSS option passes in both
directions". After that, a subflow that loses its MPTCP options "SHOULD
be treated as broken and closed with a RST", with the "Middlebox
interference" reason. It's a *SHOULD*.
Commit 119d51e225fe ("mptcp: fallback when MPTCP opts are dropped after
1st data") did this fallback as long as allow_infinite_fallback is set,
i.e. also after this confirmation, and left the check of the DATA_ACK
for later [1]. Such a late fallback is fragile: the peer might still
resend data that was mapped before, or a zero window probe might have
mapped old data again. The previous commits "mptcp: do not fallback
while old data is in flight", "mptcp: stop resending data to a peer that
fell back", "mptcp: don't resend data acked without MPTCP opts" and
"mptcp: continue the last mapping after a fallback" handle these cases,
except one: if only the receiver falls back, it can deliver data resent
at the MPTCP level as new data, if the sender does not reset the subflow
before, e.g. with an older kernel. Yeah, a very specific corner case.
Now, when data without DSS is found on a subflow, the subflow is reset
if a DATA_ACK received on it acknowledged data that had been sent: the
MPTCP options then passed in both directions. Except after an MP_FAIL
exchange: a fallback to TCP is then in progress, so data without DSS is
expected, even if the infinite mapping has not been seen. This also
closes the case above, but only for a receiver whose data has been
acknowledged.
Receiving a DATA_ACK is not enough: when the MPTCP options are only
dropped in one direction, the peer can fall back while the DATA_ACKs it
sent before acknowledged no data. A client that is not fully
established falls back when a packet from the server has no MPTCP
options, e.g. an ACK of its data, and the other hosts when they receive
data without DSS. Except after an MP_FAIL, Linux falls back without
sending an infinite mapping, then sends data without DSS: the other
side can only fall back too, as before, if its data had not been
acknowledged. For the same reason, the amount of received data -- e.g.
more than an initial window -- is not used.
The same is done when a mapping is invalid, e.g. when it does not cover
the received data after a resegmentation by a middlebox, but not for an
infinite mapping, the fallback signal from the RFC: it gets a new
MAPPING_INFINITE status, also named in the tracepoint.
When a middlebox starts dropping the MPTCP options in the middle of a
connection, after a DATA_ACK acknowledged data, the subflow is then
reset, instead of falling back to TCP when it was safe. If it was the
only subflow, the MPTCP connection stays without subflow until the
close timeout -- 60 seconds by default, see net.mptcp.close_timeout --
unless a new one is created in between.
New Packetdrill tests check these resets.
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/519 [1]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
v2: also reset on an invalid mapping (Clashiko), and commit message: the
remaining case is now handled by the sender
v3: name MAPPING_INFINITE in the tracepoint, and msg: all the invalid
mappings (Clashiko)
Note: this commit changes the behaviour, it is for next. It fixes a very
specific corner case (but it follows what the RFC 8684 recommends to do)
but for that it needs an extra flag and more checks. Is it worth it? (I
think so, but that's why it is flagged as RFC.)
Note (Clashiko on v2): subflow_nodss_is_fatal() also handles the invalid
mappings, and the description of MPTCP_MIB_DSSRESET is imprecise: to be
improved if this RFC is accepted.
Note (Sashiko on v2): an skb going past the end of its mapping is still
handled by mptcp_dss_corruption(), which falls back, even after a
DATA_ACK: to be covered too if this RFC is accepted.
---
include/trace/events/mptcp.h | 3 ++-
net/mptcp/options.c | 11 +++++++----
net/mptcp/protocol.h | 3 ++-
net/mptcp/subflow.c | 29 +++++++++++++++++++++++++----
4 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/include/trace/events/mptcp.h b/include/trace/events/mptcp.h
index ebc7408c1fa6..527eb7a18528 100644
--- a/include/trace/events/mptcp.h
+++ b/include/trace/events/mptcp.h
@@ -21,7 +21,8 @@
{ 3, "MAPPING_DATA_FIN" }, \
{ 4, "MAPPING_DUMMY" }, \
{ 5, "MAPPING_BAD_CSUM" }, \
- { 6, "MAPPING_NODSS" })
+ { 6, "MAPPING_NODSS" }, \
+ { 7, "MAPPING_INFINITE" })
TRACE_EVENT(mptcp_subflow_get_send,
diff --git a/net/mptcp/options.c b/net/mptcp/options.c
index 41eb39968a9a..e561143dd121 100644
--- a/net/mptcp/options.c
+++ b/net/mptcp/options.c
@@ -1144,7 +1144,7 @@ static void rwin_update(struct mptcp_sock *msk, struct sock *ssk,
subflow->rcv_wnd_sent = mptcp_rcv_wnd;
}
-static void ack_update_msk(struct mptcp_sock *msk,
+static bool ack_update_msk(struct mptcp_sock *msk,
struct sock *ssk,
const struct sk_buff *skb,
struct mptcp_options_received *mp_opt)
@@ -1153,6 +1153,7 @@ static void ack_update_msk(struct mptcp_sock *msk,
u32 win = ntohs(tcp_hdr(skb)->window);
struct sock *sk = (struct sock *)msk;
u64 snd_nxt;
+ bool acked;
mptcp_data_lock(sk);
@@ -1185,7 +1186,8 @@ static void ack_update_msk(struct mptcp_sock *msk,
if (after64(msk->wnd_end, snd_nxt))
__mptcp_check_push(sk, ssk);
- if (after64(new_snd_una, old_snd_una)) {
+ acked = after64(new_snd_una, old_snd_una);
+ if (acked) {
__mptcp_snd_una_update(msk, new_snd_una);
__mptcp_data_acked(sk);
}
@@ -1195,6 +1197,7 @@ static void ack_update_msk(struct mptcp_sock *msk,
trace_ack_update_msk(mp_opt->data_ack,
old_snd_una, new_snd_una,
new_wnd_end, READ_ONCE(msk->wnd_end));
+ return acked;
}
bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit)
@@ -1356,8 +1359,8 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
/* we can't wait for recvmsg() to update the ack_seq, otherwise
* monodirectional flows will stuck
*/
- if (mp_opt.use_ack)
- ack_update_msk(msk, sk, skb, &mp_opt);
+ if (mp_opt.use_ack && ack_update_msk(msk, sk, skb, &mp_opt))
+ subflow->dss_confirmed = 1; /* MPTCP opts pass both ways */
rwin_update(msk, sk, skb);
/* Zero-data-length packets are dropped by the caller and not
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 59ddf3dafeba..70cd119bdbb8 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -609,7 +609,8 @@ struct mptcp_subflow_context {
resetting : 1, /* subflow is resetting */
old_data_pending : 1, /* old data not acked with MPTCP opts */
map_old : 1, /* MPC: peer's last map is below dsn_end */
- __unused : 7;
+ dss_confirmed : 1, /* a DATA_ACK acked our data */
+ __unused : 6;
bool data_avail;
bool scheduled;
bool pm_listener; /* a listener managed by the kernel PM? */
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 190c75311ff6..efbd3efd379e 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1072,7 +1072,8 @@ enum mapping_status {
MAPPING_DATA_FIN,
MAPPING_DUMMY,
MAPPING_BAD_CSUM,
- MAPPING_NODSS
+ MAPPING_NODSS,
+ MAPPING_INFINITE
};
static void dbg_bad_map(struct mptcp_subflow_context *subflow, u32 ssn)
@@ -1242,7 +1243,7 @@ static enum mapping_status get_mapping_status(struct sock *ssk,
if (data_len == 0) {
pr_debug("infinite mapping received\n");
MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPRX);
- return MAPPING_INVALID;
+ return MAPPING_INFINITE;
}
if (mpext->data_fin == 1) {
@@ -1453,6 +1454,22 @@ static void subflow_update_dsn_base(struct mptcp_subflow_context *subflow)
subflow->dsn_end = end;
}
+/* RFC 8684, 3.7: no fallback once a DATA_ACK acked our data, except MP_FAIL */
+static bool subflow_nodss_is_fatal(struct mptcp_sock *msk,
+ const struct mptcp_subflow_context *subflow)
+{
+ bool fatal;
+
+ if (!subflow->dss_confirmed)
+ return false;
+
+ /* before a fallback, only an MP_FAIL clears allow_subflows */
+ spin_lock_bh(&msk->fallback_lock);
+ fatal = msk->allow_subflows;
+ spin_unlock_bh(&msk->fallback_lock);
+ return fatal;
+}
+
static bool subflow_check_data_avail(struct sock *ssk)
{
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
@@ -1473,7 +1490,9 @@ static bool subflow_check_data_avail(struct sock *ssk)
status = get_mapping_status(ssk, msk);
trace_subflow_check_data_avail(status, skb_peek(&ssk->sk_receive_queue));
if (unlikely(status == MAPPING_INVALID || status == MAPPING_DUMMY ||
- status == MAPPING_BAD_CSUM || status == MAPPING_NODSS))
+ status == MAPPING_BAD_CSUM ||
+ status == MAPPING_NODSS ||
+ status == MAPPING_INFINITE))
goto fallback;
if (status != MAPPING_OK)
@@ -1523,7 +1542,9 @@ static bool subflow_check_data_avail(struct sock *ssk)
return true;
}
- if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
+ if (((status == MAPPING_NODSS || status == MAPPING_INVALID) &&
+ subflow_nodss_is_fatal(msk, subflow)) ||
+ !mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
/* fatal protocol error, reset the subflow and let the
* worker close it
*/
--
2.55.0
^ permalink raw reply related [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN
2026-11-24 21:59 ` [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
@ 2026-11-24 22:33 ` sashiko-bot
0 siblings, 0 replies; 75+ messages in thread
From: sashiko-bot @ 2026-11-24 22:33 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: pending DATA_FIN skipped for TCP_ESTABLISHED in
__mptcp_close_ssk()
--
commit 31bc56e76b249e9f9785ca53d63505bc1884f890
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
mptcp: no sf left: process pending DATA_FIN
This commit introduces mptcp_check_rcv_close() to spool the backlog and
process a pending DATA_FIN or MP_FASTCLOSE before closing the MPTCP socket
when the last subflow closes.
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index bcdad00d35732..b57d0f82b416e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2707,6 +2707,18 @@ static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
>
> static void mptcp_check_fastclose(struct mptcp_sock *msk);
>
> +/* After the close, a pending DATA_FIN or MP_FASTCLOSE would be ignored */
> +static void mptcp_check_rcv_close(struct sock *sk)
> +{
> + /* process the DATA_FIN after the data still in the backlog */
> + if (READ_ONCE(mptcp_sk(sk)->rcv_data_fin)) {
> + mptcp_move_skbs(sk);
> + mptcp_check_data_fin(sk);
> + }
> +
> + mptcp_check_fastclose(mptcp_sk(sk));
> +}
> +
> /* subflow sockets can be either outgoing (connect) or incoming
> * (accept).
> *
> @@ -2819,9 +2831,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> mptcp_schedule_work(sk);
> } else if (sk->sk_state != TCP_ESTABLISHED ||
> msk->in_accept_queue) {
> - /* After the close, an MP_FASTCLOSE would be ignored */
> - mptcp_check_fastclose(msk);
> -
> + mptcp_check_rcv_close(sk);
> mptcp_set_state(sk, TCP_CLOSE);
> WRITE_ONCE(sk->sk_shutdown,
> sk->sk_shutdown | SEND_SHUTDOWN);
[Severity: Medium]
Should mptcp_check_rcv_close(sk) run before the
sk->sk_state != TCP_ESTABLISHED check?
On an accepted non-fallback socket in TCP_ESTABLISHED, if the peer sends
the final data with DATA_FIN and closes the last subflow while
mptcp_worker() holds the socket lock, the data sits in msk->backlog_list.
Because mptcp_worker() runs mptcp_check_data_fin() and
__mptcp_close_subflow() before release_sock() spools the backlog, and
mptcp_close_ssk() only spools the backlog before __mptcp_close_ssk() on
fallback sockets:
net/mptcp/protocol.c:mptcp_close_ssk() {
...
if (ssk == msk->first && __mptcp_check_fallback(msk) &&
READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
mptcp_move_skbs(sk);
mptcp_check_data_fin(sk);
}
__mptcp_close_ssk(sk, ssk, subflow, flags);
}
sk->sk_state is still TCP_ESTABLISHED here. __mptcp_close_ssk() skips
mptcp_check_rcv_close() and starts the close timeout timer instead, and
when release_sock() later spools the backlog and processes the DATA_FIN,
the socket transitions to TCP_CLOSE_WAIT after msk->first has already been
closed, leaving the socket stuck in TCP_CLOSE_WAIT with no subflows until
the close timeout expires.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=12
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts
2026-11-24 21:59 ` [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
@ 2026-11-24 22:36 ` sashiko-bot
0 siblings, 0 replies; 75+ messages in thread
From: sashiko-bot @ 2026-11-24 22:36 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: false reset in check_fully_established() due to stale
opt_ack_seq
--
commit d927d8fcbe3e60d7a3edc0251d874227df06db6e
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
mptcp: don't resend data acked without MPTCP opts
This commit tracks the highest TCP ack_seq received with MPTCP options in
subflow->opt_ack_seq and resets the subflow instead of resending data if
snd_una has advanced past opt_ack_seq before any MP_JOIN subflow is
established.
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index f9b65d0c6290a..05b9c66aaed63 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
[ ... ]
> @@ -1287,11 +1291,16 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
> if (!check_fully_established(msk, sk, subflow, skb, &mp_opt))
> return sk->sk_state != TCP_CLOSE;
>
> - /* MPTCP opt acking the old data, not an infinite map: no fallback */
> - if (unlikely(subflow->old_data_pending) && mp_opt.suboptions &&
> - !(mp_opt.use_map && !mp_opt.data_len) &&
> - !before(TCP_SKB_CB(skb)->ack_seq, subflow->old_data_end))
> - subflow->old_data_pending = 0;
> + /* MPTCP opts, not an infinite map: the peer did not fall back */
> + if (mp_opt.suboptions && !(mp_opt.use_map && !mp_opt.data_len)) {
> + u32 ack_seq = TCP_SKB_CB(skb)->ack_seq;
> +
> + if (after(ack_seq, subflow->opt_ack_seq))
> + subflow->opt_ack_seq = ack_seq;
> + if (unlikely(subflow->old_data_pending) &&
> + !before(ack_seq, subflow->old_data_end))
> + subflow->old_data_pending = 0;
> + }
[Severity: Medium]
Can calling check_fully_established() before updating subflow->opt_ack_seq
falsely reset a passive TFO subflow?
On a passive TFO child (tcp_sk(ssk)->syn_fastopen_child), if an out-of-order
packet transitions ssk to TCP_ESTABLISHED before subflow->fully_established
is set, the server can already send data on ssk. When the peer's packet with
valid MPTCP options (such as OPTION_MPTCP_MPC_ACK) arrives and acknowledges
that data, tcp_ack() advances tcp_sk(ssk)->snd_una before
mptcp_incoming_options() runs.
Because check_fully_established() runs before subflow->opt_ack_seq is
updated:
net/mptcp/options.c:check_fully_established() {
...
mptcp_data_lock(sk);
__mptcp_subflow_fully_established(msk, subflow, mp_opt);
if (tcp_sk(ssk)->syn_fastopen_child)
__mptcp_check_push(sk, ssk);
mptcp_data_unlock(sk);
...
}
__mptcp_check_push() -> mptcp_sendmsg_frag() sees after(tcp_sk(ssk)->snd_una,
subflow->opt_ack_seq) as true. If mptcp_sendmsg_frag() sends a zero-window
probe or old data (before64(data_seq, msk->snd_nxt)), it resets the subflow
with MPTCP_RST_EMIDDLEBOX even though the incoming packet carried valid MPTCP
options.
In addition, if __mptcp_check_push() inside check_fully_established() resets
ssk on a packet without OPTION_MPTCP_DSS, check_fully_established() still
returns true and mptcp_incoming_options() returns true before checking
sk->sk_state == TCP_CLOSE, leaving tcp_data_queue() to process the skb on a
closed subflow.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=29
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK
2026-11-24 22:00 ` [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
@ 2026-11-24 22:36 ` sashiko-bot
0 siblings, 0 replies; 75+ messages in thread
From: sashiko-bot @ 2026-11-24 22:36 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: fallback after dss_confirmed in mptcp_dss_corruption()
on partial map
--
commit 52bcf0ed394d73280e0a61e58a2314837d68feb0
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
mptcp: reset when the DSS disappears after a DATA_ACK
This commit tracks whether a received DATA_ACK has acknowledged sent data
on a subflow and resets the subflow instead of falling back to TCP when a
subsequent packet lacks a DSS mapping or has an invalid mapping.
> diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
> index 190c75311ff69..efbd3efd379ed 100644
> --- a/net/mptcp/subflow.c
> +++ b/net/mptcp/subflow.c
[ ... ]
> @@ -1523,7 +1542,9 @@ static bool subflow_check_data_avail(struct sock *ssk)
> return true;
> }
>
> - if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
> + if (((status == MAPPING_NODSS || status == MAPPING_INVALID) &&
> + subflow_nodss_is_fatal(msk, subflow)) ||
> + !mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
> /* fatal protocol error, reset the subflow and let the
> * worker close it
> */
[Severity: Medium]
Can an skb that starts within the current mapping but extends past
subflow->map_data_len (for example, after middlebox resegmentation or
coalescing) still trigger a fallback after subflow->dss_confirmed is set?
In get_mapping_status(), validate_mapping() only checks that the starting
subflow sequence number lies within the active mapping range, without
verifying that the mapping covers the full skb length:
net/mptcp/subflow.c:validate_mapping() {
...
if (unlikely(before(ssn, subflow->map_subflow_seq))) {
...
return false;
}
if (unlikely(!before(ssn, subflow->map_subflow_seq +
subflow->map_data_len))) {
...
return false;
}
return true;
}
get_mapping_status() therefore returns MAPPING_OK, bypassing
subflow_nodss_is_fatal() in subflow_check_data_avail(). When
__mptcp_move_skbs_from_subflow() then sees map_remaining < len, it calls
mptcp_dss_corruption(), which calls mptcp_try_fallback() directly without
checking subflow->dss_confirmed:
net/mptcp/protocol.c:mptcp_dss_corruption() {
if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSCORRUPTIONRESET);
mptcp_subflow_reset(ssk);
}
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=50
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers"
2026-11-24 22:00 ` [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
@ 2026-11-24 22:45 ` sashiko-bot
0 siblings, 0 replies; 75+ messages in thread
From: sashiko-bot @ 2026-11-24 22:45 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: mptcp_sched_get_send() skips mptcp_set_timeout() on
scheduled subflow
--
commit a82acd8ca33d023de6cf973e96c25c49bb5f9fc5
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Squash to "bpf: Export mptcp packet scheduler helpers"
This commit calls mptcp_set_timeout() in mptcp_sched_get_send() when a
non-default scheduler is configured so that msk->timer_ival is initialized
even if a subflow is already scheduled or the BPF scheduler does not set
the timeout itself.
> diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c
> index 1e59072d478c9..01500f9f9f8a6 100644
> --- a/net/mptcp/sched.c
> +++ b/net/mptcp/sched.c
> @@ -182,6 +182,10 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)
> return -EINVAL;
> }
>
> + /* as the default scheduler: the rtx timer needs an interval */
> + if (msk->sched && msk->sched != &mptcp_sched_default)
> + mptcp_set_timeout((struct sock *)msk);
> +
> mptcp_for_each_subflow(msk, subflow) {
> if (READ_ONCE(subflow->scheduled))
> return 0;
> @@ -189,6 +193,7 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)
>
> if (msk->sched == &mptcp_sched_default || !msk->sched)
> return mptcp_sched_default_get_send(msk);
> +
> return msk->sched->get_send(msk);
> }
[Severity: Medium]
Does guarding mptcp_set_timeout() with msk->sched != &mptcp_sched_default
still leave msk->timer_ival at 0 when a subflow is already scheduled under
the default scheduler?
With the default scheduler, mptcp_set_timeout() is normally called inside
mptcp_sched_default_get_send() -> mptcp_subflow_get_send(). However, a
subflow can retain subflow->scheduled == true after all pending data is
acknowledged and mptcp_stop_rtx_timer() resets msk->timer_ival to 0. For
example, in ack_update_msk() during recovery, __mptcp_check_push() runs
before __mptcp_data_acked() -> __mptcp_clean_una(): the push can schedule a
second subflow and delegate MPTCP_DELEGATE_SEND right before
__mptcp_clean_una() clears msk->first_pending and stops the rtx timer.
When __mptcp_subflow_push_pending() later runs on that delegated subflow,
mptcp_send_head(sk) is NULL, so the push loop is not entered and
subflow->scheduled is never cleared.
On the next send, mptcp_sched_get_send() skips mptcp_set_timeout() above,
sees READ_ONCE(subflow->scheduled), and returns 0 without calling
mptcp_sched_default_get_send(). If __subflow_push_pending() then exits
before its own mptcp_set_timeout() call (because mptcp_sendmsg_frag() fails
or msk->snd_burst <= 0 after the first fragment), mptcp_reset_rtx_timer()
arms the retransmit timer with msk->timer_ival == 0, causing it to fire
every jiffy.
Calling mptcp_set_timeout() unconditionally here (or in the early return
when subflow->scheduled is set) would cover the default scheduler as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=46
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect
2026-11-24 21:59 ` [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
@ 2026-11-24 22:45 ` sashiko-bot
0 siblings, 0 replies; 75+ messages in thread
From: sashiko-bot @ 2026-11-24 22:45 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mptcp: mptcp_syn_options() sets ssn_offset on MP_JOIN simult
connect
--
commit dbb5c11e7bc9fc6242718c808b25e1938f5448b0
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
mptcp: keep the first byte after a simult connect
This commit initializes subflow->ssn_offset when sending a SYN-ACK in
TCP_SYN_RECV after a simultaneous connect and only updates it in
subflow_finish_connect() when the incoming packet carries TCPHDR_SYN.
> diff --git a/net/mptcp/options.c b/net/mptcp/options.c
> index 05b9c66aaed63..41eb39968a9a6 100644
> --- a/net/mptcp/options.c
> +++ b/net/mptcp/options.c
> @@ -474,6 +474,11 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
> * in mptcp_established_options_mp()
> */
> subflow->snd_isn = TCP_SKB_CB(skb)->end_seq;
> +
> + /* simult connect: the peer's SYN-ACK will not set ssn_offset */
> + if (unlikely(sk->sk_state == TCP_SYN_RECV))
> + subflow->ssn_offset = tcp_sk(sk)->rcv_nxt - 1;
> +
> if (subflow->request_mptcp) {
> if (unlikely(subflow_simultaneous_connect(sk))) {
> WARN_ON_ONCE(!mptcp_try_fallback(sk, MPTCP_MIB_SIMULTCONNFALLBACK));
[Severity: Medium]
Can setting subflow->ssn_offset before checking subflow->request_mptcp
leave an active MP_JOIN subflow with a valid ssn_offset after a crossed
SYN?
An active MP_JOIN subflow enters TCP_SYN_SENT with request_join = 1,
remote_key_valid = 1, and mp_join = 0. If a crossed bare SYN moves it to
TCP_SYN_RECV, mptcp_syn_options() now sets subflow->ssn_offset to the
peer's ISN without falling back or resetting the subflow. When a 3rd ACK
with seq == ssn_offset + 1 arrives in TCP_SYN_RECV,
tcp_rcv_state_process() transitions to TCP_ESTABLISHED without calling
subflow_finish_connect() and enters check_fully_established():
net/mptcp/options.c:check_fully_established() {
...
if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) {
if (subflow->mp_join)
goto reset;
if (subflow->is_mptfo && mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
goto set_fully_established;
return subflow->mp_capable;
}
if (subflow->remote_key_valid &&
(((mp_opt->suboptions & OPTION_MPTCP_DSS) && mp_opt->use_ack) ||
((mp_opt->suboptions & OPTION_MPTCP_ADD_ADDR) &&
(!mp_opt->echo || subflow->mp_join)))) {
goto set_fully_established;
}
...
}
Because seq == subflow->ssn_offset + 1 now matches while mp_join is still
0 and remote_key_valid is 1, an ACK carrying a DSS ACK marks the subflow
fully established without MP_JOIN HMAC validation and triggers
WARN_ON_ONCE(!__mptcp_check_fallback(msk) && !subflow->mp_capable &&
!subflow->mp_join && !(state & TCPF_CLOSE)) in subflow_data_ready() if
data arrives, while a bare ACK attempts TCP fallback on the parent msk
instead of resetting the MP_JOIN subflow.
Moving the subflow->ssn_offset assignment inside the
subflow_simultaneous_connect(sk) block under if (subflow->request_mptcp)
would avoid initializing it on MP_JOIN subflows.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=37
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
@ 2026-11-24 22:52 ` sashiko-bot
0 siblings, 0 replies; 75+ messages in thread
From: sashiko-bot @ 2026-11-24 22:52 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] mptcp: premature TCP_CLOSE and wakeup before
mptcp_close_err() on timeout
- [Medium] mptcp: emulated fallback DATA_FIN on reset causes EPIPE in
mptcp_close_last_err()
- [Medium] mptcp: missing mptcp_check_data_fin_ack() call in
mptcp_check_rcv_close()
- [Medium] mptcp: skipped mptcp_check_rcv_close() in __mptcp_close_ssk()
when ESTABLISHED
--
commit c9c65f9a90b8849493c3af38e75cc7959566f4e9
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
mptcp: report errors as TCP does when closing
This commit updates MPTCP socket closing paths to set SHUTDOWN_MASK and
propagate subflow or state-dependent socket errors when the last subflow
closes or the close timeout expires, matching tcp_done_with_error().
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/648
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 016b16b3cc925..0a7600aea181e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -518,6 +518,56 @@ static void mptcp_close_wake_up(struct sock *sk)
> sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
> }
>
> +/* Mirror the tcp_reset() error propagation */
> +static int mptcp_reset_err(const struct sock *sk)
> +{
> + int err;
> +
> + switch (sk->sk_state) {
> + case TCP_SYN_SENT:
> + err = ECONNREFUSED;
> + break;
> + case TCP_CLOSE_WAIT:
> + err = EPIPE;
> + break;
> + default:
> + err = ECONNRESET;
> + }
> +
> + return err;
> +}
> +
> +/* No more data can be exchanged: report it, as tcp_done_with_error() does */
> +static void mptcp_close_err(struct sock *sk, int err)
> +{
> + WRITE_ONCE(sk->sk_err, err);
> + /* This barrier is coupled with smp_rmb() in mptcp_poll() */
> + smp_wmb();
> + WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
> + mptcp_set_state(sk, TCP_CLOSE);
> + if (sock_flag(sk, SOCK_DEAD))
> + return;
> +
> + mptcp_close_wake_up(sk);
> + sk_error_report(sk);
> +}
> +
> +/* As TCP: the error of the last subflow, e.g. ETIMEDOUT, but after a reset
> + * (EBADMSG: by MPTCP) or without error, it depends on the msk state
> + */
> +static void mptcp_close_last_err(struct sock *sk, int err)
> +{
> + switch (err) {
> + case 0:
> + case ECONNREFUSED:
> + case ECONNRESET:
> + case EPIPE:
> + case EBADMSG:
> + err = mptcp_reset_err(sk);
> + }
> + mptcp_close_err(sk, err);
> +}
[Severity: Medium]
Can mptcp_close_last_err() report EPIPE instead of ECONNRESET when a
fallen-back subflow is reset while mptcp_worker() holds the msk socket
lock?
When msk->first receives a TCP RST in TCP_ESTABLISHED while mptcp_worker()
holds lock_sock(sk), subflow_error_report() defers __mptcp_error_report()
via MPTCP_ERROR_REPORT, and subflow_sched_work_if_closed() sets
msk->rcv_data_fin = 1 and MPTCP_WORK_CLOSE_SUBFLOW because
subflow_is_done(ssk) is true on TCP_CLOSE:
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
/* on fallback, also emulated after a reset: check for a FIN */
if (!__mptcp_check_fallback(msk) ||
(msk->first && sock_flag(msk->first, SOCK_DONE)))
sock_set_flag(sk, SOCK_DONE);
smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
switch (sk->sk_state) {
case TCP_ESTABLISHED:
mptcp_set_state(sk, TCP_CLOSE_WAIT);
break;
...
}
Although mptcp_check_data_fin() avoids setting SOCK_DONE when the fallback
subflow was reset without a FIN, it still advances sk->sk_state from
TCP_ESTABLISHED to TCP_CLOSE_WAIT (or from TCP_FIN_WAIT2 to TCP_CLOSE)
before __mptcp_close_ssk() runs. In __mptcp_close_ssk(), msk->first is
disconnected rather than disposed, so __mptcp_subflow_error_report() is
skipped and mptcp_close_last_err(sk, ECONNRESET) overwrites ECONNRESET
with mptcp_reset_err(sk) (EPIPE in TCP_CLOSE_WAIT) and wakes waiters
before release_sock(sk) runs __mptcp_error_report(). If sk was in
TCP_FIN_WAIT2, mptcp_check_data_fin() moves sk to TCP_CLOSE and wakes
waiters while sk->sk_err is still 0, and __mptcp_close_ssk() then skips
mptcp_close_last_err().
[ ... ]
> @@ -2905,13 +2957,15 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> mptcp_set_close_tout(sk, tcp_jiffies32 -
> (mptcp_close_timeout(sk) + 1));
> mptcp_schedule_work(sk);
> + } else if (sk->sk_state == TCP_CLOSE) {
> + mptcp_close_wake_up(sk);
> } else if (sk->sk_state != TCP_ESTABLISHED ||
> msk->in_accept_queue) {
[Severity: Medium]
Does gating mptcp_check_rcv_close(sk) on sk->sk_state != TCP_ESTABLISHED
miss a pending DATA_FIN in msk->backlog_list (or a pending MP_FASTCLOSE)
when the last subflow closes on an accepted socket?
If the peer sends final data with DATA_FIN and closes or resets the only
subflow while mptcp_worker() holds lock_sock(sk), the incoming data sits
in msk->backlog_list while msk->rcv_data_fin is set, so
mptcp_check_data_fin() in mptcp_worker() cannot advance msk->ack_seq to
msk->rcv_data_fin_seq and leaves sk->sk_state in TCP_ESTABLISHED. When
__mptcp_close_subflow() -> __mptcp_close_ssk() then runs on a non-fallback
socket, it skips this branch and starts the close timeout timer instead of
calling mptcp_check_rcv_close(sk) to spool the backlog, move sk to
TCP_CLOSE_WAIT, and close immediately via mptcp_close_last_err();
mptcp_release_cb() then transitions sk to TCP_CLOSE_WAIT with no subflows
left, leaving the socket to wait for the close timeout and fail with
ETIMEDOUT.
> mptcp_check_rcv_close(sk);
> - mptcp_set_state(sk, TCP_CLOSE);
> - WRITE_ONCE(sk->sk_shutdown,
> - sk->sk_shutdown | SEND_SHUTDOWN);
> - mptcp_close_wake_up(sk);
> + if (sk->sk_state == TCP_CLOSE)
> + mptcp_close_wake_up(sk);
> + else
> + mptcp_close_last_err(sk, ssk_err);
> } else {
> mptcp_start_tout_timer(sk);
> }
[Severity: Medium]
Should mptcp_check_rcv_close(sk) also call mptcp_check_data_fin_ack(sk)
before __mptcp_close_ssk() checks whether sk->sk_state reached TCP_CLOSE?
When an incoming DATA_ACK acknowledges our outgoing DATA_FIN in softirq,
ack_update_msk() updates msk->snd_una and schedules mptcp_worker(), which
is the only caller of mptcp_check_data_fin_ack(sk). If __mptcp_close_ssk()
runs on the last subflow while mptcp_pending_data_fin_ack(sk) is true in
TCP_LAST_ACK, TCP_CLOSING, or TCP_FIN_WAIT1 (for example, during
mptcp_pm_worker() or when the DATA_ACK and subflow close arrive after
mptcp_check_data_fin_ack() in mptcp_worker()), mptcp_check_rcv_close(sk)
only checks rcv_data_fin and rcv_fastclose, leaving sk->sk_state !=
TCP_CLOSE so mptcp_close_last_err() sets ECONNRESET on a cleanly closed
connection.
[ ... ]
> @@ -3441,8 +3485,7 @@ static void mptcp_worker(struct work_struct *work)
> mptcp_do_fastclose(sk);
> mptcp_for_each_subflow_safe(msk, subflow, tmp)
> __mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
> - WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
> - mptcp_close_wake_up(sk);
> + mptcp_close_err(sk, ETIMEDOUT);
> }
[Severity: Medium]
Does calling mptcp_do_fastclose(sk) and __mptcp_close_ssk() before
mptcp_close_err(sk, ETIMEDOUT) wake lockless pollers and SO_ERROR readers
with sk->sk_state == TCP_CLOSE before sk->sk_err and SHUTDOWN_MASK are set?
mptcp_do_fastclose(sk) sets sk->sk_state to TCP_CLOSE while sk->sk_err is
still 0 and sk->sk_shutdown does not have SHUTDOWN_MASK, and
__mptcp_close_ssk() then hits the new sk->sk_state == TCP_CLOSE branch and
calls mptcp_close_wake_up(sk):
kworker CPU1
mptcp_worker()
mptcp_do_fastclose(sk)
mptcp_set_state(sk, TCP_CLOSE)
__mptcp_close_ssk(sk, ...)
mptcp_close_wake_up(sk)
mptcp_poll() / getsockopt(SO_ERROR)
state == TCP_CLOSE
sk_shutdown == 0
sk_err == 0 <-- misses ETIMEDOUT
mptcp_close_err(sk, ETIMEDOUT)
A thread woken from poll() or calling getsockopt(SO_ERROR) before
mptcp_close_err() runs can observe TCP_CLOSE with sk_err == 0 and
sk_shutdown == 0, reporting EPOLLHUP without EPOLLERR, EPOLLIN, or
EPOLLOUT and returning 0 from SO_ERROR instead of ETIMEDOUT.
mptcp_check_fastclose() similarly calls mptcp_set_state(sk, TCP_CLOSE)
before WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK) and without the
smp_wmb() after writing sk->sk_err that mptcp_close_err() uses.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f@kernel.org?part=48
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 00/50] mptcp: misc fixes
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
` (49 preceding siblings ...)
2026-11-24 22:00 ` [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
@ 2026-11-25 0:39 ` MPTCP CI
50 siblings, 0 replies; 75+ messages in thread
From: MPTCP CI @ 2026-11-25 0:39 UTC (permalink / raw)
To: Matthieu Baerts; +Cc: mptcp
Hi Matthieu,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_regressions ⚠️
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): selftest_diag ⚠️
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Unstable: 5 failed test(s): regression:sched-cpu-preempt regression:sched-mem-pressure(5) regression:sched-serverlim(3) validation:sched-loss(3) validation:sched-weak-secondary ⚠️ (56 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/45501866736
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/ecc8ef853125
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1221333
If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normal
For more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
@ 2026-11-25 1:16 ` Mat Martineau
2026-11-25 1:17 ` Mat Martineau
0 siblings, 1 reply; 75+ messages in thread
From: Mat Martineau @ 2026-11-25 1:16 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux
On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
> The close timeout of an orphaned MPTCP socket started at close(), and
> its expiry reset the connection, while some data could still be waiting
> for the peer to open its window: a peer reading slowly or pausing got a
> reset 60 seconds after close(), and lost the end of the data, while TCP
> delivers it.
>
> This timeout is there for the DATA_FIN exchange, see commit d866ae9aaa43
> ("mptcp: add a new sysctl for make after break timeout"), and for an
> orphan that can no longer send anything. So restart it when the DATA_FIN
> is sent, and when it expires before, as long as a subflow can still send
> the data, which is then pushed again: an established subflow, on which
> the peer acked something recently, at least the window probes. Until
> then, as for a TCP socket that is not orphaned, nothing limits how long
> the peer can keep its window closed, while it acks the window probes.
> The timeout still starts at close(): the subflows are not TCP orphans,
> so its expiry is the only check that the orphan can still send.
>
> This was reported on GitHub, with a reproducer: a server writes 2 MB,
> then calls close(), while the client pauses before reading the rest.
> After a pause of 90 seconds, the client got ECONNRESET, while TCP
> delivered everything, as MPTCP now does. If the client vanishes instead,
> the orphan is now reset as TCP does.
>
> Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
> Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/647
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
v2 LGTM:
Reviewed-by: Mat Martineau <martineau@kernel.org>
> ---
> v2: new, for issue #647 reported on GitHub
>
> Note (Clashiko on v2): when the last subflow is closed in the same
> worker run, before the DATA_FIN is sent, the destruction of the orphan
> is delayed once, by the close timeout. Not restarting the timeout once
> expired would reset an orphan sending its DATA_FIN after a long probing.
> ---
> net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index d64e04245963..944c9d11d211 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2871,6 +2871,28 @@ static bool mptcp_close_tout_expired(const struct sock *sk)
> inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
> }
>
> +/* Before its DATA_FIN, keep an orphan while a subflow can send its data */
> +static bool mptcp_orphan_keep(struct sock *sk)
> +{
> + struct mptcp_sock *msk = mptcp_sk(sk);
> + struct mptcp_subflow_context *subflow;
> +
> + if (!sock_flag(sk, SOCK_DEAD) || msk->snd_nxt == msk->write_seq)
> + return false;
> +
> + mptcp_for_each_subflow(msk, subflow) {
> + struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
> +
> + /* a live peer acks at least the probes, every TCP_RTO_MAX */
> + if (__mptcp_subflow_active(subflow) &&
> + tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
> + 2 * TCP_RTO_MAX)
> + return true;
> + }
> +
> + return false;
> +}
> +
> static void mptcp_check_fastclose(struct mptcp_sock *msk)
> {
> struct mptcp_subflow_context *subflow, *tmp;
> @@ -3208,6 +3230,11 @@ static void mptcp_worker(struct work_struct *work)
> if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
> __mptcp_close_subflow(sk);
>
> + if (mptcp_close_tout_expired(sk) && mptcp_orphan_keep(sk)) {
> + mptcp_start_tout_timer(sk);
> + __mptcp_push_pending(sk, 0);
> + }
> +
> if (mptcp_close_tout_expired(sk)) {
> struct mptcp_subflow_context *subflow, *tmp;
>
> @@ -3449,6 +3476,10 @@ static void mptcp_check_send_data_fin(struct sock *sk)
>
> WRITE_ONCE(msk->snd_nxt, msk->write_seq);
>
> + /* an orphan's close timeout is for the DATA_FIN exchange */
> + if (sock_flag(sk, SOCK_DEAD))
> + mptcp_start_tout_timer(sk);
> +
> mptcp_for_each_subflow(msk, subflow) {
> struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
>
>
> --
> 2.55.0
>
>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data
2026-11-25 1:16 ` Mat Martineau
@ 2026-11-25 1:17 ` Mat Martineau
0 siblings, 0 replies; 75+ messages in thread
From: Mat Martineau @ 2026-11-25 1:17 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux
On Tue, 24 Nov 2026, Mat Martineau wrote:
> On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
>
>> The close timeout of an orphaned MPTCP socket started at close(), and
>> its expiry reset the connection, while some data could still be waiting
>> for the peer to open its window: a peer reading slowly or pausing got a
>> reset 60 seconds after close(), and lost the end of the data, while TCP
>> delivers it.
>>
>> This timeout is there for the DATA_FIN exchange, see commit d866ae9aaa43
>> ("mptcp: add a new sysctl for make after break timeout"), and for an
>> orphan that can no longer send anything. So restart it when the DATA_FIN
>> is sent, and when it expires before, as long as a subflow can still send
>> the data, which is then pushed again: an established subflow, on which
>> the peer acked something recently, at least the window probes. Until
>> then, as for a TCP socket that is not orphaned, nothing limits how long
>> the peer can keep its window closed, while it acks the window probes.
>> The timeout still starts at close(): the subflows are not TCP orphans,
>> so its expiry is the only check that the orphan can still send.
>>
>> This was reported on GitHub, with a reproducer: a server writes 2 MB,
>> then calls close(), while the client pauses before reading the rest.
>> After a pause of 90 seconds, the client got ECONNRESET, while TCP
>> delivered everything, as MPTCP now does. If the client vanishes instead,
>> the orphan is now reset as TCP does.
>>
>> Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
>> Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/647
>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>
> v2 LGTM:
(I meant v3...)
>
> Reviewed-by: Mat Martineau <martineau@kernel.org>
>
>> ---
>> v2: new, for issue #647 reported on GitHub
>>
>> Note (Clashiko on v2): when the last subflow is closed in the same
>> worker run, before the DATA_FIN is sent, the destruction of the orphan
>> is delayed once, by the close timeout. Not restarting the timeout once
>> expired would reset an orphan sending its DATA_FIN after a long probing.
>> ---
>> net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
>>
>> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
>> index d64e04245963..944c9d11d211 100644
>> --- a/net/mptcp/protocol.c
>> +++ b/net/mptcp/protocol.c
>> @@ -2871,6 +2871,28 @@ static bool mptcp_close_tout_expired(const struct
>> sock *sk)
>> inet_csk(sk)->icsk_mtup.probe_timestamp +
>> mptcp_close_timeout(sk));
>> }
>>
>> +/* Before its DATA_FIN, keep an orphan while a subflow can send its data
>> */
>> +static bool mptcp_orphan_keep(struct sock *sk)
>> +{
>> + struct mptcp_sock *msk = mptcp_sk(sk);
>> + struct mptcp_subflow_context *subflow;
>> +
>> + if (!sock_flag(sk, SOCK_DEAD) || msk->snd_nxt == msk->write_seq)
>> + return false;
>> +
>> + mptcp_for_each_subflow(msk, subflow) {
>> + struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
>> +
>> + /* a live peer acks at least the probes, every TCP_RTO_MAX */
>> + if (__mptcp_subflow_active(subflow) &&
>> + tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
>> + 2 * TCP_RTO_MAX)
>> + return true;
>> + }
>> +
>> + return false;
>> +}
>> +
>> static void mptcp_check_fastclose(struct mptcp_sock *msk)
>> {
>> struct mptcp_subflow_context *subflow, *tmp;
>> @@ -3208,6 +3230,11 @@ static void mptcp_worker(struct work_struct *work)
>> if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
>> __mptcp_close_subflow(sk);
>>
>> + if (mptcp_close_tout_expired(sk) && mptcp_orphan_keep(sk)) {
>> + mptcp_start_tout_timer(sk);
>> + __mptcp_push_pending(sk, 0);
>> + }
>> +
>> if (mptcp_close_tout_expired(sk)) {
>> struct mptcp_subflow_context *subflow, *tmp;
>>
>> @@ -3449,6 +3476,10 @@ static void mptcp_check_send_data_fin(struct sock
>> *sk)
>>
>> WRITE_ONCE(msk->snd_nxt, msk->write_seq);
>>
>> + /* an orphan's close timeout is for the DATA_FIN exchange */
>> + if (sock_flag(sk, SOCK_DEAD))
>> + mptcp_start_tout_timer(sk);
>> +
>> mptcp_for_each_subflow(msk, subflow) {
>> struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
>>
>>
>> --
>> 2.55.0
>>
>>
>>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window
2026-11-24 21:59 ` [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
@ 2026-11-25 1:19 ` Mat Martineau
0 siblings, 0 replies; 75+ messages in thread
From: Mat Martineau @ 2026-11-25 1:19 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux
On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
> Since the previous commit, an orphan with data to send is kept while
> the peer acks something, at least the window probes: a peer keeping its
> window closed, e.g. not reading, could then keep the orphan forever.
>
> TCP limits this for its orphans: tcp_probe_timer() aborts them instead
> of probing again after the max interval. The subflows of an MPTCP orphan
> are not orphaned: they probe again then, and back off once more, up to
> tcp_retries2. So check if TCP would have aborted them, when the close
> timeout expires. Same with data in flight, when the peer has shrunk its
> window to zero: tcp_retransmit_timer() only aborts orphans then.
>
> Two corner cases needing non-default settings are not covered, which is
> fine: an idle subflow refreshed by keepalives still keeps the orphan
> when the stale detection is disabled, and tcp_orphan_retries is ignored.
>
> This was found by an AI code review agent, while reviewing the previous
> commit. With its reproducer and a long pause, the orphan was kept until
> the end of the pause. It is now reset as TCP does, respecting
> tcp_retries2.
>
> Note for the backports: this patch is needed with the previous one, and
> before v6.15, tcp_rto_max() can be replaced by TCP_RTO_MAX.
>
> Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Mat Martineau <martineau@kernel.org>
> ---
> v2: new, to limit the orphans kept by the previous patch, with the same
> Fixes tag to backport them together.
>
> Note (Clashiko on v2): a peer acking the data at the TCP level only
> keeps the orphan, but this is bounded by tcp_max_orphans and tcp_mem
> since the next patch. With the stale detection, the probing subflow is
> marked as stale, and its data is moved to the idle one.
> ---
> net/mptcp/protocol.c | 29 ++++++++++++++++++++++++++++-
> 1 file changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 944c9d11d211..ff71f1954077 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2871,6 +2871,32 @@ static bool mptcp_close_tout_expired(const struct sock *sk)
> inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
> }
>
> +/* Would TCP abort this subflow if it were an orphan probing a zero window? */
> +static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
> +{
> + u8 retries2 = READ_ONCE(sock_net(ssk)->ipv4.sysctl_tcp_retries2);
> + struct inet_connection_sock *icsk = inet_csk(ssk);
> + const struct tcp_sock *tp = tcp_sk(ssk);
> + unsigned long limit;
> + bool slow, ret;
> + u64 when;
> +
> + slow = lock_sock_fast_nested(ssk);
> + limit = tcp_rto_max(ssk);
> + if (tp->packets_out) {
> + ret = !tp->snd_wnd && icsk->icsk_rto >= limit;
> + } else {
> + if (icsk->icsk_backoff < retries2)
> + limit *= 2;
> + /* a shift of 32 already exceeds the limit */
> + when = (u64)icsk->icsk_rto << min_t(u8, icsk->icsk_backoff, 32);
> + ret = tcp_send_head(ssk) && when >= limit;
> + }
> + unlock_sock_fast(ssk, slow);
> +
> + return ret;
> +}
> +
> /* Before its DATA_FIN, keep an orphan while a subflow can send its data */
> static bool mptcp_orphan_keep(struct sock *sk)
> {
> @@ -2886,7 +2912,8 @@ static bool mptcp_orphan_keep(struct sock *sk)
> /* a live peer acks at least the probes, every TCP_RTO_MAX */
> if (__mptcp_subflow_active(subflow) &&
> tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
> - 2 * TCP_RTO_MAX)
> + 2 * TCP_RTO_MAX &&
> + !mptcp_subflow_probe_timed_out(ssk))
> return true;
> }
>
>
> --
> 2.55.0
>
>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does
2026-11-24 21:59 ` [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
@ 2026-11-25 1:21 ` Mat Martineau
0 siblings, 0 replies; 75+ messages in thread
From: Mat Martineau @ 2026-11-25 1:21 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux
On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
> The MPTCP sockets orphaned by close() were not counted in
> tcp_orphan_count, contrary to TCP: tcp_max_orphans did not limit them,
> and they were not visible in /proc/net/sockstat.
>
> This is all the more needed since commit "mptcp: keep an orphan while it
> can send its data": an orphan can then be kept longer than its close
> timeout, e.g., as Sashiko noticed, by a peer acking the data at the TCP
> level only, without moving the DATA_ACK.
>
> Count them, and as TCP does, reset an orphan when there are too many
> orphans, or when TCP uses too much memory: at close(), and when its
> close timeout expires while it is kept to send its data. This is similar
> to what tcp_out_of_resources() does from the TCP timers, without the
> stricter limit for the stalled orphans. These resets are counted in
> TCPAbortOnMemory, not in a new MPTCP counter: the MPTCP orphans now
> share the TCP orphan count and limits.
>
> This has been found by a review agent, and validated with a script
> closing 8 connections whose peer doesn't read, with tcp_max_orphans set
> to 4: the MPTCP orphans were all kept, without being counted, while
> other orphans were reset. Now, only 5 or 6 are kept, vs 4 or 5 with TCP,
> which also checks the limit from the timers of its orphans.
>
> Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Mat Martineau <martineau@kernel.org>
> ---
> v2: new, spotted by a review agent
>
> Note (Clashiko on v2): the reset reason stays TCP_ABORT_ON_CLOSE, as for
> the other fastclose resets: only the tracepoint is affected.
> ---
> net/mptcp/protocol.c | 24 ++++++++++++++++++++++--
> net/mptcp/protocol.h | 1 +
> 2 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index ff71f1954077..9e297fa08bfe 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2897,6 +2897,16 @@ static bool mptcp_subflow_probe_timed_out(struct sock *ssk)
> return ret;
> }
>
> +/* As TCP orphans: limited in number and memory */
> +static bool mptcp_orphan_oom(struct sock *sk)
> +{
> + if (!tcp_check_oom(sk, 0))
> + return false;
> +
> + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
> + return true;
> +}
> +
> /* Before its DATA_FIN, keep an orphan while a subflow can send its data */
> static bool mptcp_orphan_keep(struct sock *sk)
> {
> @@ -2914,7 +2924,7 @@ static bool mptcp_orphan_keep(struct sock *sk)
> tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
> 2 * TCP_RTO_MAX &&
> !mptcp_subflow_probe_timed_out(ssk))
> - return true;
> + return !mptcp_orphan_oom(sk);
> }
>
> return false;
> @@ -3547,6 +3557,9 @@ static void __mptcp_destroy_sock(struct sock *sk)
> sk_stream_kill_queues(sk);
> xfrm_sk_free_policy(sk);
>
> + if (test_and_clear_bit(MPTCP_ORPHAN_COUNTED, &msk->flags))
> + tcp_orphan_count_dec();
> +
> sock_put(sk);
> }
>
> @@ -3636,8 +3649,15 @@ bool __mptcp_close(struct sock *sk, long timeout)
> /* all the subflows are closed, only timeout can change the msk
> * state, let's not keep resources busy for no reasons
> */
> - if (subflows_alive == 0)
> + if (subflows_alive == 0) {
> mptcp_set_state(sk, TCP_CLOSE);
> + } else if (sk->sk_state != TCP_CLOSE) {
> + /* as TCP orphans: counted, and limited */
> + tcp_orphan_count_inc();
> + set_bit(MPTCP_ORPHAN_COUNTED, &msk->flags);
> + if (mptcp_orphan_oom(sk))
> + mptcp_do_fastclose(sk);
> + }
>
> sock_hold(sk);
> pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index 2c9a442dacd6..888ee9d66967 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -117,6 +117,7 @@
> #define MPTCP_FALLBACK_DONE 2
> #define MPTCP_WORK_CLOSE_SUBFLOW 3
> #define MPTCP_RTX_ENABLED 4
> +#define MPTCP_ORPHAN_COUNTED 5
>
> /* MPTCP socket release cb flags */
> #define MPTCP_PUSH_PENDING 1
>
> --
> 2.55.0
>
>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does
2026-11-24 21:59 ` [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
@ 2026-11-26 1:57 ` Mat Martineau
2026-11-26 2:59 ` Geliang Tang
0 siblings, 1 reply; 75+ messages in thread
From: Mat Martineau @ 2026-11-26 1:57 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux
On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
> Once an MPTCP socket has received a DATA_FIN, recv() returns the
> remaining data, then EOF. But if the connection was then reset, e.g. by
> an MP_FASTCLOSE, recv() returned an error after the data, e.g. EPIPE,
> instead of EOF as TCP does. A proxy resetting the other connection on
> read errors then dropped the data it still had to forward.
>
> As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and
> check it before the socket error in recvmsg(). With an MP_FASTCLOSE, the
> data still in the backlog is moved first, not to miss the DATA_FIN.
> After a fallback, a DATA_FIN is also emulated after a reset: only set
> SOCK_DONE after a FIN, not to hide a reset behind an EOF. This FIN is
> cleared when the first subflow is disconnected: process this DATA_FIN
> before.
>
> This was reported on GitHub, and is validated with new Packetdrill
> tests: data and a DATA_FIN are received, then an MP_FASTCLOSE; and
> after a fallback, data, a FIN and a reset. Without this patch, the
> second read() returned EPIPE in both cases:
>
> receive_fastclose_after_data_fin.pkt:27: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
> v1_connect_tcpfallback_fin_reset.pkt:19: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
>
> Note for the backports: the issue with an MP_FASTCLOSE comes from commit
> 69800e516e96 ("mptcp: propagate fastclose error"), in v6.1. Before that,
> the modifications in mptcp_check_fastclose() and mptcp_disconnect() are
> not needed.
>
> Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
> Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Mat Martineau <martineau@kernel.org>
> ---
> v2: new, for issue #647 reported on GitHub
> v3: process the DATA_FIN before disconnecting the first subflow, which
> clears its FIN (Clashiko)
>
> Note (Clashiko on v2): with a DATA_FIN, then an MP_FASTCLOSE in
> FIN_WAIT2, the reset subflows are only released at close(): not a leak.
> A DATA_FIN mapped on another CPU while an MP_FASTCLOSE is processed can
> still lead to ECONNRESET: two subflows racing, and the connection reset
> by the peer anyway.
> ---
> net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++--
> 1 file changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 9e297fa08bfe..de6da0b6c4ca 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -714,6 +714,10 @@ static void mptcp_check_data_fin(struct sock *sk)
> WRITE_ONCE(msk->rcv_data_fin, 0);
>
> WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
> + /* on fallback, also emulated after a reset: check for a FIN */
> + if (!__mptcp_check_fallback(msk) ||
> + (msk->first && sock_flag(msk->first, SOCK_DONE)))
> + sock_set_flag(sk, SOCK_DONE);
> smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
>
> switch (sk->sk_state) {
> @@ -972,6 +976,9 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
> * destroy the msk as needed.
> */
> ssk_state = inet_sk_state_load(ssk);
> + /* a FIN received before still leads to EOF, as with TCP */
> + if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
> + sock_set_flag(sk, SOCK_DONE);
> if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
> mptcp_set_state(sk, ssk_state);
> WRITE_ONCE(sk->sk_err, -err);
> @@ -2494,6 +2501,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
> !timeo)
> break;
> } else {
> + if (sock_flag(sk, SOCK_DONE))
> + break;
> +
> copied = sock_error(sk);
> if (copied)
> break;
> @@ -2813,6 +2823,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> struct mptcp_subflow_context *subflow)
> {
> + struct mptcp_sock *msk = mptcp_sk(sk);
> +
> /* The first subflow can already be closed or disconnected */
> if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
> return;
> @@ -2820,12 +2832,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> subflow->close_event_done = true;
>
> if (sk->sk_state == TCP_ESTABLISHED)
> - mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
> + mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
>
> /* subflow aborted before reaching the fully_established status
> * attempt the creation of the next subflow
> */
> - mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
> + mptcp_pm_subflow_check_next(msk, subflow);
> +
> + /* On fallback, the FIN of the first subflow is cleared when it is
> + * disconnected: process the DATA_FIN emulated from it before.
> + */
> + if (ssk == msk->first && __mptcp_check_fallback(msk) &&
> + READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
> + mptcp_move_skbs(sk);
> + mptcp_check_data_fin(sk);
> + }
>
> __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
> }
> @@ -2938,6 +2959,11 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
> if (likely(!READ_ONCE(msk->rcv_fastclose)))
> return;
>
> + /* a DATA_FIN received before still leads to EOF, as with TCP */
> + if (READ_ONCE(msk->rcv_data_fin))
> + mptcp_move_skbs(sk);
> + mptcp_check_data_fin(sk);
> +
> mptcp_token_destroy(msk);
>
> mptcp_for_each_subflow_safe(msk, subflow, tmp) {
> @@ -3797,6 +3823,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
> atomic64_set(&msk->rcv_wnd_sent, 0);
>
> WRITE_ONCE(sk->sk_shutdown, 0);
> + sock_reset_flag(sk, SOCK_DONE);
> sk_error_report(sk);
> return 0;
> }
>
> --
> 2.55.0
>
>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept()
2026-11-24 21:59 ` [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
@ 2026-11-26 2:20 ` Mat Martineau
0 siblings, 0 replies; 75+ messages in thread
From: Mat Martineau @ 2026-11-26 2:20 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux, Chris Mason
On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
> From: Chris Mason <mason@kernel.org>
>
> accept() of an MPTCP connection that has already received data can leak
> one page of memory cgroup charge, and the leaked charges can get the
> server OOM killed.
>
> At accept(), __inet_accept() charges the MPTCP socket (msk) for the
> memory that it holds, rounded up to whole pages, and
> mptcp_graft_subflows() does the same for each subflow. A page is
> uncharged only once, when the socket that holds it releases it, so
> rounding up each socket on its own is only correct while each page
> belongs to one socket. But for each skb that the msk takes over from a
> subflow, it borrows skb->truesize bytes from the pages that the subflow
> reserved, so the two can share a page:
>
> reserved by the subflow 4096 bytes 1 page
> now held by the msk 896 bytes charged for 1 page
> still held by the subflow 3200 bytes charged for 1 page
>
> The fix used here is to keep a running sum of what the msk and its
> subflows hold, and to let the new mptcp_charge_subflow() charge each
> subflow only for the pages that it adds to the rounded-up sum.
>
> This issue has been found with the help of an LLM, and reproduced in a
> VM, with the reproducer shared with the original version of this patch:
> an MPTCP server in a memory cgroup, the first byte of the client
> arriving before accept(). Without this patch, 4096 bytes stayed charged
> to the memory cgroup for each connection, after its end:
>
> SNAP label=after-1000 rounds=1000 sockets_left_in_srv=0 [...] c_sock=4096000 [...]
> SNAP label=after-5000 rounds=5000 sockets_left_in_srv=0 [...] c_sock=20480000 [...]
>
> With a memory limit, the original version of this patch reported that
> the server was killed by the OOM killer after about 14,400 connections.
>
> Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow")
> Signed-off-by: Chris Mason <mason@kernel.org>
> [ Shorter comment. Commit message: how the issue was found, and its
> symptoms. ]
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> Note (Clashiko on v2): the backlog can still be charged twice here: this
> is fixed by the next patch.
> ---
> net/mptcp/protocol.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index f8cb585da0b3..504fe4a9954f 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -4664,10 +4664,26 @@ static int mptcp_listen(struct socket *sock, int backlog)
> return err;
> }
>
> +/* The msk and its subflows share pages: charge their rounded-up sum */
I suggest adding a note that this is similar to __sk_charge() (to make it
easier keep the two functions consistent if either has future changes).
But otherwise the patch looks good.
Reviewed-by: Mat Martineau <martineau@kernel.org>
> +static int mptcp_charge_subflow(struct sock *sk, struct sock *ssk, int mem)
> +{
> + int new_mem = mem + ssk->sk_forward_alloc +
> + atomic_read(&ssk->sk_rmem_alloc);
> + int amt = sk_mem_pages(new_mem) - sk_mem_pages(mem);
> + gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
> +
> + mem_cgroup_sk_inherit(sk, ssk);
> + if (amt > 0)
> + mem_cgroup_sk_charge(ssk, amt, gfp);
> + kmem_cache_charge(ssk, gfp);
> + return new_mem;
> +}
> +
> static void mptcp_graft_subflows(struct sock *sk)
> {
> struct mptcp_subflow_context *subflow;
> struct mptcp_sock *msk = mptcp_sk(sk);
> + int mem;
>
> if (mem_cgroup_sockets_enabled) {
> LIST_HEAD(join_list);
> @@ -4685,6 +4701,9 @@ static void mptcp_graft_subflows(struct sock *sk)
> __mptcp_flush_join_list(sk, &join_list);
> }
>
> + /* What __inet_accept() just charged for the msk, before rounding up. */
> + mem = sk->sk_forward_alloc + atomic_read(&sk->sk_rmem_alloc);
> +
> mptcp_for_each_subflow(msk, subflow) {
> struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
>
> @@ -4700,7 +4719,7 @@ static void mptcp_graft_subflows(struct sock *sk)
> goto unlock;
>
> __mptcp_inherit_cgrp_data(sk, ssk);
> - __mptcp_inherit_memcg(sk, ssk, GFP_KERNEL);
> + mem = mptcp_charge_subflow(sk, ssk, mem);
>
> unlock:
> release_sock(ssk);
>
> --
> 2.55.0
>
>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog twice at accept()
2026-11-24 21:59 ` [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
@ 2026-11-26 2:43 ` Mat Martineau
0 siblings, 0 replies; 75+ messages in thread
From: Mat Martineau @ 2026-11-26 2:43 UTC (permalink / raw)
To: Matthieu Baerts (NGI0); +Cc: MPTCP Linux, Chris Mason
On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
> From: Chris Mason <mason@kernel.org>
>
> accept() can permanently overcharge the memory cgroup of an MPTCP
> server, so the server can be OOM killed, if the new connection received
> data while its MPTCP socket was locked.
>
> The sockets of an MPTCP connection have no memory cgroup before
> accept(), which then charges the sk_forward_alloc and the sk_rmem_alloc
> of the MPTCP socket (msk) and of each subflow. mptcp_graft_subflows()
> also charges msk->backlog_unaccounted: the truesize of the skbs that
> __mptcp_add_backlog() queued while the socket lock of the msk was held
> and their subflow had no memory cgroup. But the first charge already
> covers each of these skbs that has not been freed, in the sk_rmem_alloc
> of its subflow or of the msk, so no later uncharge matches the extra
> charge.
>
> The fix used here is to remove msk->backlog_unaccounted, its charge in
> mptcp_graft_subflows() and the warning that tests it in
> mptcp_can_spool_backlog(). An RFC patch [1] removes the same lines, as
> part of another approach.
>
> This issue has been found with the help of an LLM, and reproduced in a
> VM, with the reproducer shared with the original version of this patch,
> on a kernel with the previous patch: 100,000 connections to an MPTCP
> server in a memory cgroup. Without this patch, about 63 MB stayed
> charged to this memory cgroup once all the connections were closed, and
> to its parent after its removal:
>
> SNAP label=after-100000 rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 [...] c_sock=63295488 [...]
> [...]
> SNAP label=c-removed rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 c=removed [...] p_sock=63295488 [...]
>
> And about 12 MB with only 50 connections, each getting 20,000 duplicates
> of a byte before accept(), beside bare ACKs with RM_ADDR, which make the
> MPTCP worker take the socket lock:
What does "20,000 duplicates of a byte" mean? Just that each connection
received 20kbytes before accept? If the test case happens to use the same
byte value for every data byte in the payload, that's superfluous
information.
Other than that, the patch LGTM.
Reviewed-by: Mat Martineau <martineau@kernel.org>
>
> SNAP label=after-50 rounds=50 sockets_left_in_srv=0 tcp_mem_pages=256 [...] c_sock=12881920 [...]
>
> Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
> Link: https://lore.kernel.org/all/20260924080219.1036588-4-caixinchen1@huawei.com/ [1]
> Signed-off-by: Chris Mason <mason@kernel.org>
> [ No comment change: the commit message explains why the backlog is
> covered. Commit message: refer to the RFC [1] removing the same lines
> + how the issue was found, and its symptoms. ]
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> net/mptcp/protocol.c | 35 +----------------------------------
> net/mptcp/protocol.h | 1 -
> 2 files changed, 1 insertion(+), 35 deletions(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 504fe4a9954f..c9ef23276399 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -802,12 +802,6 @@ static void __mptcp_add_backlog(struct sock *sk,
>
> account:
> WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
> -
> - /* Possibly not accept()ed yet, keep track of memory not CG
> - * accounted, mptcp_graft_subflows() will handle it.
> - */
> - if (!mem_cgroup_from_sk(ssk))
> - msk->backlog_unaccounted += delta;
> }
>
> static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
> @@ -2456,12 +2450,6 @@ static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
> {
> struct mptcp_sock *msk = mptcp_sk(sk);
>
> - /* After CG initialization, subflows should never add skb before
> - * gaining the CG themself.
> - */
> - DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket &&
> - mem_cgroup_from_sk(sk));
> -
> if (list_empty(&msk->backlog_list))
> return false;
>
> @@ -4691,8 +4679,7 @@ static void mptcp_graft_subflows(struct sock *sk)
> /* Subflows joining after __inet_accept() will get the
> * mem CG properly initialized at mptcp_finish_join() time,
> * but subflows pending in join_list need explicit
> - * initialization before flushing `backlog_unaccounted`
> - * or MPTCP can later unexpectedly observe unaccounted memory.
> + * initialization by the loop below.
> */
> mptcp_data_lock(sk);
> list_splice_init(&msk->join_list, &join_list);
> @@ -4724,26 +4711,6 @@ static void mptcp_graft_subflows(struct sock *sk)
> unlock:
> release_sock(ssk);
> }
> -
> - if (mem_cgroup_sk_enabled(sk)) {
> - gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
> - int amt;
> -
> - /* Account the backlog memory; prior accept() is aware of
> - * fwd and rmem only.
> - */
> - mptcp_data_lock(sk);
> - amt = sk_mem_pages(sk->sk_forward_alloc +
> - msk->backlog_unaccounted +
> - atomic_read(&sk->sk_rmem_alloc)) -
> - sk_mem_pages(sk->sk_forward_alloc +
> - atomic_read(&sk->sk_rmem_alloc));
> - msk->backlog_unaccounted = 0;
> - mptcp_data_unlock(sk);
> -
> - if (amt)
> - mem_cgroup_sk_charge(sk, amt, gfp);
> - }
> }
>
> static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index d0ae782c9ade..9a9dbab672af 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -394,7 +394,6 @@ struct mptcp_sock {
>
> struct list_head backlog_list; /* protected by the data lock */
> u32 backlog_len;
> - u32 backlog_unaccounted;
> };
>
> #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
>
> --
> 2.55.0
>
>
>
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does
2026-11-26 1:57 ` Mat Martineau
@ 2026-11-26 2:59 ` Geliang Tang
2026-11-26 8:06 ` Matthieu Baerts
0 siblings, 1 reply; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 2:59 UTC (permalink / raw)
To: Mat Martineau, Matthieu Baerts (NGI0); +Cc: MPTCP Linux
Hi Matt, Mat,
On Wed, 2026-11-25 at 17:57 -0800, Mat Martineau wrote:
> On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
>
> > Once an MPTCP socket has received a DATA_FIN, recv() returns the
> > remaining data, then EOF. But if the connection was then reset, e.g. by
> > an MP_FASTCLOSE, recv() returned an error after the data, e.g. EPIPE,
> > instead of EOF as TCP does. A proxy resetting the other connection on
> > read errors then dropped the data it still had to forward.
> >
> > As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and
> > check it before the socket error in recvmsg(). With an MP_FASTCLOSE, the
> > data still in the backlog is moved first, not to miss the DATA_FIN.
> > After a fallback, a DATA_FIN is also emulated after a reset: only set
> > SOCK_DONE after a FIN, not to hide a reset behind an EOF. This FIN is
> > cleared when the first subflow is disconnected: process this DATA_FIN
> > before.
> >
> > This was reported on GitHub, and is validated with new Packetdrill
> > tests: data and a DATA_FIN are received, then an MP_FASTCLOSE; and
> > after a fallback, data, a FIN and a reset. Without this patch, the
> > second read() returned EPIPE in both cases:
> >
> > receive_fastclose_after_data_fin.pkt:27: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
> > v1_connect_tcpfallback_fin_reset.pkt:19: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
> >
> > Note for the backports: the issue with an MP_FASTCLOSE comes from commit
> > 69800e516e96 ("mptcp: propagate fastclose error"), in v6.1. Before that,
> > the modifications in mptcp_check_fastclose() and mptcp_disconnect() are
> > not needed.
> >
> > Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
> > Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
> > Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>
> Reviewed-by: Mat Martineau <martineau@kernel.org>
Thanks for adding this SOCK_DONE patch; it is very helpful for my work on
modifying mptcp_inq_hint(). mptcp_inq_hint() should check SOCK_DONE, just like
tcp_inq_hint() does.
Acked-by: Geliang Tang <geliang@kernel.org>
I'm wondering whether this patch should come before patch 1, because patch 1
checks SOCK_DONE, but SOCK_DONE isn't set at that point.
Thanks,
-Geliang
>
> > ---
> > v2: new, for issue #647 reported on GitHub
> > v3: process the DATA_FIN before disconnecting the first subflow, which
> > clears its FIN (Clashiko)
> >
> > Note (Clashiko on v2): with a DATA_FIN, then an MP_FASTCLOSE in
> > FIN_WAIT2, the reset subflows are only released at close(): not a leak.
> > A DATA_FIN mapped on another CPU while an MP_FASTCLOSE is processed can
> > still lead to ECONNRESET: two subflows racing, and the connection reset
> > by the peer anyway.
> > ---
> > net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++--
> > 1 file changed, 29 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> > index 9e297fa08bfe..de6da0b6c4ca 100644
> > --- a/net/mptcp/protocol.c
> > +++ b/net/mptcp/protocol.c
> > @@ -714,6 +714,10 @@ static void mptcp_check_data_fin(struct sock *sk)
> > WRITE_ONCE(msk->rcv_data_fin, 0);
> >
> > WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
> > + /* on fallback, also emulated after a reset: check for a FIN */
> > + if (!__mptcp_check_fallback(msk) ||
> > + (msk->first && sock_flag(msk->first, SOCK_DONE)))
> > + sock_set_flag(sk, SOCK_DONE);
> > smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
> >
> > switch (sk->sk_state) {
> > @@ -972,6 +976,9 @@ static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
> > * destroy the msk as needed.
> > */
> > ssk_state = inet_sk_state_load(ssk);
> > + /* a FIN received before still leads to EOF, as with TCP */
> > + if (sock_flag(ssk, SOCK_DONE) && mptcp_pending_data_fin(sk, NULL))
> > + sock_set_flag(sk, SOCK_DONE);
> > if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
> > mptcp_set_state(sk, ssk_state);
> > WRITE_ONCE(sk->sk_err, -err);
> > @@ -2494,6 +2501,9 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
> > !timeo)
> > break;
> > } else {
> > + if (sock_flag(sk, SOCK_DONE))
> > + break;
> > +
> > copied = sock_error(sk);
> > if (copied)
> > break;
> > @@ -2813,6 +2823,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> > void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> > struct mptcp_subflow_context *subflow)
> > {
> > + struct mptcp_sock *msk = mptcp_sk(sk);
> > +
> > /* The first subflow can already be closed or disconnected */
> > if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
> > return;
> > @@ -2820,12 +2832,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
> > subflow->close_event_done = true;
> >
> > if (sk->sk_state == TCP_ESTABLISHED)
> > - mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
> > + mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
> >
> > /* subflow aborted before reaching the fully_established status
> > * attempt the creation of the next subflow
> > */
> > - mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
> > + mptcp_pm_subflow_check_next(msk, subflow);
> > +
> > + /* On fallback, the FIN of the first subflow is cleared when it is
> > + * disconnected: process the DATA_FIN emulated from it before.
> > + */
> > + if (ssk == msk->first && __mptcp_check_fallback(msk) &&
> > + READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
> > + mptcp_move_skbs(sk);
> > + mptcp_check_data_fin(sk);
> > + }
> >
> > __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
> > }
> > @@ -2938,6 +2959,11 @@ static void mptcp_check_fastclose(struct mptcp_sock *msk)
> > if (likely(!READ_ONCE(msk->rcv_fastclose)))
> > return;
> >
> > + /* a DATA_FIN received before still leads to EOF, as with TCP */
> > + if (READ_ONCE(msk->rcv_data_fin))
> > + mptcp_move_skbs(sk);
> > + mptcp_check_data_fin(sk);
> > +
> > mptcp_token_destroy(msk);
> >
> > mptcp_for_each_subflow_safe(msk, subflow, tmp) {
> > @@ -3797,6 +3823,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
> > atomic64_set(&msk->rcv_wnd_sent, 0);
> >
> > WRITE_ONCE(sk->sk_shutdown, 0);
> > + sock_reset_flag(sk, SOCK_DONE);
> > sk_error_report(sk);
> > return 0;
> > }
> >
> > --
> > 2.55.0
> >
> >
> >
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does
2026-11-24 21:59 ` [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
@ 2026-11-26 6:40 ` Geliang Tang
2026-11-26 8:15 ` Matthieu Baerts
0 siblings, 1 reply; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 6:40 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Hi Matt,
On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
> After a disconnect with connect(AF_UNSPEC), an error from the previous
> connection, e.g. a reset not reported yet to the application, was still
> reported for the next connection, by poll(), SO_ERROR, and the first
> send() or recv(). TCP clears it in tcp_connect_init(): do the same,
> once the subflow connect() succeeded, so an early failure keeps it.
>
> This issue has been found by an AI code review agent, while reviewing
> other fixes, and confirmed with a reproducer: the peer resets the
> connection, the error is not read, then the socket is disconnected and
> connected again. SO_ERROR then reported ECONNRESET each time, while TCP
> reported no error, as MPTCP now does.
>
> Fixes: 3d1d6d66e156 ("mptcp: implement support for user-space disconnect")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Thanks for this fix. Looks good to me!
Reviewed-by: Geliang Tang <geliang@kernel.org>
> ---
> v2: new, for an issue found by a review agent
> ---
> net/mptcp/protocol.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index ff1dcf306723..6328815ad273 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -4452,6 +4452,8 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
> if (err < 0)
> goto out;
>
> + /* as tcp_connect_init(): drop an error from a previous connection */
> + WRITE_ONCE(sk->sk_err, 0);
tcp_connect_init() also calls sock_reset_flag(sk, SOCK_DONE) here; maybe MPTCP
needs this sock_reset_flag(sk, SOCK_DONE) too.
Thanks,
-Geliang
> inet_assign_bit(DEFER_CONNECT, sk, inet_test_bit(DEFER_CONNECT, ssk));
>
> out:
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect
2026-11-24 21:59 ` [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
@ 2026-11-26 6:41 ` Geliang Tang
0 siblings, 0 replies; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 6:41 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Hi Matt,
On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
> With TCP_FASTOPEN_CONNECT, mptcp_connect() copies the DEFER_CONNECT bit
> of the first subflow to the msk. This bit is cleared on the first
> write(), but not when the msk is disconnected, e.g. with
> connect(AF_UNSPEC) before any write().
>
> tcp_disconnect() clears this bit on the subflow, but mptcp_disconnect()
> leaves it set on the msk. The next write() then goes through
> mptcp_sendmsg_fastopen(), and tries to connect the msk again with a NULL
> address: mptcp_connect() moves the msk back to SYN_SENT, possibly
> allocates a token and increments the MPCapableActive counter, before the
> subflow connect() fails. -EINVAL is then returned, instead of -EPIPE.
> The stale bit is also reported by the diag interface.
>
> Clear DEFER_CONNECT in mptcp_disconnect(), like tcp_disconnect() does.
>
> This issue has been found by an AI code review agent, while fixing a
> similar issue, and confirmed with a new Packetdrill test: a deferred
> connect, then connect(AF_UNSPEC), then send(). Without this patch,
> send() failed with EINVAL:
>
> client-TCP_FASTOPEN_CONNECT-disconnect.pkt:35: runtime error in send call: Expected errno 32 (Broken pipe) but got 22 (Invalid argument)
>
> Fixes: a42cf9d18278 ("mptcp: poll allow write call before actual connect")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Looks good to me, thanks.
Reviewed-by: Geliang Tang <geliang@kernel.org>
> ---
> v2: new, for an issue found by a review agent
> ---
> net/mptcp/protocol.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 6328815ad273..257c851c8a76 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -3828,6 +3828,7 @@ static int mptcp_disconnect(struct sock *sk, int flags)
>
> mptcp_check_listen_stop(sk);
> mptcp_set_state(sk, TCP_CLOSE);
> + inet_clear_bit(DEFER_CONNECT, sk);
>
> /* The later subflow close can not kick again the tout timer,
> * as the msk is already in closed status.
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows
2026-11-24 21:59 ` [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
@ 2026-11-26 7:04 ` Geliang Tang
2026-11-26 7:35 ` Matthieu Baerts
0 siblings, 1 reply; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 7:04 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Hi Matt,
On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
> mptcp_do_fastclose() sends a reset with an MP_FASTCLOSE on each subflow
> not in LISTEN or CLOSE, also on the ones in SYN_SENT, while TCP sends no
> reset in this state, see tcp_need_reset() used by tcp_disconnect(). On a
> disconnect in SYN_SENT, e.g. with connect(AF_UNSPEC), an MPTCP client
> then sends a reset with an MP_FASTCLOSE carrying an unknown key, 0. With
> TCP_FASTOPEN_CONNECT, this reset is even sent before any SYN.
>
> Before the commit below, these resets were sent by tcp_disconnect(), so
> not in SYN_SENT. Skip them again in this state, as TCP does, but move
> the subflow to TCP_CLOSE at once, as tcp_disconnect() does: a SYN-ACK
> received before the end of the close cannot complete the connection, and
> a later one gets a reset from the stack.
>
> This issue has been found by an AI code review agent, while reviewing
> "mptcp: clear DEFER_CONNECT on disconnect", and confirmed with a new
> Packetdrill test: a disconnect in SYN_SENT, then the SYN-ACK. Without
> this patch, a reset with MPTCP options was sent at the disconnect,
> before the one replying to the SYN-ACK:
>
> disconnect_in_syn_sent.pkt:16: error handling packet: live packet field ipv4_total_length: expected: 40 (0x28) vs actual: 56 (0x38)
>
> Fixes: ae155060247b ("mptcp: fix duplicate reset on fastclose")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> v2: new, for an issue found by a review agent
> v3: move the subflow to TCP_CLOSE at once, not to complete the
> connection with a SYN-ACK received in between (Clashiko)
> ---
> net/mptcp/protocol.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 87f6da0f6cab..6c712f677220 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -3321,6 +3321,12 @@ static void mptcp_do_fastclose(struct sock *sk)
>
> subflow->send_fastclose = 1;
>
> + /* no reset in SYN_SENT, but a close at once, as TCP does */
> + if (ssk->sk_state == TCP_SYN_SENT) {
> + tcp_set_state(ssk, TCP_CLOSE);
> + goto unlock;
> + }
> +
The existing check for LISTEN and CLOSE states in this function uses
if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)).
For consistency, it would be better to use the same style for the SYN_SENT
check here:
if ((1 << ssk->sk_state) & TCPF_SYN_SENT)
This keeps the code style uniform throughout the function. WDYT?
Thanks,
-Geliang
> /* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
> * issue in __tcp_select_window(), see tcp_disconnect().
> */
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener
2026-11-24 21:59 ` [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
@ 2026-11-26 7:07 ` Geliang Tang
0 siblings, 0 replies; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 7:07 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Hi Matt,
On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
> A new msk is a copy of its listener, made without the listener's lock:
> if the application calls sendmsg() with MSG_FASTOPEN on the listener at
> the same time, the new msk can inherit msk->fastopening, only set during
> tcp_sendmsg_fastopen(). mptcp_disconnect() then fails on this socket:
> connect(AF_UNSPEC) returns EBUSY.
>
> Clear this flag when creating a new msk.
>
> This issue has been found by an AI code review agent, while reviewing
> "mptcp: fastopen: keep listeners and connections": before this other
> fix, these new sockets were mostly reset with the listener. It has been
> confirmed with a Packetdrill test, and a debug delay added in
> mptcp_sendmsg_fastopen(), during which the handshake completes. Without
> this patch, connect(AF_UNSPEC) on the accepted socket failed:
>
> runtime error in connect call: Expected result 0 but got -1 with errno 16 (Device or resource busy)
>
> Fixes: 7d803344fdc3 ("mptcp: fix deadlock in fastopen error path")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Looks good! Thanks.
Reviewed-by: Geliang Tang <geliang@kernel.org>
> ---
> v2: new, for an issue found by a review agent
> v3: msg: the new title of the previous patch
> ---
> net/mptcp/protocol.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index d529cfb582a5..b1072123397f 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -4005,6 +4005,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
> WRITE_ONCE(msk->local_key, subflow_req->local_key);
> WRITE_ONCE(msk->token, subflow_req->token);
> msk->in_accept_queue = 1;
> + msk->fastopening = 0;
> WRITE_ONCE(msk->fully_established, false);
> if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD)
> WRITE_ONCE(msk->csum_enabled, true);
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows
2026-11-26 7:04 ` Geliang Tang
@ 2026-11-26 7:35 ` Matthieu Baerts
2026-11-26 8:02 ` Geliang Tang
0 siblings, 1 reply; 75+ messages in thread
From: Matthieu Baerts @ 2026-11-26 7:35 UTC (permalink / raw)
To: Geliang Tang; +Cc: MPTCP Linux
Hi Geliang,
Thank you for the reviews!
On 26/11/2026 08:04, Geliang Tang wrote:
> Hi Matt,
>
> On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
>> mptcp_do_fastclose() sends a reset with an MP_FASTCLOSE on each subflow
>> not in LISTEN or CLOSE, also on the ones in SYN_SENT, while TCP sends no
>> reset in this state, see tcp_need_reset() used by tcp_disconnect(). On a
>> disconnect in SYN_SENT, e.g. with connect(AF_UNSPEC), an MPTCP client
>> then sends a reset with an MP_FASTCLOSE carrying an unknown key, 0. With
>> TCP_FASTOPEN_CONNECT, this reset is even sent before any SYN.
>>
>> Before the commit below, these resets were sent by tcp_disconnect(), so
>> not in SYN_SENT. Skip them again in this state, as TCP does, but move
>> the subflow to TCP_CLOSE at once, as tcp_disconnect() does: a SYN-ACK
>> received before the end of the close cannot complete the connection, and
>> a later one gets a reset from the stack.
>>
>> This issue has been found by an AI code review agent, while reviewing
>> "mptcp: clear DEFER_CONNECT on disconnect", and confirmed with a new
>> Packetdrill test: a disconnect in SYN_SENT, then the SYN-ACK. Without
>> this patch, a reset with MPTCP options was sent at the disconnect,
>> before the one replying to the SYN-ACK:
>>
>> disconnect_in_syn_sent.pkt:16: error handling packet: live packet field ipv4_total_length: expected: 40 (0x28) vs actual: 56 (0x38)
>>
>> Fixes: ae155060247b ("mptcp: fix duplicate reset on fastclose")
>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>> ---
>> v2: new, for an issue found by a review agent
>> v3: move the subflow to TCP_CLOSE at once, not to complete the
>> connection with a SYN-ACK received in between (Clashiko)
>> ---
>> net/mptcp/protocol.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
>> index 87f6da0f6cab..6c712f677220 100644
>> --- a/net/mptcp/protocol.c
>> +++ b/net/mptcp/protocol.c
>> @@ -3321,6 +3321,12 @@ static void mptcp_do_fastclose(struct sock *sk)
>>
>> subflow->send_fastclose = 1;
>>
>> + /* no reset in SYN_SENT, but a close at once, as TCP does */
>> + if (ssk->sk_state == TCP_SYN_SENT) {
>> + tcp_set_state(ssk, TCP_CLOSE);
>> + goto unlock;
>> + }
>> +
>
> The existing check for LISTEN and CLOSE states in this function uses
>
> if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)).
>
> For consistency, it would be better to use the same style for the SYN_SENT
> check here:
>
> if ((1 << ssk->sk_state) & TCPF_SYN_SENT)
>
> This keeps the code style uniform throughout the function. WDYT?
It's good to keep the code style uniform, but I don't think doing that
here is interesting: converting the state to a bitmap is good to check
for multiple states, but not just for one where we can directly compare
the state. Plus it looks this conversion is never done to compare just
one state (except in sock_map_sk_state_allowed() but that feels wrong).
So I think we should better not change this, no?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows
2026-11-26 7:35 ` Matthieu Baerts
@ 2026-11-26 8:02 ` Geliang Tang
0 siblings, 0 replies; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 8:02 UTC (permalink / raw)
To: Matthieu Baerts; +Cc: MPTCP Linux
On Thu, 2026-11-26 at 08:35 +0100, Matthieu Baerts wrote:
> Hi Geliang,
>
> Thank you for the reviews!
>
> On 26/11/2026 08:04, Geliang Tang wrote:
> > Hi Matt,
> >
> > On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
> > > mptcp_do_fastclose() sends a reset with an MP_FASTCLOSE on each subflow
> > > not in LISTEN or CLOSE, also on the ones in SYN_SENT, while TCP sends no
> > > reset in this state, see tcp_need_reset() used by tcp_disconnect(). On a
> > > disconnect in SYN_SENT, e.g. with connect(AF_UNSPEC), an MPTCP client
> > > then sends a reset with an MP_FASTCLOSE carrying an unknown key, 0. With
> > > TCP_FASTOPEN_CONNECT, this reset is even sent before any SYN.
> > >
> > > Before the commit below, these resets were sent by tcp_disconnect(), so
> > > not in SYN_SENT. Skip them again in this state, as TCP does, but move
> > > the subflow to TCP_CLOSE at once, as tcp_disconnect() does: a SYN-ACK
> > > received before the end of the close cannot complete the connection, and
> > > a later one gets a reset from the stack.
> > >
> > > This issue has been found by an AI code review agent, while reviewing
> > > "mptcp: clear DEFER_CONNECT on disconnect", and confirmed with a new
> > > Packetdrill test: a disconnect in SYN_SENT, then the SYN-ACK. Without
> > > this patch, a reset with MPTCP options was sent at the disconnect,
> > > before the one replying to the SYN-ACK:
> > >
> > > disconnect_in_syn_sent.pkt:16: error handling packet: live packet field ipv4_total_length: expected: 40 (0x28) vs actual: 56 (0x38)
> > >
> > > Fixes: ae155060247b ("mptcp: fix duplicate reset on fastclose")
> > > Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> > > ---
> > > v2: new, for an issue found by a review agent
> > > v3: move the subflow to TCP_CLOSE at once, not to complete the
> > > connection with a SYN-ACK received in between (Clashiko)
> > > ---
> > > net/mptcp/protocol.c | 6 ++++++
> > > 1 file changed, 6 insertions(+)
> > >
> > > diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> > > index 87f6da0f6cab..6c712f677220 100644
> > > --- a/net/mptcp/protocol.c
> > > +++ b/net/mptcp/protocol.c
> > > @@ -3321,6 +3321,12 @@ static void mptcp_do_fastclose(struct sock *sk)
> > >
> > > subflow->send_fastclose = 1;
> > >
> > > + /* no reset in SYN_SENT, but a close at once, as TCP does */
> > > + if (ssk->sk_state == TCP_SYN_SENT) {
> > > + tcp_set_state(ssk, TCP_CLOSE);
> > > + goto unlock;
> > > + }
> > > +
> >
> > The existing check for LISTEN and CLOSE states in this function uses
> >
> > if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)).
> >
> > For consistency, it would be better to use the same style for the SYN_SENT
> > check here:
> >
> > if ((1 << ssk->sk_state) & TCPF_SYN_SENT)
> >
> > This keeps the code style uniform throughout the function. WDYT?
>
> It's good to keep the code style uniform, but I don't think doing that
> here is interesting: converting the state to a bitmap is good to check
> for multiple states, but not just for one where we can directly compare
> the state. Plus it looks this conversion is never done to compare just
> one state (except in sock_map_sk_state_allowed() but that feels wrong).
>
> So I think we should better not change this, no?
You're right, using "ssk->sk_state == TCP_SYN_SENT" is more efficient here.
Reviewed-by: Geliang Tang <geliang@kernel.org>
Thanks,
-Geliang
>
> Cheers,
> Matt
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does
2026-11-26 2:59 ` Geliang Tang
@ 2026-11-26 8:06 ` Matthieu Baerts
0 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts @ 2026-11-26 8:06 UTC (permalink / raw)
To: Geliang Tang, Mat Martineau; +Cc: MPTCP Linux
Hi Geliang, Mat,
Thank you for the reviews!
On 26/11/2026 03:59, Geliang Tang wrote:
> Hi Matt, Mat,
>
> On Wed, 2026-11-25 at 17:57 -0800, Mat Martineau wrote:
>> On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:
>>
>>> Once an MPTCP socket has received a DATA_FIN, recv() returns the
>>> remaining data, then EOF. But if the connection was then reset, e.g. by
>>> an MP_FASTCLOSE, recv() returned an error after the data, e.g. EPIPE,
>>> instead of EOF as TCP does. A proxy resetting the other connection on
>>> read errors then dropped the data it still had to forward.
>>>
>>> As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and
>>> check it before the socket error in recvmsg(). With an MP_FASTCLOSE, the
>>> data still in the backlog is moved first, not to miss the DATA_FIN.
>>> After a fallback, a DATA_FIN is also emulated after a reset: only set
>>> SOCK_DONE after a FIN, not to hide a reset behind an EOF. This FIN is
>>> cleared when the first subflow is disconnected: process this DATA_FIN
>>> before.
>>>
>>> This was reported on GitHub, and is validated with new Packetdrill
>>> tests: data and a DATA_FIN are received, then an MP_FASTCLOSE; and
>>> after a fallback, data, a FIN and a reset. Without this patch, the
>>> second read() returned EPIPE in both cases:
>>>
>>> receive_fastclose_after_data_fin.pkt:27: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
>>> v1_connect_tcpfallback_fin_reset.pkt:19: runtime error in read call: Expected result 0 but got -1 with errno 32 (Broken pipe)
>>>
>>> Note for the backports: the issue with an MP_FASTCLOSE comes from commit
>>> 69800e516e96 ("mptcp: propagate fastclose error"), in v6.1. Before that,
>>> the modifications in mptcp_check_fastclose() and mptcp_disconnect() are
>>> not needed.
>>>
>>> Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
>>> Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
>>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>>
>> Reviewed-by: Mat Martineau <martineau@kernel.org>
>
> Thanks for adding this SOCK_DONE patch; it is very helpful for my work on
> modifying mptcp_inq_hint(). mptcp_inq_hint() should check SOCK_DONE, just like
> tcp_inq_hint() does.
>
> Acked-by: Geliang Tang <geliang@kernel.org>
>
> I'm wondering whether this patch should come before patch 1, because patch 1
> checks SOCK_DONE, but SOCK_DONE isn't set at that point.
Yes, maybe. I mean: this patch 4 fixes an issue that got discovered when
working on patch 1. We could but if there are no objections, I would
prefer to keep this like that: the 6 first patches are likely to be sent
together, and both patches 1 and 4 should be backported to v5.15. So no
for extra work here?
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does
2026-11-26 6:40 ` Geliang Tang
@ 2026-11-26 8:15 ` Matthieu Baerts
0 siblings, 0 replies; 75+ messages in thread
From: Matthieu Baerts @ 2026-11-26 8:15 UTC (permalink / raw)
To: Geliang Tang; +Cc: MPTCP Linux
Hi Geliang,
Thank you for the review!
On 26/11/2026 07:40, Geliang Tang wrote:> Hi Matt,
>
> On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
>> After a disconnect with connect(AF_UNSPEC), an error from the previous
>> connection, e.g. a reset not reported yet to the application, was still
>> reported for the next connection, by poll(), SO_ERROR, and the first
>> send() or recv(). TCP clears it in tcp_connect_init(): do the same,
>> once the subflow connect() succeeded, so an early failure keeps it.
>>
>> This issue has been found by an AI code review agent, while reviewing
>> other fixes, and confirmed with a reproducer: the peer resets the
>> connection, the error is not read, then the socket is disconnected and
>> connected again. SO_ERROR then reported ECONNRESET each time, while TCP
>> reported no error, as MPTCP now does.
>>
>> Fixes: 3d1d6d66e156 ("mptcp: implement support for user-space disconnect")
>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>
> Thanks for this fix. Looks good to me!
>
> Reviewed-by: Geliang Tang <geliang@kernel.org>
>
>> ---
>> v2: new, for an issue found by a review agent
>> ---
>> net/mptcp/protocol.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
>> index ff1dcf306723..6328815ad273 100644
>> --- a/net/mptcp/protocol.c
>> +++ b/net/mptcp/protocol.c
>> @@ -4452,6 +4452,8 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
>> if (err < 0)
>> goto out;
>>
>> + /* as tcp_connect_init(): drop an error from a previous connection */
>> + WRITE_ONCE(sk->sk_err, 0);
>
> tcp_connect_init() also calls sock_reset_flag(sk, SOCK_DONE) here; maybe MPTCP
> needs this sock_reset_flag(sk, SOCK_DONE) too.
We are doing that in mptcp_disconnect() and I think that's enough. From
what I see a reused msk can't reach mptcp_connect() without it, and
nothing can set SOCK_DONE again before the next connection is
established. In fact, I think the sock_reset_flag(sk, SOCK_DONE) in
tcp_connect_init() is redundant and not needed.
(Note that on the other end, it seems better to clear sk_err here than
in the disconnect, similar to TCP, so the error can still be seen after
disconnect(), and before connect()).
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 75+ messages in thread
* Re: [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections
2026-11-24 21:59 ` [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections Matthieu Baerts (NGI0)
@ 2026-11-26 8:20 ` Geliang Tang
0 siblings, 0 replies; 75+ messages in thread
From: Geliang Tang @ 2026-11-26 8:20 UTC (permalink / raw)
To: Matthieu Baerts (NGI0), MPTCP Linux
Hi Matt,
On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
> A sendmsg() with MSG_FASTOPEN on an MPTCP listener fails, e.g. with
> EISCONN, as with TCP, but it also closes the listener: after any error,
> mptcp_sendmsg_fastopen() retries the disconnect that could have failed
> in __inet_stream_connect(), while there is nothing to retry for a
> listener. On a connection closed by both sides, with data still to be
> read, the same retry also drops this data and the end of the stream.
>
> Skip this disconnect for a listener and for a connected socket:
> __inet_stream_connect() returned without trying to disconnect them. They
> are then kept as they are, as with TCP.
>
> This issue has been found by an AI code review agent, while reviewing
> "mptcp: report sf aborts during deferred connect", and confirmed with a
> new Packetdrill test: sendto() with MSG_FASTOPEN on a listener, then a
> SYN. Without this patch, the SYN got a reset instead of a SYN-ACK:
>
> listen_sendto_fastopen.pkt:14: error handling packet: live packet field ipv4_total_length: expected: 60 (0x3c) vs actual: 40 (0x28)
>
> The case of the closed connection has been found by an AI code review
> agent (Clashiko), while reviewing a previous version of this patch, and
> confirmed with another Packetdrill test: after a shutdown(), data and a
> DATA_FIN are received, then sendto() with MSG_FASTOPEN fails with
> EISCONN. Without this patch, the data could no longer be read:
>
> closed_sendto_fastopen.pkt:30: runtime error in read call: Expected result 1000 but got -1 with errno 107 (Transport endpoint is not connected)
>
> Fixes: 7d803344fdc3 ("mptcp: fix deadlock in fastopen error path")
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Looks good. Thanks!
Reviewed-by: Geliang Tang <geliang@kernel.org>
> ---
> v2: new, for an issue found by a review agent
> v3: also skip it for a connected socket, not to drop unread data
> (Clashiko)
>
> Note (Clashiko on v2): only retrying a disconnect that failed, with
> SS_DISCONNECTING, would leave a deferred socket stuck after an early
> error from tcp_sendmsg_fastopen(), DEFER_CONNECT being cleared on the
> msk: then, the disconnect is still retried, as before.
> ---
> net/mptcp/protocol.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 6c712f677220..d529cfb582a5 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2004,11 +2004,14 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
> */
> if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
> *copied_syn = 0;
> - } else if (ret && ret != -EINPROGRESS) {
> + } else if (ret && ret != -EINPROGRESS && sk->sk_state != TCP_LISTEN &&
> + sk->sk_socket->state != SS_CONNECTED) {
> /* The disconnect() op called by tcp_sendmsg_fastopen()/
> * __inet_stream_connect() can fail, due to looking check,
> * see mptcp_disconnect().
> * Attempt it again outside the problematic scope.
> + * A listener or a connected socket is not disconnected there,
> + * as with TCP.
> */
> if (!mptcp_disconnect(sk, 0)) {
> sk->sk_disconnects++;
^ permalink raw reply [flat|nested] 75+ messages in thread
end of thread, other threads:[~2026-11-26 8:20 UTC | newest]
Thread overview: 75+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 21:59 [PATCH mptcp-net v3 00/50] mptcp: misc fixes Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-11-25 1:16 ` Mat Martineau
2026-11-25 1:17 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
2026-11-25 1:19 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-11-25 1:21 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-11-26 1:57 ` Mat Martineau
2026-11-26 2:59 ` Geliang Tang
2026-11-26 8:06 ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 05/50] mptcp: let TCP send orphan data after fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 07/50] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 08/50] mptcp: set SEND_SHUTDOWN on close by an sf error Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 09/50] mptcp: start close timeout on initial sf shutdown Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN Matthieu Baerts (NGI0)
2026-11-24 22:33 ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does Matthieu Baerts (NGI0)
2026-11-26 6:40 ` Geliang Tang
2026-11-26 8:15 ` Matthieu Baerts
2026-11-24 21:59 ` [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect Matthieu Baerts (NGI0)
2026-11-26 6:41 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows Matthieu Baerts (NGI0)
2026-11-26 7:04 ` Geliang Tang
2026-11-26 7:35 ` Matthieu Baerts
2026-11-26 8:02 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections Matthieu Baerts (NGI0)
2026-11-26 8:20 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener Matthieu Baerts (NGI0)
2026-11-26 7:07 ` Geliang Tang
2026-11-24 21:59 ` [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 23/50] mptcp: pm: kernel: count endpoint listeners as sockets in use Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 24/50] mptcp: count a listener once when listen() is called again Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 27/50] mptcp: do not fallback while old data is in flight Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 28/50] mptcp: stop resending data to a peer that fell back Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts Matthieu Baerts (NGI0)
2026-11-24 22:36 ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 30/50] mptcp: pm: kernel: don't count signal+subflow ID 0 endp Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 31/50] selftests: mptcp: join: check re-adding " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 32/50] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
2026-11-26 2:20 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
2026-11-26 2:43 ` Mat Martineau
2026-11-24 21:59 ` [PATCH mptcp-net v3 35/50] mptcp: don't charge a subflow twice when it joins during accept() Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect Matthieu Baerts (NGI0)
2026-11-24 22:45 ` sashiko-bot
2026-11-24 21:59 ` [PATCH mptcp-net v3 38/50] mptcp: move to ESTABLISHED " Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 39/50] mptcp: fix MSG_PEEK after a partly peeked skb Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 41/50] selftests: mptcp: join: infinite map: no spurious rtx Matthieu Baerts (NGI0)
2026-11-24 21:59 ` [PATCH mptcp-net v3 42/50] selftests: mptcp: connect: trunc: wait for acks Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 44/50] mptcp: order write_seq and DATA_FIN flag for fallback Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops" Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers" Matthieu Baerts (NGI0)
2026-11-24 22:45 ` sashiko-bot
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 47/50] mptcp: push pending data after a fallback on reception Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing Matthieu Baerts (NGI0)
2026-11-24 22:52 ` sashiko-bot
2026-11-24 22:00 ` [PATCH mptcp-next mptcp-net v3 49/50] mptcp: trace: name all the mapping statuses Matthieu Baerts (NGI0)
2026-11-24 22:00 ` [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK Matthieu Baerts (NGI0)
2026-11-24 22:36 ` sashiko-bot
2026-11-25 0:39 ` [PATCH mptcp-net v3 00/50] mptcp: misc fixes MPTCP CI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox