Skip to contentSkip to conversation

mptcp: misc fixes

PATCH Superseded Matthieu Baerts (NGI0) 6 participants 105 messages Nov 24 – Dec 1

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Matthieu Baerts (NGI0)

author maintainer
#0 lore raw

v3 cover mptcp: misc fixes

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.

---
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/[email protected]

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/[email protected]

---
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,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#1 lore raw

PATCH v3 1/50 mptcp: keep an orphan while it can send its data

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")

---
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(+)
net/mptcp/protocol.c +31 -0
index d64e04245963..944c9d11d211 100644
@@ -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);
 
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 1/50
#2 lore raw

Re: [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data

Quoted 23 lines · 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.

Quoted 3 lines
Fixes e16163b6e2b7 ("mptcp: refactor shutdown and close")

v2 LGTM:

Quoted 73 lines

---
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(+)
net/mptcp/protocol.c +31 -0
index d64e04245963..944c9d11d211 100644
@@ -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);
 
Signature · 2 lines
-- 
2.55.0
maintainer
#3 lore raw

Re: [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data

Quoted 25 lines · Mat Martineau
Quoted 23 lines · 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.

Quoted 5 lines
Quoted 3 lines
Fixes e16163b6e2b7 ("mptcp: refactor shutdown and close")

v2 LGTM:

(I meant v3...)

Quoted 81 lines
Quoted 77 lines

---
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(+)
net/mptcp/protocol.c +22 -0
index d64e04245963..944c9d11d211 100644
@@ -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;
net/mptcp/protocol.c +9 -0
@@ -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);
Signature · 2 lines
-- 
2.55.0
#4 lore raw

Re: [PATCH mptcp-net v3 01/50] mptcp: keep an orphan while it can send its data

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In mptcp_check_send_data_fin() (net/mptcp/protocol.c), this patch adds a restart of the close timeout for every orphan when the DATA_FIN…

--

mptcp: keep an orphan while it can send its data

With this patch, an orphaned MPTCP socket is no longer reset when its close timeout expires while a subflow can still send pending data. The close timeout is restarted when the DATA_FIN is sent. On expiry, it is also restarted as long as an active subflow has recently received an ack from the peer.

Quoted 4 lines
net/mptcp/protocol.c +0 -0
index d64e04245963c..944c9d11d2116 100644

[ ... ]

net/mptcp/protocol.c static void mptcp_check_send_data_fin(struct sock *sk) · line 3482

Quoted 8 lines
net/mptcp/protocol.c +4 -0
@@ -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);
+

[Severity: Low]
Can this restart cancel the forced expiry that __mptcp_close_ssk() sets when an orphan's last subflow reaches TCP_CLOSE?

net/mptcp/protocol.c:__mptcp_close_ssk() {
    ...
	if (list_is_singular(&msk->conn_list) && msk->first &&
	    inet_sk_state_load(msk->first) == TCP_CLOSE) {
		if (sock_flag(sk, SOCK_DEAD)) {
			/* let the worker close and destroy the orphan */
			mptcp_set_close_tout(sk, tcp_jiffies32 -
					     (mptcp_close_timeout(sk) + 1));
			mptcp_schedule_work(sk);
    ...
}

mptcp_worker() calls mptcp_pm_worker() and then mptcp_check_send_data_fin() before any of the mptcp_close_tout_expired() checks.

Take an orphan whose last data was pushed from BH by __mptcp_subflow_push_pending(). That function only schedules the worker for the DATA_FIN. Suppose all the data is then acked, and the last subflow is closed before mptcp_check_send_data_fin() runs, for example:

mptcp_worker()
mptcp_pm_worker()
mptcp_pm_rm_addr_or_subflow() (peer RM_ADDR or local endpoint removal)
mptcp_close_ssk()
__mptcp_close_ssk() <- sets the expired marker
mptcp_check_send_data_fin()
mptcp_start_tout_timer() <- probe_timestamp reset to now

A netlink subflow_destroy or endpoint removal under the msk lock, before the worker runs, leads to the same result.

In both cases mptcp_close_tout_expired() then returns false. The state is still FIN_WAIT1 or LAST_ACK rather than TCP_CLOSE, so __mptcp_destroy_sock() is skipped.

Does the orphan then stay alive with no usable subflow until the close timer fires, about TCP_TIMEWAIT_LEN later? Before this patch it was destroyed in the same worker run.

Subflows closed by a peer RST go through __mptcp_close_subflow(). That runs after mptcp_check_send_data_fin() in the worker, so they don't seem to be affected.

The note below the --- line mentions this one-time delay. It rejects not restarting an already expired timeout, because that would reset an orphan sending its DATA_FIN after a long probing.

Could the timeout be restarted here only when some subflow can still send (__mptcp_subflow_active()), and the expired marker kept otherwise? In the long probing case an active subflow exists, so that case would not be affected.

The new comment ("an orphan's close timeout is for the DATA_FIN exchange") also doesn't fit this case, because no subflow is left to carry the DATA_FIN.

The comments in __mptcp_close_ssk() ("let the worker close and destroy the orphan") also no longer match what happens on this path.

Quoted 3 lines
net/mptcp/protocol.c +0 -0
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
 
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#5 lore raw

PATCH v3 2/50 mptcp: limit an orphan probing a zero window

In reply to 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")

---
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(-)
net/mptcp/protocol.c +28 -1
index 944c9d11d211..ff71f1954077 100644
@@ -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;
 	}
 
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 2/50
#6 lore raw

Re: [PATCH mptcp-net v3 02/50] mptcp: limit an orphan probing a zero window

Quoted 20 lines · 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.

Quoted 5 lines

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")
Quoted 65 lines

---
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(-)
net/mptcp/protocol.c +28 -1
index 944c9d11d211..ff71f1954077 100644
@@ -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;
 	}
 
Signature · 2 lines
-- 
2.55.0
author maintainer
#7 lore raw

PATCH v3 3/50 mptcp: count orphans as TCP does

In reply to 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")

---
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(-)
net/mptcp/protocol.c +22 -2
index ff71f1954077..9e297fa08bfe 100644
@@ -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);
net/mptcp/protocol.h +1 -0
index 2c9a442dacd6..888ee9d66967 100644
@@ -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
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 3/50
#8 lore raw

Re: [PATCH mptcp-net v3 03/50] mptcp: count orphans as TCP does

Quoted 17 lines · 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.

Quoted 8 lines

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")
Quoted 85 lines

---
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(-)
net/mptcp/protocol.c +22 -2
index ff71f1954077..9e297fa08bfe 100644
@@ -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);
net/mptcp/protocol.h +1 -0
index 2c9a442dacd6..888ee9d66967 100644
@@ -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
Signature · 2 lines
-- 
2.55.0
author maintainer
#9 lore raw

PATCH v3 4/50 mptcp: return EOF after a DATA_FIN, as TCP does

In reply to 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")

---
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(-)
net/mptcp/protocol.c +29 -2
index 9e297fa08bfe..de6da0b6c4ca 100644
@@ -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;
 }
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 4/50
#10 lore raw

Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does

Quoted 22 lines · 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)

Quoted 8 lines

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")
Quoted 108 lines

---
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(-)
net/mptcp/protocol.c +29 -2
index 9e297fa08bfe..de6da0b6c4ca 100644
@@ -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;
 }
Signature · 2 lines
-- 
2.55.0
reviewer Acked-by
#11 lore raw

Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does

Hi Matt, Mat,

Quoted 29 lines · Mat Martineau
Quoted 27 lines · 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.

Quoted 5 lines
Quoted 3 lines
Fixes 15cc10453398 ("mptcp: deliver ssk errors to msk")

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.

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

Quoted 109 lines
Quoted 109 lines

---
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(-)
net/mptcp/protocol.c +29 -2
index 9e297fa08bfe..de6da0b6c4ca 100644
@@ -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;
 }
Signature · 2 lines
-- 
2.55.0
author maintainer
#12 lore raw

Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does

Hi Geliang, Mat,

Thank you for the reviews!

Quoted 38 lines · Geliang Tang

Hi Matt, Mat,

Quoted 29 lines · Mat Martineau
Quoted 27 lines · 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.

Quoted 5 lines
Quoted 3 lines
Fixes 15cc10453398 ("mptcp: deliver ssk errors to msk")
Quoted 8 lines

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.

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

Signature · 1 line
Sponsored by the NGI0 Core fund.
#13 lore raw

Re: [PATCH mptcp-net v3 04/50] mptcp: return EOF after a DATA_FIN, as TCP does

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] After a fallback, a race can still make recv() return an error instead of EOF after a FIN followed by a reset, which is the case this…
- [Low] The commit message leaves out several user-visible behaviour changes.

--

mptcp: return EOF after a DATA_FIN, as TCP does

This patch sets SOCK_DONE on the msk when a DATA_FIN is processed. It also checks SOCK_DONE before the socket error in mptcp_recvmsg(), so recv() returns EOF instead of an error when a reset follows a DATA_FIN. With an MP_FASTCLOSE, or on a fallback in mptcp_close_ssk(), the pending DATA_FIN is now processed before the reset or disconnect clears that state.

Quoted 4 lines
net/mptcp/protocol.c +0 -0
index 9e297fa08bfed..de6da0b6c4ca4 100644

[ ... ]

net/mptcp/protocol.c static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk) · line 984

Quoted 10 lines
net/mptcp/protocol.c +3 -0
@@ -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);

[Severity: Low]
This isn't a bug, but the commit message seems to leave out a few user-visible behaviour changes. It says:

As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and check it before the socket error in recvmsg().

In __mptcp_subflow_error_report(), SOCK_DONE is set on the msk but the DATA_FIN is not processed. ack_seq is not bumped, rcv_data_fin is not cleared and RCV_SHUTDOWN is not set. The msk then moves straight to TCP_CLOSE. Could the message describe this path too?

mptcp_splice_read() already had a SOCK_DONE check. It could never fire, because nothing in net/mptcp/ set SOCK_DONE on the msk:

net/mptcp/protocol.c:mptcp_splice_read() {
    ...
		} else if (!ret) {
			if (spliced)
				break;
			if (sock_flag(sk, SOCK_DONE))
				break;
			ret = sock_error(sk);
    ...
}

With this patch, splice() also returns EOF where it used to return an error. Should the message mention that?

In mptcp_check_fastclose(), mptcp_check_data_fin() now runs before the error switch:

	/* Mirror the tcp_reset() error propagation */
	switch (sk->sk_state) {
	...
	case TCP_CLOSE_WAIT:
		WRITE_ONCE(sk->sk_err, EPIPE);
		break;
	case TCP_CLOSE:
		return;
	default:
		WRITE_ONCE(sk->sk_err, ECONNRESET);
	}

With a pending DATA_FIN in ESTABLISHED, the msk first moves to CLOSE_WAIT. SO_ERROR and send() then see EPIPE instead of ECONNRESET.

In FIN_WAIT2, the msk moves to TCP_CLOSE and the switch returns early. In that case:

- no sk_err is set
- sk_error_report() is not called, so there is no EPOLLERR
- MPTCP_WORK_CLOSE_SUBFLOW is not set
- the reset subflows stay until close()

Only the notes below the '---' line explain this last case, and git history won't keep them.

The message also targets stable backports down to v6.1. Could these changes be documented in the commit message itself?

[ ... ]

Quoted 1 line
net/mptcp/protocol.c +0 -0
@@ -2820,12 +2832,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,

[ ... ]

net/mptcp/protocol.c void mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2852

Quoted 11 lines
net/mptcp/protocol.c +8 -0
+	/* 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);
 }

[Severity: Medium]
On a fallback connection, can a race still make recv() return an error instead of EOF when a FIN is followed by a reset?

This check reads msk->rcv_data_fin without holding the subflow lock. The FIN is cleared later, under lock_sock_nested(ssk):

mptcp_close_ssk()
__mptcp_close_ssk()
__mptcp_subflow_disconnect()
tcp_disconnect()
sock_reset_flag(sk, SOCK_DONE)

So the check and the disconnect are not in the same critical section.

The emulated DATA_FIN can be set for the first time only when the subflow moves to TCP_CLOSE, after a FIN was already received. Two examples:

- The msk is in FIN_WAIT1 after shutdown(SHUT_WR), and the peer FIN moves the subflow to CLOSING.
- The subflow is in CLOSE_WAIT while our data is still pending.

In both cases subflow_sched_work_if_closed() returns early, and the subflow keeps SOCK_DONE:

	if (likely(ssk->sk_state != TCP_CLOSE &&
		   (ssk->sk_state != TCP_CLOSE_WAIT ||
		    inet_sk_state_load(sk) != TCP_ESTABLISHED)))
		return;

When the RST arrives, subflow_sched_work_if_closed() schedules the worker before it writes rcv_data_fin:

	if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
		mptcp_schedule_work(sk);
	...
	if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
	    msk->first == ssk &&
	    mptcp_update_rcv_data_fin(msk, subflow->map_seq +
				      subflow->map_data_len, true))

A possible sequence:

CPU0 (softirq, ssk spinlock held)
tcp_reset()->tcp_done()->subflow_state_change()
subflow_sched_work_if_closed()
test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW)
mptcp_schedule_work()

CPU1 (mptcp_worker, already owning the msk)
test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW)
__mptcp_close_subflow()

    mptcp_close_ssk(first)
      READ_ONCE(msk->rcv_data_fin) == 0, new block skipped
      __mptcp_close_ssk()
        lock_sock_nested(ssk) spins

CPU0
mptcp_update_rcv_data_fin() sets rcv_data_fin = 1 subflow_error_report() only sets MPTCP_ERROR_REPORT, msk is owned ssk spinlock released

CPU1
tcp_disconnect() clears SOCK_DONE, keeps ssk->sk_err tail of __mptcp_close_ssk() moves the non-ESTABLISHED msk to TCP_CLOSE

After that, mptcp_pending_data_fin() can never be true again.

At release_sock(msk), the deferred report runs:
__mptcp_error_report()->__mptcp_subflow_error_report(). By then the subflow no longer has SOCK_DONE and the msk is closed, so the new check there does not set SOCK_DONE. ECONNRESET or EPIPE is copied into sk->sk_err.

recvmsg() then returns the queued data followed by the error instead of EOF. The rescheduled worker exits right away because the msk is in TCP_CLOSE.

Later patches in this series don't change mptcp_close_ssk() or subflow_sched_work_if_closed(). At the end of the series, mptcp_check_rcv_close() in the tail of __mptcp_close_ssk() processes the DATA_FIN only after the disconnect. SOCK_DONE is still not set, and mptcp_close_last_err() still reports the error.

The window is narrow, because mptcp_worker must be running at the same time. When the msk is not owned, subflow_check_data_avail() sets rcv_data_fin before subflow_error_report(), so the common paths are covered.

Could the decision be made under the ssk lock, before __mptcp_subflow_disconnect()? Alternatively, could the subflow FIN be recorded on the msk before the disconnect?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#14 lore raw

PATCH v3 5/50 mptcp: let TCP send orphan data after fallback

In reply to 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")

---
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(+)
net/mptcp/protocol.c +28 -0
index de6da0b6c4ca..f28262f07282 100644
@@ -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;
 
Signature · 1 line
2.55.0
author maintainer
#15 lore raw

PATCH v3 6/50 mptcp: reset the subflow on abort after fallback

In reply to 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")

---
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(-)
net/mptcp/protocol.c +5 -7
index f28262f07282..bbb28f778d81 100644
@@ -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);
 
Signature · 1 line
2.55.0
#16 lore raw

Re: [PATCH mptcp-net v3 06/50] mptcp: reset the subflow on abort after fallback

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says that, after a fallback to TCP, closing with SO_LINGER and a zero timeout "did not reset the connection as TCP…
- [Low] With the fallback early return gone, mptcp_do_fastclose() (net/mptcp/protocol.c:3272-3289) sends a plain TCP RST with…

--

mptcp: reset the subflow on abort after fallback

This patch removes the fallback early return in mptcp_do_fastclose(). As a result, a plain TCP reset is now sent on each subflow when an MPTCP socket that fell back to TCP is aborted. It also moves the switch of fastclosed subflows to TCP_CLOSE earlier in __mptcp_close_ssk(), so that inet_child_forget() does not send a second reset to children of a closed listener that were never accepted.

Quoted 4 lines

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.

[Severity: Low]
Is the SO_LINGER part of this description accurate? It looks like the zero linger case already sent a TCP reset before this patch.

SO_LINGER is copied to every subflow. mptcp_setsockopt_sol_socket_linger() does it for existing subflows, and sync_socket_options() does it for subflows created later:

net/mptcp/sockopt.c:sync_socket_options() {
    ...
	if (sock_flag(sk, SOCK_LINGER)) {
		ssk->sk_lingertime = sk->sk_lingertime;
		sock_set_flag(ssk, SOCK_LINGER);
    ...
}

Before this patch, the SO_LINGER(0) close of a fallen-back socket went through:

__mptcp_close()
mptcp_do_fastclose() <- returned early after fallback
__mptcp_destroy_sock()

    mptcp_destroy()
      mptcp_destroy_common()
        __mptcp_close_ssk()
          __tcp_close(ssk, 0)

send_fastclose was never set, so the subflow was not moved to TCP_CLOSE. __tcp_close() then reached the zero linger branch:

net/ipv4/tcp.c:__tcp_close() {
    ...
	} else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
		/* Check zero linger _after_ checking for unread data. */
		sk->sk_prot->disconnect(sk, 0);
    ...
}

tcp_disconnect() sends a reset for every state in tcp_need_reset().

Only the unread data case seems to have sent a FIN. That is the case the Packetdrill test covers: the unread data was in the msk receive queue, so __tcp_close() on the subflow saw neither unread data nor zero linger.

Could the commit message be limited to the unread data case?

Quoted 4 lines
net/mptcp/protocol.c +0 -0
index f28262f072820..bbb28f778d81d 100644

[ ... ]

net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3275

Quoted 12 lines
net/mptcp/protocol.c +1 -4
@@ -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);
 

[Severity: Low]
With the early return gone, the loop now filters fallen-back subflows only by LISTEN and CLOSE:

net/mptcp/protocol.c:mptcp_do_fastclose() {
    ...
		/* Some subflow socket states don't allow/need a reset.*/
		if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
			goto unlock;
    ...
		tcp_send_active_reset(ssk, SK_RST_REASON_TCP_ABORT_ON_CLOSE);
    ...
}

Plain TCP uses a narrower rule in tcp_disconnect():

net/ipv4/tcp.c:tcp_disconnect() {
    ...
	} else if (tcp_need_reset(old_state)) {
		tcp_send_active_reset(sk, SK_RST_REASON_TCP_STATE);
		WRITE_ONCE(sk->sk_err, ECONNRESET);
	} else if (tp->snd_nxt != tp->write_seq &&
		   (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK)) {
    ...
}

tcp_need_reset() covers only ESTABLISHED, CLOSE_WAIT, FIN_WAIT1, FIN_WAIT2 and SYN_RECV.

Before this patch, these fallen-back subflows were torn down by tcp_disconnect(). On SO_LINGER(0) close, that happened through the zero linger branch of __tcp_close(). On disconnect() and on the orphan close timeout, it happened through __mptcp_subflow_disconnect().

Can a fallen-back subflow in CLOSING or LAST_ACK now get a reset that plain TCP would not send? That would be the case when all its data and its FIN were already sent (snd_nxt == write_seq), on close() with SO_LINGER{1,0}, connect(AF_UNSPEC), the orphan close timeout in mptcp_worker(), or mptcp_orphan_oom().

For close() with unread data, TCP also resets in these states, so that path matches.

SYN_SENT subflows are handled later in this series by "mptcp: no fastclose reset from SYN_SENT subflows". Only the CLOSING and LAST_ACK difference remains at the end of the series.

The commit message says the reset is now sent as without a fallback. Only the v2 note below the "---" line mentions this difference, and git am drops that note. Should the permanent commit message, or a comment in mptcp_do_fastclose(), mention it?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#17 lore raw

PATCH v3 7/50 mptcp: wake up blocked senders when no sf left

In reply to 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")

---
v2: new, for issue #648 reported on GitHub

---
 net/mptcp/protocol.c | 3 +++
 1 file changed, 3 insertions(+)
net/mptcp/protocol.c +3 -0
index bbb28f778d81..d54ca367fc39 100644
@@ -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);
 	}
 
Signature · 1 line
2.55.0
author maintainer
#18 lore raw

PATCH v3 8/50 mptcp: set SEND_SHUTDOWN on close by an sf error

In reply to 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")

---
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(-)
net/mptcp/protocol.c +6 -2
index d54ca367fc39..d1bbba582aa1 100644
@@ -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;
 
Signature · 1 line
2.55.0
author maintainer
#19 lore raw

PATCH v3 9/50 mptcp: start close timeout on initial sf shutdown

In reply to 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")

---
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(+)
net/mptcp/protocol.c +8 -0
index d1bbba582aa1..5d916c6b43f4 100644
@@ -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);
 	}
 }
 
Signature · 1 line
2.55.0
author maintainer
#20 lore raw

PATCH v3 10/50 mptcp: process a DATA_FIN received with old data

In reply to 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")

---
v2: new, for an issue causing a flaky selftest

---
 net/mptcp/subflow.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/mptcp/subflow.c +7 -4
index 054ee992904e..67a749643ad7 100644
@@ -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);
 
Signature · 1 line
2.55.0
#21 lore raw

Re: [PATCH mptcp-net v3 10/50] mptcp: process a DATA_FIN received with old data

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In get_mapping_status() (net/mptcp/subflow.c), the patch moves if (updated) mptcp_schedule_work((struct sock *)msk); from the…

--

mptcp: process a DATA_FIN received with old data

A DATA_FIN can be recorded by get_mapping_status() while it arrives with data that is old at the MPTCP level, or in the middle of such a mapping. Because that data is never moved to the msk, the DATA_FIN was never processed or acked. This patch schedules the MPTCP worker whenever the DATA_FIN is first recorded, so mptcp_check_data_fin() can handle it.

net/mptcp/subflow.c static enum mapping_status get_mapping_status(struct sock *ssk, · line 1249

Quoted 13 lines
net/mptcp/subflow.c +4 -0
index 054ee992904e0..67a749643ad75 100644
@@ -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) {

[Severity: Low]
This isn't a bug, but the new comment only seems to describe one of the two paths that now run this mptcp_schedule_work() call.

In get_mapping_status(), the call has moved above the
if (subflow->map_valid) test. So it now covers the case where a DATA_FIN-only DSS arrives in the middle of an existing mapping, and also the !subflow->map_valid case that returns MAPPING_DATA_FIN.

In the !map_valid case there is no current mapping. The worker is scheduled there because a DATA_FIN outside a mapping never reaches the msk through the data-move path. Before this patch, that was the only reason for the call.

Could the comment cover both cases? For example, "The current mapping, if any, can be old ...", or a short note about the no-mapping case. Otherwise a later reader might think the scheduling is only needed for old mappings.

Quoted 12 lines
net/mptcp/subflow.c +0 -3
 				/* 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;
 		}
 

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#22 lore raw

PATCH v3 11/50 mptcp: no sf left: process pending MP_FASTCLOSE

In reply to 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")

---
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(+)
net/mptcp/protocol.c +5 -0
index 5d916c6b43f4..bcdad00d3573 100644
@@ -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);
Signature · 1 line
2.55.0
reviewer
#23 lore raw

Re: [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE

Hi Matt,

Quoted 46 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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")

---
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(+)
net/mptcp/protocol.c +0 -0
index 5d916c6b43f4..bcdad00d3573 100644

net/mptcp/protocol.c static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk) · line 2709

Quoted 5 lines
net/mptcp/protocol.c +2 -0
@@ -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);
+

Would it be more appropriate to move the definition of mptcp_check_rcv_close() helper from patch 12 into this patch?

static void mptcp_check_rcv_close(struct sock *sk)

{
	mptcp_check_fastclose(mptcp_sk(sk));
}

WDYT?

Thanks,
-Geliang

Quoted 13 lines
net/mptcp/protocol.c +3 -0
 /* 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);
author maintainer
#24 lore raw

Re: [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE

Hi Geliang,

Thank you for the review!

Quoted 52 lines · Geliang Tang

Hi Matt,

Quoted 49 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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")

---
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(+)
net/mptcp/protocol.c +0 -0
index 5d916c6b43f4..bcdad00d3573 100644
@@ -2705,6 +2705,8 @@ static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
 	mptcp_data_unlock(sk);
 }
 
Quoted 5 lines

net/mptcp/protocol.c static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk) · line 2709

Quoted 2 lines
net/mptcp/protocol.c +2 -0
+static void mptcp_check_fastclose(struct mptcp_sock *msk);
+

Would it be more appropriate to move the definition of mptcp_check_rcv_close() helper from patch 12 into this patch?

It's a good idea, but I prefer not to do that for net and keep the patch as small as possible. The patch 11/50 can be backported up to v5.10:
better to keep it small. While the next one is for v6.19 (so only backported to v7.3).

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
reviewer Reviewed-by
#25 lore raw

Re: [PATCH mptcp-net v3 11/50] mptcp: no sf left: process pending MP_FASTCLOSE

Hi Matt,

Quoted 63 lines · Matthieu Baerts

Hi Geliang,

Thank you for the review!

Quoted 52 lines · Geliang Tang

Hi Matt,

Quoted 49 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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")

---
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(+)
net/mptcp/protocol.c +0 -0
index 5d916c6b43f4..bcdad00d3573 100644
@@ -2705,6 +2705,8 @@ static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
 	mptcp_data_unlock(sk);
 }
 
Quoted 5 lines

net/mptcp/protocol.c static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk) · line 2709

Quoted 2 lines
net/mptcp/protocol.c +2 -0
+static void mptcp_check_fastclose(struct mptcp_sock *msk);
+

Would it be more appropriate to move the definition of mptcp_check_rcv_close() helper from patch 12 into this patch?

Quoted 4 lines

It's a good idea, but I prefer not to do that for net and keep the patch as small as possible. The patch 11/50 can be backported up to v5.10:
better to keep it small. While the next one is for v6.19 (so only backported to v7.3).

I agree.

Thanks,
-Geliang

Quoted 3 lines

Cheers,
Matt

author maintainer
#26 lore raw

PATCH v3 12/50 mptcp: no sf left: process pending DATA_FIN

In reply to 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")

---
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(-)
net/mptcp/protocol.c +13 -3
index bcdad00d3573..b57d0f82b416 100644
@@ -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);
Signature · 1 line
2.55.0
#27 lore raw

Re: [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN

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() --

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) <[email protected]>

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.

Quoted 24 lines
net/mptcp/protocol.c +12 -0
index bcdad00d35732..b57d0f82b416e 100644
@@ -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).
  *

net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2837

Quoted 10 lines
net/mptcp/protocol.c +1 -3
@@ -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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
author maintainer
#28 lore raw

Re: [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN

Hello,

Quoted 4 lines · On 24/11/2026 23:33, [email protected] wrote:
Quoted 4 lines
net/mptcp/protocol.c +0 -0
index bcdad00d35732..b57d0f82b416e 100644

(...)

Quoted 7 lines
Quoted 7 lines
net/mptcp/protocol.c +0 -3
@@ -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);
-
Quoted 8 lines

net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2837

Quoted 4 lines
net/mptcp/protocol.c +1 -0
+			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?

In ESTABLISHED, the DATA_FIN is processed when the backlog is spooled at the release of the socket: the reader gets the data, then EOF, and the close timeout closes the socket, as before. So no need to change if I'm not mistaken. I can clarify the commit message.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#29 lore raw

Re: [PATCH mptcp-net v3 12/50] mptcp: no sf left: process pending DATA_FIN

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] mptcp: pending DATA_FIN skipped for TCP_ESTABLISHED in __mptcp_close_ssk()
- [Low] The commit message's evidence does not test what this commit changes.

--

mptcp: no sf left: process pending DATA_FIN

This adds mptcp_check_rcv_close(). When the last subflow is closed, the helper spools the MPTCP-level backlog and processes a pending DATA_FIN, and a pending MP_FASTCLOSE, before __mptcp_close_ssk() moves the msk to TCP_CLOSE. Without it, RCV_SHUTDOWN is never set if the DATA_FIN was still waiting behind data in the backlog.

Quoted 3 lines

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:

[ ... ]

Quoted 4 lines

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:

[ ... ]

Quoted 5 lines

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:

[ ... ]

Quoted 5 lines

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.

[Severity: Low]
Do these reproducers actually run the code this commit adds? Every one of them is a fallback case.

For fallback, the earlier commit in this series, "mptcp: return EOF after a DATA_FIN, as TCP does", already does the same spool and check in mptcp_close_ssk(), just before it calls __mptcp_close_ssk():

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, MPTCP_CF_PUSH);
    ...
}

At that point the msk is still in FIN_WAIT1 or FIN_WAIT2. If the DATA_FIN can be processed, mptcp_check_data_fin() clears rcv_data_fin. The new mptcp_check_rcv_close() call in __mptcp_close_ssk() then reads rcv_data_fin as false and skips its own spool and check.

If the first attempt cannot process the DATA_FIN, nothing that happens before the second attempt changes that. No new data reaches the msk, so the same mptcp_move_skbs() + mptcp_check_data_fin() sequence gives the same result.

After a fallback, msk->first is the only subflow. The other direct callers of __mptcp_close_ssk() don't reach this branch with a pending DATA_FIN in a state where it could be processed. Those callers are the close-timeout path in mptcp_worker(), which runs after mptcp_do_fastclose(), and mptcp_destroy_common().

So in this series, the DATA_FIN part of the new helper seems to change behaviour only for non-fallback MPTCP connections. One example is FIN_WAIT2 after shutdown(SHUT_WR), with data and the DATA_FIN still in the msk backlog when the last subflow is removed by a reset or by the PM.

Could the commit message describe that non-fallback case instead? Could it also explain why mptcp_close_ssk() and mptcp_check_rcv_close() both do the same spool and DATA_FIN check?

The v2 note after the --- line mentions the earlier commit, but that note won't be kept in the git history. As written, "With the same debug patch, these subtests no longer failed" gives this commit credit for fixes the earlier commit already made.

[ ... ]

Quoted 5 lines

net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2837

Quoted 10 lines
net/mptcp/protocol.c +1 -3
@@ -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]
Does this still miss the DATA_FIN when the last subflow goes away while the msk is in TCP_ESTABLISHED?

mptcp_check_rcv_close() is only called from the branch taken when sk->sk_state != TCP_ESTABLISHED. But a DATA_FIN stuck behind data in msk->backlog_list is exactly what keeps the msk in TCP_ESTABLISHED instead of moving it to TCP_CLOSE_WAIT.

Take a non-fallback msk in TCP_ESTABLISHED that is not in the accept queue and not orphaned. The peer sends its last data and the DATA_FIN while mptcp_worker() owns the msk. mptcp_data_ready() queues the data on msk->backlog_list, so msk->ack_seq does not move. The last subflow is then reset or removed by the PM:

mptcp_worker()
mptcp_check_data_fin(sk)
ack_seq < rcv_data_fin_seq, state stays TCP_ESTABLISHED
__mptcp_close_subflow(sk)

    mptcp_close_ssk()
      no spool here, this is not a fallback socket
      __mptcp_close_ssk()
        sk_state == TCP_ESTABLISHED
        mptcp_start_tout_timer(sk)
release_sock(sk)
  mptcp_release_cb()
    spools msk->backlog_list
    mptcp_check_data_fin(sk)
      TCP_ESTABLISHED -> TCP_CLOSE_WAIT

At that point the msk has no usable subflow left. It is in TCP_CLOSE_WAIT without SEND_SHUTDOWN. Nothing re-evaluates the "all subflows closed" condition, because only __mptcp_close_ssk() does that. The msk is closed only when the close timeout fires, 60 seconds later by default.

Now suppose the same data had arrived while the msk was not owned. The DATA_FIN would have been processed first, so __mptcp_close_ssk() would have seen TCP_CLOSE_WAIT. The msk would then have been moved to TCP_CLOSE and woken up right away. So the outcome depends on whether the worker happened to own the socket. That is the same kind of timing dependency this commit is trying to remove.

Should the DATA_FIN part of mptcp_check_rcv_close() run before the sk->sk_state test? Then the choice between closing the msk and starting the timeout would be made on the state after the DATA_FIN has been processed. Or is staying in TCP_CLOSE_WAIT until the timeout intended here? If so, could the commit message say so?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#30 lore raw

PATCH v3 13/50 mptcp: process pending close events at accept()

In reply to 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")

---
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(-)
net/mptcp/protocol.c +3 -1
index b57d0f82b416..8edff68ec650 100644
@@ -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));
 		}
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 13/50
#31 lore raw

Re: [PATCH mptcp-net v3 13/50] mptcp: process pending close events at accept()

Hi Matt,

Quoted 23 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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.

Quoted 6 lines

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")

Looks good to me!

Thanks,
-Geliang

Quoted 26 lines

---
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(-)
net/mptcp/protocol.c +3 -1
index b57d0f82b416..8edff68ec650 100644
@@ -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));
 		}
author maintainer
#32 lore raw

PATCH v3 14/50 mptcp: report errors received before accept()

In reply to 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")

---
v3: new, for an issue spotted by Clashiko

---
 net/mptcp/protocol.c | 2 ++
 1 file changed, 2 insertions(+)
net/mptcp/protocol.c +2 -0
index 8edff68ec650..ff1dcf306723 100644
@@ -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,
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 14/50
#33 lore raw

Re: [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept()

Hi Matt,

Quoted 21 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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:

Quoted 4 lines

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")

Looks good to me!

Thanks,
-Geliang

Quoted 19 lines

---
v3: new, for an issue spotted by Clashiko

---
 net/mptcp/protocol.c | 2 ++
 1 file changed, 2 insertions(+)
net/mptcp/protocol.c +2 -0
index 8edff68ec650..ff1dcf306723 100644
@@ -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,
reviewer Reviewed-by on v3 14/50
#34 lore raw

Re: [PATCH mptcp-net v3 14/50] mptcp: report errors received before accept()

In reply to Matthieu Baerts (NGI0)

Hi Matt,

Quoted 21 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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:

Quoted 4 lines

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")

Looks good to me!

Thanks,
-Geliang

Quoted 19 lines

---
v3: new, for an issue spotted by Clashiko

---
 net/mptcp/protocol.c | 2 ++
 1 file changed, 2 insertions(+)
net/mptcp/protocol.c +2 -0
index 8edff68ec650..ff1dcf306723 100644
@@ -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,
author maintainer
#35 lore raw

PATCH v3 15/50 mptcp: clear sk_err on connect(), as TCP does

In reply to 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")

---
v2: new, for an issue found by a review agent

---
 net/mptcp/protocol.c | 2 ++
 1 file changed, 2 insertions(+)
net/mptcp/protocol.c +2 -0
index ff1dcf306723..6328815ad273 100644
@@ -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:
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 15/50
#36 lore raw

Re: [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does

Hi Matt,

Quoted 6 lines · 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.

Quoted 8 lines

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")

Thanks for this fix. Looks good to me!

Quoted 11 lines

---
v2: new, for an issue found by a review agent

---
 net/mptcp/protocol.c | 2 ++
 1 file changed, 2 insertions(+)
net/mptcp/protocol.c +0 -0
index ff1dcf306723..6328815ad273 100644

net/mptcp/protocol.c static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr, · line 4456

Quoted 5 lines
net/mptcp/protocol.c +2 -0
@@ -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

Quoted 3 lines
net/mptcp/protocol.c +0 -0
 	inet_assign_bit(DEFER_CONNECT, sk, inet_test_bit(DEFER_CONNECT, ssk));
 
 out:
author maintainer
#37 lore raw

Re: [PATCH mptcp-net v3 15/50] mptcp: clear sk_err on connect(), as TCP does

Hi Geliang,

Thank you for the review!

On 26/11/2026 07:40, Geliang Tang wrote:> Hi Matt,

Quoted 35 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:
Quoted 6 lines

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.

Quoted 8 lines

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")

Thanks for this fix. Looks good to me!

Quoted 14 lines

---
v2: new, for an issue found by a review agent

---
 net/mptcp/protocol.c | 2 ++
 1 file changed, 2 insertions(+)
net/mptcp/protocol.c +0 -0
index ff1dcf306723..6328815ad273 100644
@@ -4452,6 +4452,8 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
 	if (err < 0)
 		goto out;
 
Quoted 5 lines

net/mptcp/protocol.c static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr, · line 4456

Quoted 2 lines
net/mptcp/protocol.c +2 -0
+	/* 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

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#38 lore raw

PATCH v3 16/50 mptcp: clear DEFER_CONNECT on disconnect

In reply to 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")

---
v2: new, for an issue found by a review agent

---
 net/mptcp/protocol.c | 1 +
 1 file changed, 1 insertion(+)
net/mptcp/protocol.c +1 -0
index 6328815ad273..257c851c8a76 100644
@@ -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.
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 16/50
#39 lore raw

Re: [PATCH mptcp-net v3 16/50] mptcp: clear DEFER_CONNECT on disconnect

Hi Matt,

Quoted 20 lines · 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:

Quoted 4 lines

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")

Looks good to me, thanks.

Quoted 18 lines

---
v2: new, for an issue found by a review agent

---
 net/mptcp/protocol.c | 1 +
 1 file changed, 1 insertion(+)
net/mptcp/protocol.c +1 -0
index 6328815ad273..257c851c8a76 100644
@@ -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.
author maintainer
#40 lore raw

PATCH v3 17/50 mptcp: report sf aborts during deferred connect

In reply to 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().")

---
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(-)
net/mptcp/protocol.c +13 -2
index 257c851c8a76..87f6da0f6cab 100644
@@ -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);
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 17/50
#41 lore raw

Re: [PATCH mptcp-net v3 17/50] mptcp: report sf aborts during deferred connect

Hi Matt,

Quoted 43 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

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.

Quoted 6 lines

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().")

It took me a bit of time to understand this patch. Looks good to me!

Thanks,
-Geliang

Quoted 41 lines

---
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(-)
net/mptcp/protocol.c +13 -2
index 257c851c8a76..87f6da0f6cab 100644
@@ -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);
author maintainer
#42 lore raw

PATCH v3 18/50 mptcp: no fastclose reset from SYN_SENT subflows

In reply to 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")

---
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(+)
net/mptcp/protocol.c +6 -0
index 87f6da0f6cab..6c712f677220 100644
@@ -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().
 		 */
Signature · 1 line
2.55.0
reviewer
#43 lore raw

Re: [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows

Hi Matt,

Quoted 36 lines · 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")

---
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(+)
net/mptcp/protocol.c +0 -0
index 87f6da0f6cab..6c712f677220 100644

net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3329

Quoted 9 lines
net/mptcp/protocol.c +6 -0
@@ -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

Quoted 3 lines
net/mptcp/protocol.c +0 -0
 		/* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
 		 * issue in __tcp_select_window(), see tcp_disconnect().
 		 */
author maintainer
#44 lore raw

Re: [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows

Hi Geliang,

Thank you for the reviews!

Quoted 51 lines · Geliang Tang

Hi Matt,

Quoted 36 lines · 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")

---
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(+)
net/mptcp/protocol.c +0 -0
index 87f6da0f6cab..6c712f677220 100644

net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3329

Quoted 9 lines
net/mptcp/protocol.c +6 -0
@@ -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

Quoted 8 lines
		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

Signature · 1 line
Sponsored by the NGI0 Core fund.
reviewer Reviewed-by
#45 lore raw

Re: [PATCH mptcp-net v3 18/50] mptcp: no fastclose reset from SYN_SENT subflows

Quoted 65 lines · Matthieu Baerts

Hi Geliang,

Thank you for the reviews!

Quoted 51 lines · Geliang Tang

Hi Matt,

Quoted 36 lines · 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")

---
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(+)
net/mptcp/protocol.c +0 -0
index 87f6da0f6cab..6c712f677220 100644

net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3329

Quoted 9 lines
net/mptcp/protocol.c +6 -0
@@ -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

Quoted 8 lines
		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?

Quoted 7 lines

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.

Thanks,
-Geliang

Quoted 3 lines

Cheers,
Matt

author maintainer
#46 lore raw

PATCH v3 19/50 mptcp: fastopen: keep listeners and connections

In reply to 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")

---
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(-)
net/mptcp/protocol.c +4 -1
index 6c712f677220..d529cfb582a5 100644
@@ -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++;
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 19/50
#47 lore raw

Re: [PATCH mptcp-net v3 19/50] mptcp: fastopen: keep listeners and connections

Hi Matt,

Quoted 24 lines · 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:

Quoted 4 lines

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")

Looks good. Thanks!

Quoted 33 lines

---
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(-)
net/mptcp/protocol.c +4 -1
index 6c712f677220..d529cfb582a5 100644
@@ -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++;
author maintainer
#48 lore raw

PATCH v3 20/50 mptcp: don't inherit fastopening from a listener

In reply to 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")

---
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(+)
net/mptcp/protocol.c +1 -0
index d529cfb582a5..b1072123397f 100644
@@ -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);
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 20/50
#49 lore raw

Re: [PATCH mptcp-net v3 20/50] mptcp: don't inherit fastopening from a listener

Hi Matt,

Quoted 15 lines · 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:

Quoted 4 lines

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")

Looks good! Thanks.

Quoted 19 lines

---
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(+)
net/mptcp/protocol.c +1 -0
index d529cfb582a5..b1072123397f 100644
@@ -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);
author maintainer
#50 lore raw

PATCH v3 21/50 mptcp: drop non-MP_JOIN cookie ACKs on PM listeners

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ 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. ]

---
v3: commit msg: the netns pinned by the queued children (Clashiko)

---
 net/mptcp/subflow.c | 5 +++++
 1 file changed, 5 insertions(+)
net/mptcp/subflow.c +5 -0
index 67a749643ad7..91698d154c40 100644
@@ -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;
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 21/50
#51 lore raw

Re: [PATCH mptcp-net v3 21/50] mptcp: drop non-MP_JOIN cookie ACKs on PM listeners

Hi Matt,

Quoted 47 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

From: Chris Mason <[email protected]>

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

Quoted 6 lines
Fixes 1729cf186d8a ("mptcp: create the listening socket for new port")

[ 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. ]

Looks good to me!

Thanks,
-Geliang

Quoted 22 lines

---
v3: commit msg: the netns pinned by the queued children (Clashiko)

---
 net/mptcp/subflow.c | 5 +++++
 1 file changed, 5 insertions(+)
net/mptcp/subflow.c +5 -0
index 67a749643ad7..91698d154c40 100644
@@ -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;
author maintainer
#52 lore raw

PATCH v3 22/50 mptcp: close a subflow reset for a bad mapping

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ 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. ]

---
v2: commit msg: the reset after a bad checksum too (Sashiko)

---
 net/mptcp/subflow.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/subflow.c +3 -2
index 91698d154c40..a216d88d35ee 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.55.0
reviewer Reviewed-by on v3 22/50
#53 lore raw

Re: [PATCH mptcp-net v3 22/50] mptcp: close a subflow reset for a bad mapping

Hi Matt,

Quoted 27 lines · On Tue, 2026-11-24 at 22:59 +0100, Matthieu Baerts (NGI0) wrote:

From: Chris Mason <[email protected]>

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:

Quoted 8 lines

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")

[ 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. ]

Looks good to me!

Thanks,
-Geliang

Quoted 29 lines

---
v2: commit msg: the reset after a bad checksum too (Sashiko)

---
 net/mptcp/subflow.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/subflow.c +3 -2
index 91698d154c40..a216d88d35ee 100644
@@ -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;
 		}
 	}
author maintainer
#54 lore raw

PATCH v3 23/50 mptcp: pm: kernel: count endpoint listeners as sockets in use

In reply to Matthieu Baerts (NGI0)

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")

---
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(-)
net/mptcp/pm_kernel.c +8 -1
index 2680d4672d58..73261685ae4c 100644
@@ -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,
Signature · 1 line
2.55.0
author maintainer
#55 lore raw

PATCH v3 24/50 mptcp: count a listener once when listen() is called again

In reply to 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")

---
v2: commit message: explain the two Fixes tags

---
 net/mptcp/protocol.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +4 -1
index b1072123397f..c57bfedc86a8 100644
@@ -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);
Signature · 1 line
2.55.0
author maintainer
#56 lore raw

PATCH v3 25/50 mptcp: send the infinite map in a single segment

In reply to 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")

---
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(+)
net/mptcp/protocol.c +6 -0
index c57bfedc86a8..39490ff40aa4 100644
@@ -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
Signature · 1 line
2.55.0
#57 lore raw

Re: [PATCH mptcp-net v3 25/50] mptcp: send the infinite map in a single segment

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The new cap in mptcp_sendmsg_frag() (net/mptcp/protocol.c:1489-1490, copy = info->mss_now while…

--

mptcp: send the infinite map in a single segment

After an MP_FAIL with a single subflow, the skb carrying the infinite mapping could be sized from the pre-fallback size goal. Its segments then grew past the MTU once the post-fallback MSS stopped reserving room for the DSS option. This patch caps the copy size to mss_now while send_infinite_map is set, so the infinite mapping is sent in a single segment.

Quoted 6 lines
net/mptcp/protocol.c +0 -0
index c57bfedc86a84..39490ff40aa4f 100644
@@ -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);

net/mptcp/protocol.c static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, · line 1493

Quoted 10 lines
net/mptcp/protocol.c +6 -0
 	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) {

[Severity: Medium]
Does lowering copy here stop the "Infinite map" subtest from reaching the InfiniteMapRx check it is meant to fix?

Before this patch, an unsent write queue tail with
mss_now <= skb->len < size_goal still passed the copy > skb->len test, and the infinite mapping was put on that tail. With the cap, such a tail fails the test, a new skb is allocated, and mptcp_update_infinite_map() makes the msk fall back right away.

After that, mptcp_established_options() in net/mptcp/options.c skips every skb other than the infinite-map one:

	if (unlikely(__mptcp_check_fallback(msk) && !mptcp_check_infinite_map(skb)))
		return 0;

So the tail, whose mpext still has a normal mapping, goes out with no DSS option.

On the receiver, get_mapping_status() in net/mptcp/subflow.c sees data with no DSS and !map_valid, and returns MAPPING_NODSS. subflow_check_data_avail() then falls back via MPTCP_MIB_DSSFALLBACK.

When the infinite-map segment arrives later, get_mapping_status() returns early:

	if (mptcp_check_fallback(ssk))
		return MAPPING_DUMMY;

That return comes before the data_len == 0 branch that increments MPTCP_MIB_INFINITEMAPRX.

The sender counts InfiniteMapTx=1 and the receiver counts InfiniteMapRx=0. mptcp_join.sh fail_tests() still expects:

	join_fail_nr=1 join_rst_nr=0 join_infi_nr=1 \

Would this sub-case then hit the same failure the commit message quotes as the flaky symptom?

infi rx server [FAIL] got 0 infinite map[s] RX expected 1

The fb_dss check would still pass, because the NODSS path uses the same DSSFALLBACK counter.

The subtest pushes 128KB in bulk, and the trace in the commit message shows notsent:98333. An unsent tail larger than one MSS when MP_FAIL arrives therefore seems plausible.

The commit message does describe the side effect:

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.

It doesn't say that this path leaves the receiver's InfiniteMapRx at 0, which keeps the cited selftest check failing. In this case the fallback is also signalled on the wire by data without a DSS option, not by the infinite mapping.

Would it make sense to keep putting the infinite mapping on such a tail, for example by splitting it at mss_now? Alternatively, could the selftest expectations and the commit message cover this case?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#58 lore raw

PATCH v3 26/50 mptcp: keep room for infinite map after fallback

In reply to 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")

---
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(-)
net/mptcp/options.c +4 -2
index 736e55532296..6b1a3994fb49 100644
@@ -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)) {
Signature · 1 line
2.55.0
#59 lore raw

Re: [PATCH mptcp-net v3 26/50] mptcp: keep room for infinite map after fallback

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The comment in mptcp_sendmsg_frag() (net/mptcp/protocol.c) is now misleading in the very case this patch fixes.

--

mptcp: keep room for infinite map after fallback

After an MP_FAIL, the msk can fall back to TCP before the infinite mapping has been sent. The next skb was then sized without room for the DSS option and ended up larger than the MTU. This patch keeps the DSS room in the MSS computation while send_infinite_map is set, until the skb carrying the infinite mapping has been created.

Quoted 6 lines
net/mptcp/options.c +0 -0
index 736e55532296b..6b1a3994fb494 100644
@@ -891,9 +891,11 @@ int mptcp_established_options(struct sock *sk, struct sk_buff *skb,
 	opts->suboptions = 0;

net/mptcp/options.c int mptcp_established_options(struct sock *sk, struct sk_buff *skb, · line 899

Quoted 10 lines
net/mptcp/options.c +4 -2
 
 	/* 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;

[Severity: Low]

This isn't a bug, but does this change make the comment in mptcp_sendmsg_frag() in net/mptcp/protocol.c misleading?

net/mptcp/protocol.c:mptcp_sendmsg_frag() {
    ...
	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;
    ...
}

With this patch, the MSS path (skb == NULL, via tcp_send_mss() -> tcp_current_mss() -> tcp_established_options()) keeps the DSS room after a fallback as long as send_infinite_map is set.

Take the early fallback case from the commit message, where the msk falls back after receiving data without DSS while the infinite mapping is still pending. Here info->mss_now does include the DSS option, even though the msk has already fallen back.

The single-segment cap is still needed, but for another reason. Once mptcp_update_infinite_map() clears send_infinite_map later in this function, later MSS computations no longer include the DSS room. That covers tcp_write_xmit(), tcp_current_mss() and retransmits. The comment does not say this.

The code under this comment is the same at the end of the series. Only "&& !old_data_pending" is added to the condition.

Could the comment be reworded, for example:

	/* Once the infinite mapping is sent, the MSS no longer includes its
	 * DSS option: send it in a single segment.
	 */
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#60 lore raw

PATCH v3 27/50 mptcp: do not fallback while old data is in flight

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ 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. ]

---
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(-)
net/mptcp/options.c +6 -0
index 6b1a3994fb49..9133e3d6e5d9 100644
@@ -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
 	 */
net/mptcp/protocol.c +18 -2
index 39490ff40aa4..7df5a2863555 100644
@@ -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;
net/mptcp/protocol.h +8 -1
index 888ee9d66967..6dbd912e08d8 100644
@@ -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;
 
Signature · 1 line
2.55.0
author maintainer
#61 lore raw

PATCH v3 28/50 mptcp: stop resending data to a peer that fell back

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ 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. ]

---
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(-)
net/mptcp/mib.h +1 -1
index 1ebdb55e9534..34a065b9e8dd 100644
@@ -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 */
net/mptcp/options.c +10 -6
index 9133e3d6e5d9..f9b65d0c6290 100644
@@ -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;
net/mptcp/protocol.c +20 -1
index 7df5a2863555..61cc4ae2a7b8 100644
@@ -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;
net/mptcp/protocol.h +1 -1
index 6dbd912e08d8..dfeabe03180b 100644
@@ -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;
Signature · 1 line
2.55.0
author maintainer
#62 lore raw

PATCH v3 29/50 mptcp: don't resend data acked without MPTCP opts

In reply to 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")

---
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(-)
net/mptcp/options.c +14 -5
index f9b65d0c6290..05b9c66aaed6 100644
@@ -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) &&
net/mptcp/protocol.c +8 -3
index 61cc4ae2a7b8..f3dd15293bc8 100644
@@ -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;
net/mptcp/protocol.h +2 -0
index dfeabe03180b..d0ae782c9ade 100644
@@ -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 */
net/mptcp/subflow.c +2 -0
index a216d88d35ee..3590c1207e88 100644
@@ -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
Signature · 1 line
2.55.0
#63 lore raw

Re: [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts

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 --

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) <[email protected]>

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.

Quoted 4 lines
net/mptcp/options.c +0 -0
index f9b65d0c6290a..05b9c66aaed63 100644

[ ... ]

Quoted 9 lines
net/mptcp/options.c +0 -5
@@ -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;

net/mptcp/options.c bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) · line 1303

Quoted 10 lines
net/mptcp/options.c +10 -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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
author maintainer
#64 lore raw

Re: [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts

Quoted 22 lines · On 24/11/2026 23:36, [email protected] wrote:
Quoted 4 lines
net/mptcp/options.c +0 -0
index f9b65d0c6290a..05b9c66aaed63 100644

[ ... ]

Quoted 15 lines
net/mptcp/options.c +6 -5
@@ -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;
Quoted 8 lines

net/mptcp/options.c bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) · line 1303

Quoted 4 lines
net/mptcp/options.c +4 -0
+		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?

The push done there for a TFO child only sends new data: no resend nor probe, so no reset. No need to change, but I can clarify the commit message.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#65 lore raw

Re: [PATCH mptcp-net v3 29/50] mptcp: don't resend data acked without MPTCP opts

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In net/mptcp/protocol.c, mptcp_sendmsg_frag() (lines 1566-1568) used to reset the subflow under `before64(data_seq, msk->snd_nxt) &&…
- [Low] For a passive MP_JOIN, MPTCP_JOINED is only set by mptcp_subflow_joined(), called from __mptcp_finish_join().

--

mptcp: don't resend data acked without MPTCP opts

This patch adds opt_ack_seq, a per-subflow field that tracks the highest TCP ack_seq received with MPTCP options. Data acked without MPTCP options now makes the subflow reset instead of being resent at the MPTCP level. The check only applies until a new MPTCP_JOINED msk flag gets set, which happens once an MP_JOIN subflow has been established.

net/mptcp/protocol.c static void mptcp_subflow_joined(struct mptcp_sock *msk, struct sock *ssk) · line 1097

Quoted 13 lines
net/mptcp/protocol.c +3 -0
index 61cc4ae2a7b81..f3dd15293bc8c 100644
@@ -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);
 }

[Severity: Low]
For a passive MP_JOIN, is this the only place where MPTCP_JOINED gets set? If the user owns the msk when the third ACK arrives, mptcp_finish_join() only queues the subflow:

net/mptcp/protocol.c:mptcp_finish_join() {
    ...
	} else {
		sock_hold(ssk);
		list_add_tail(&subflow->node, &msk->join_list);
		__set_bit(MPTCP_FLUSH_JOIN_LIST, &msk->cb_flags);
    ...
}

mptcp_subflow_joined() then runs only later, through mptcp_release_cb()->__mptcp_flush_join_list().

Until then, code running under the same ownership can still call mptcp_sendmsg_frag() on the first subflow while MPTCP_JOINED is clear. Two examples are mptcp_worker()->__mptcp_retrans() and a zero window probe from the sendmsg path.

Suppose the peer already considers the join established and leaves out a Data ACK that does not advance on the first subflow. The commit message says RFC 8684 section 3.3.2 allows this after a join. tcp_ack() then moves snd_una, but opt_ack_seq does not move.

Would mptcp_sendmsg_frag() then reset the first subflow with MPTCP_RST_EMIDDLEBOX and increment MPTCP_MIB_FALLBACKFAILED, even though a join has already been accepted?

The window is narrow. It needs the msk lock to be held across a round trip, and a non-Linux peer that leaves out non-advancing Data ACKs only after a join. mptcp_release_cb() flushes the join list before it handles PUSH_PENDING and RETRANSMIT, so the release path itself looks correctly ordered.

[ ... ]

net/mptcp/protocol.c static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, · line 1568

Quoted 13 lines
net/mptcp/protocol.c +5 -3
@@ -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))) {

[Severity: Low]
This isn't a bug, but could the commit message say that this also changes what the previous commit added in "mptcp: stop resending data to a peer that fell back"?

The old condition reset the subflow for data that had already been resent and was then acked without MPTCP options. It did this whether or not any join had happened.

This patch drops the old_data_pending term and gates the whole check on MPTCP_JOINED. After an MP_JOIN subflow is established, that reset no longer happens, and the data is resent again.

The commit message says:

Only before any MP_JOIN subflow has been established
...
Two other new tests check that this data is still resent after a join,

It doesn't say that the reset for data that was already resent is now also skipped after a join. The code itself looks fine; this is only about the description.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#66 lore raw

PATCH v3 30/50 mptcp: pm: kernel: don't count signal+subflow ID 0 endp

In reply to Matthieu Baerts (NGI0)

From: Josef Bacik <[email protected]>

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")

[ Keep the original one-line comment. Commit message: 'behind it' ->
'after it' + how the issue was found, and its symptoms. ]

---
 net/mptcp/pm_kernel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/pm_kernel.c +4 -2
index 73261685ae4c..47c6ccb0a29e 100644
@@ -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);
Signature · 1 line
2.55.0
author maintainer
#67 lore raw

PATCH v3 31/50 selftests: mptcp: join: check re-adding signal+subflow ID 0 endp

In reply to 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")

---
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(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +11 -2
index c3ccce96b45b..4c045532f137 100755
@@ -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
 
Signature · 1 line
2.55.0
author maintainer
#68 lore raw

PATCH v3 32/50 mptcp: reclaim forward memory after coalescing skbs

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ Shorter comment. Commit message: the rest of the borrowed amount has
to be released + how the issue was found, and its symptoms. ]

---
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(+)
net/mptcp/protocol.c +6 -0
index f3dd15293bc8..f8cb585da0b3 100644
@@ -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,
Signature · 1 line
2.55.0
author maintainer
#69 lore raw

PATCH v3 33/50 mptcp: don't charge a shared page twice at accept()

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]

---
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(-)
net/mptcp/protocol.c +20 -1
index f8cb585da0b3..504fe4a9954f 100644
@@ -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);
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 33/50
#70 lore raw

Re: [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept()

Quoted 52 lines · On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:

From: Chris Mason <[email protected]>

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")

[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]

---
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(-)
net/mptcp/protocol.c +0 -0
index f8cb585da0b3..504fe4a9954f 100644

net/mptcp/protocol.c static int mptcp_listen(struct socket *sock, int backlog) · line 4667

Quoted 4 lines
net/mptcp/protocol.c +1 -0
@@ -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.

Quoted 47 lines
net/mptcp/protocol.c +19 -1
+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);
Signature · 1 line
2.55.0
author maintainer
#71 lore raw

Re: [PATCH mptcp-net v3 33/50] mptcp: don't charge a shared page twice at accept()

Hi Mat,

Thank you for the reviews!

Quoted 60 lines · Mat Martineau
Quoted 58 lines · On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:

From: Chris Mason <[email protected]>

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")

[ Shorter comment. Commit message: how the issue was found, and its symptoms. ]

---
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(-)
net/mptcp/protocol.c +0 -0
index f8cb585da0b3..504fe4a9954f 100644
@@ -4664,10 +4664,26 @@ static int mptcp_listen(struct socket *sock,
 int backlog)
     return err;
 }
 
Quoted 5 lines

net/mptcp/protocol.c static int mptcp_listen(struct socket *sock, int backlog) · line 4667

Quoted 1 line
net/mptcp/protocol.c +1 -0
+/* 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.

Good idea! The v4 will contain:

/* Similar to __sk_charge(), but the msk and its subflows share pages */

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#72 lore raw

PATCH v3 34/50 mptcp: don't charge the backlog twice at accept()

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ 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. ]

---
 net/mptcp/protocol.c | 35 +----------------------------------
 net/mptcp/protocol.h |  1 -
 2 files changed, 1 insertion(+), 35 deletions(-)
net/mptcp/protocol.c +1 -34
index 504fe4a9954f..c9ef23276399 100644
@@ -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,
net/mptcp/protocol.h +0 -1
index d0ae782c9ade..9a9dbab672af 100644
@@ -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)
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 34/50
#73 lore raw

Re: [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog twice at accept()

Quoted 28 lines · On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:

From: Chris Mason <[email protected]>

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:

Quoted 7 lines

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.

Quoted 100 lines

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")

[ 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. ]

---
net/mptcp/protocol.c | 35 +---------------------------------- net/mptcp/protocol.h | 1 -

2 files changed, 1 insertion(+), 35 deletions(-)
net/mptcp/protocol.c +0 -0
index 504fe4a9954f..c9ef23276399 100644
@@ -802,12 +802,6 @@ static void __mptcp_add_backlog(struct sock *sk,
 

account:

	WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
net/mptcp/protocol.c +0 -6
-
-	/* 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,

net/mptcp/protocol.c +1 -8
@@ -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);
	}
net/mptcp/protocol.c +0 -20
-
-	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,

net/mptcp/protocol.h +0 -1
index d0ae782c9ade..9a9dbab672af 100644
@@ -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)
Signature · 2 lines
-- 
2.55.0
author maintainer
#74 lore raw

Re: [PATCH mptcp-net v3 34/50] mptcp: don't charge the backlog twice at accept()

Hi Mat,

Thank you for the review!

Quoted 36 lines · Mat Martineau
Quoted 34 lines · On Tue, 24 Nov 2026, Matthieu Baerts (NGI0) wrote:

From: Chris Mason <[email protected]>

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 [...]

Quoted 8 lines
Quoted 3 lines

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.

Yes, that was not clear what I added :)

I just re-checked Chris' repro, and I meant to say 20,000 one-byte segments that are new for TCP but all have the same data seq number.

I will replace this paragraph with:

And about 12 MB with only 50 connections, each getting 20,000 one-byte segments before accept(), new for TCP but with the same data sequence number, so the msk drops them as duplicates. Bare ACKs with RM_ADDR, sent at the same time, make the MPTCP worker take the socket lock, so that some of these segments go through the backlog: (...)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#75 lore raw

PATCH v3 35/50 mptcp: don't charge a subflow twice when it joins during accept()

In reply to 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")

---
v2: update a comment (Clashiko)

---
 net/mptcp/protocol.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +4 -3
index c9ef23276399..8017f8775728 100644
@@ -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);
Signature · 1 line
2.55.0
author maintainer
#76 lore raw

PATCH v3 36/50 mptcp: continue the last mapping after a fallback

In reply to Matthieu Baerts (NGI0)

From: Chris Mason <[email protected]>

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")

[ 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. ]

---
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(-)
net/mptcp/protocol.h +8 -1
index 9a9dbab672af..7cdd0a7e8296 100644
@@ -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;
net/mptcp/subflow.c +18 -3
index 3590c1207e88..f73e4b8deca4 100644
@@ -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;
 }
Signature · 1 line
2.55.0
#77 lore raw

Re: [PATCH mptcp-net v3 36/50] mptcp: continue the last mapping after a fallback

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] After this patch, a dummy mapping always continues in a straight line from the last mapping that went through…

--

mptcp: continue the last mapping after a fallback

After a fallback, this commit builds the dummy mapping from the peer's last valid mapping (dsn_base) and no longer from iasn. Zero window probes and reinjections therefore stop pushing later data into the out-of-order queue. It also tracks the highest end of the peer's mappings (dsn_end), and mptcp_try_fallback() now fails while the last mapping ends below it.

Quoted 4 lines
net/mptcp/subflow.c +0 -0
index 3590c1207e88b..f73e4b8deca42 100644

[ ... ]

net/mptcp/subflow.c static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk) · line 1449

Quoted 11 lines
net/mptcp/subflow.c +7 -0
@@ -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);

[Severity: Medium]

Can a resend that ends exactly at dsn_end still get stale bytes delivered as new data?

A zero window probe, or a reinjection of the stream tail, ends exactly at dsn_end, so before(end, subflow->dsn_end) is false. map_old stays 0, so mptcp_try_fallback() still allows the fallback, and dsn_base is rebased onto the resend.

Now say the next resend of the same byte has its DSS stripped. get_mapping_status() returns MAPPING_NODSS, or the infinite mapping status, and subflow_check_data_avail() jumps to the fallback label. That segment is never compared with dsn_end. Its dummy mapping is then:

    subflow->dsn_base + subflow->map_subflow_seq - 1

That value is msk->ack_seq, so __mptcp_move_skb() delivers the stale byte in order. Using the notation from the commit message:

    data     SSN 1 to 1000   DSN iasn to iasn + 999
    probe 1  SSN 1001        DSN iasn + 999 with DSS, map_old = 0
    probe 2  SSN 1002        no DSS, dummy DSN iasn + 1000, delivered
    probe 3  SSN 1003        no DSS, dummy DSN iasn + 1001, delivered

Probes 2 and 3 carry the byte at iasn + 999 again, and the application reads them as new data with no error. The old iasn + SSN - 1 formula sent probe 2 to the out-of-order queue, so the reader stalled instead.

The commit message covers this with:

"unless the sender resets the subflow before, as it does since "mptcp: don't resend data acked without MPTCP opts""

A fully patched Linux sender does reset first for a repeated probe, via the check in mptcp_sendmsg_frag(). Older kernels and other MPTCP stacks do not. Even a patched sender still allows the first MPTCP-level retransmission of data that was acked with MPTCP options. After an earlier probe or reinjection, that case also goes from a stall to a duplicate.

The last patch of the series, "mptcp: reset when the DSS disappears after a DATA_ACK", only covers this when the receiver's own data was DATA_ACKed:
subflow_nodss_is_fatal() requires dss_confirmed. It also skips MAPPING_INFINITE, and it has no Fixes: tag. A stable tree that picks up this patch through its Fixes: tag would turn a visible hang into silent stream corruption against non-resetting peers, without that mitigation.

Could the receiver also treat a mapping that ends exactly at dsn_end, and re-maps data at or below ack_seq, as old? If not, could the commit message say that this safety depends on the remote kernel or stack? Today only the note below the '---' line mentions "e.g. with an older kernel", and that note is dropped when the patch is applied.

Quoted 3 lines
net/mptcp/subflow.c +3 -0
+	if (!subflow->map_old)
+		subflow->dsn_end = end;
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#78 lore raw

PATCH v3 37/50 mptcp: keep the first byte after a simult connect

In reply to 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")

---
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(-)
net/mptcp/options.c +5 -0
index 05b9c66aaed6..41eb39968a9a 100644
@@ -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));
net/mptcp/subflow.c +3 -1
index f73e4b8deca4..439a11d92281 100644
@@ -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);
Signature · 1 line
2.55.0
#79 lore raw

Re: [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect

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 --

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) <[email protected]>

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.

Quoted 6 lines
net/mptcp/options.c +0 -0
index 05b9c66aaed63..41eb39968a9a6 100644
@@ -474,6 +474,11 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 	 * in mptcp_established_options_mp()

net/mptcp/options.c bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb, · line 484

Quoted 10 lines
net/mptcp/options.c +5 -0
 	 */
 	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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=37
#80 lore raw

Re: [PATCH mptcp-net v3 37/50] mptcp: keep the first byte after a simult connect

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The fix is incomplete: there is still a simultaneous-connect path where ssn_offset ends up wrong, and on that path the patch makes…
- [Medium] mptcp: mptcp_syn_options() sets ssn_offset on MP_JOIN simult connect

--

mptcp: keep the first byte after a simult connect

After a simultaneous connect, this patch sets subflow->ssn_offset in mptcp_syn_options() when the crossed SYN-ACK is sent from SYN_RECV. subflow_finish_connect() now takes ssn_offset only from a SYN. The first non-SYN packet received in ESTABLISHED no longer overwrites it, so the first received byte is kept.

Quoted 21 lines
net/mptcp/options.c +5 -0
index 05b9c66aaed63..41eb39968a9a6 100644
@@ -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));
net/mptcp/subflow.c +0 -0
index f73e4b8deca42..439a11d92281b 100644

net/mptcp/subflow.c static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) · line 596

Quoted 7 lines
net/mptcp/subflow.c +3 -1
@@ -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;

[Severity: Medium]
Does this assignment also need to be limited to the MPC case?

It is done for any subflow in TCP_SYN_RECV, before the request_mptcp check. An active MP_JOIN subflow created by __mptcp_subflow_connect() (request_join = 1, remote_key_valid = 1, mp_join = 0) can also receive a crossed bare SYN while in TCP_SYN_SENT. tcp_rcv_synsent_state_process() then sets rcv_nxt to the peer ISN + 1, moves the socket to TCP_SYN_RECV and calls tcp_send_synack(). That ends up here, so ssn_offset now becomes the peer ISN on the join subflow. This path has no fallback and no reset, because subflow_simultaneous_connect() is only checked under request_mptcp.

Suppose the peer then sends an ACK with seq == ssn_offset + 1. tcp_rcv_state_process() moves the subflow from TCP_SYN_RECV to TCP_ESTABLISHED without going through sk_rx_dst_set(), so subflow_finish_connect() never validates the MP_JOIN handshake. The same skb then goes through tcp_data_queue() -> mptcp_incoming_options() -> check_fully_established().

Before this patch, ssn_offset was still 0 at that point, so the "TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1" test returned early. Now the test passes with mp_join == 0, and there are three outcomes:

- If the ACK carries a DSS with use_ack, or a non-echo ADD_ADDR, the remote_key_valid check jumps to set_fully_established without any HMAC validation. Any payload then triggers the WARN_ON_ONCE() in subflow_data_ready(), because neither mp_capable nor mp_join is set.

- If the ACK carries no MPTCP option, the subflow is not reset because mp_join is 0. Instead, mptcp_try_fallback(ssk, MPTCP_MIB_MPCAPABLEDATAFALLBACK) can make the parent msk fall back to TCP while allow_infinite_fallback is still true.

- If the ACK carries an MP_CAPABLE option on a client msk, it triggers WARN_ONCE(1, "bogus mpc option on established client sk").

A remote peer can drive all of this by crossing a SYN with one of our MP_JOIN SYNs.

Should the new ssn_offset assignment move under the request_mptcp && subflow_simultaneous_connect() branch, where the fallback is actually done? Or should an MP_JOIN subflow hitting a simultaneous connect be reset instead?

[Severity: High]
Can ssn_offset stay at 0 here after a simultaneous connect?

With this change, mptcp_syn_options() is the only place that sets ssn_offset for a simultaneous connect. It only runs if the crossed SYN-ACK gets far enough to build its options. The return value of tcp_send_synack() is ignored by its caller:

net/ipv4/tcp_input.c:tcp_rcv_synsent_state_process() {
    ...
		tcp_send_synack(sk);
    ...
}

tcp_send_synack() can fail before any option is built:

net/ipv4/tcp_output.c:tcp_send_synack() {
    ...
			nskb = skb_copy(skb, GFP_ATOMIC);
			...
			if (!nskb)
				return -ENOMEM;
    ...
}

The clone or copy in __tcp_transmit_skb() can also return -ENOBUFS before tcp_syn_options() is reached.

When that happens, neither the new ssn_offset assignment nor the SIMULTCONN fallback runs. Suppose the peer's crossed SYN-ACK then moves the socket to ESTABLISHED before the RTO retransmits our SYN-ACK. The next skb that subflow_finish_connect() sees is not a SYN, so ssn_offset keeps its initial value of 0.

The later "mptcp: move to ESTABLISHED after a simult connect" change in subflow_state_change() only applies when mptcp_check_fallback(sk) is already true. It doesn't set ssn_offset either, so this path still seems reachable at the end of the series.

With ssn_offset at 0, the fallback dummy mapping in subflow_check_data_avail() becomes:

	subflow->map_subflow_seq = TCP_SKB_CB(skb)->seq - subflow->ssn_offset;
	subflow->map_seq = __mptcp_expand_seq(subflow->map_seq,
					      subflow->dsn_base +
					      subflow->map_subflow_seq - 1);

Every mapping is then off by the peer's ISN relative to msk->ack_seq, which starts at 0 after the fallback.

Would the received data then be dropped as old, or left in the msk out-of-order queue forever? It has already been acked at the TCP level, so it would not be retransmitted.

Before this patch, this path lost one byte. After it, the whole receive stream looks like it could be lost.

The v2 note below the '---' calls the allocation failure case theoretical, but that note won't end up in the commit message.

Could subflow_finish_connect() keep a fallback assignment for non-SYN skbs on this path? Another option would be to derive the peer ISN once the socket reaches ESTABLISHED.

Quoted 3 lines
net/mptcp/subflow.c +0 -0
 	pr_debug("subflow=%p synack seq=%x\n", subflow, subflow->ssn_offset);
 
 	mptcp_get_options(skb, &mp_opt);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#81 lore raw

PATCH v3 38/50 mptcp: move to ESTABLISHED after a simult connect

In reply to 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")

---
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(+)
net/mptcp/subflow.c +13 -0
index 439a11d92281..190c75311ff6 100644
@@ -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.
Signature · 1 line
2.55.0
author maintainer
#82 lore raw

PATCH v3 39/50 mptcp: fix MSG_PEEK after a partly peeked skb

In reply to 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")

---
v2: new, for an issue causing a flaky selftest

---
 net/mptcp/protocol.c | 1 +
 1 file changed, 1 insertion(+)
net/mptcp/protocol.c +1 -0
index 8017f8775728..0ff84d9684f1 100644
@@ -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);
Signature · 1 line
2.55.0
author maintainer
#83 lore raw

PATCH v3 40/50 mptcp: send the DATA_ACK after moving the backlog

In reply to 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")

---
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(+)
net/mptcp/protocol.c +17 -0
index 0ff84d9684f1..2f89719e8454 100644
@@ -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);
Signature · 1 line
2.55.0
#84 lore raw

Re: [PATCH mptcp-net v3 40/50] mptcp: send the DATA_ACK after moving the backlog

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The fix tries only one subflow, the one recorded from the last backlog skb with a non-NULL skb->sk, and gives up if that subflow…
- [Low] The new mptcp_subflow_schedule_ack() (net/mptcp/protocol.c:2421-2428) calls tcp_send_delayed_ack(ssk) on a…

--

mptcp: send the DATA_ACK after moving the backlog

Data received while the msk is owned by the user goes to the backlog. The TCP ACKs sent for it carry the old DATA_ACK, so the peer can do a spurious MPTCP-level retransmission. This patch schedules a delayed ACK on the subflow of the last skb spooled from the backlog, if no ACK is already pending there.

Quoted 5 lines
net/mptcp/protocol.c +0 -0
index 0ff84d9684f13..2f89719e84545 100644

net/mptcp/protocol.c static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied) · line 2426

Quoted 10 lines
net/mptcp/protocol.c +7 -0
@@ -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);

[Severity: Low]
Is the side effect on the subflow's TCP delayed-ACK heuristics intended?

At this point TCP has already ACKed the data, possibly right away, so the subflow has no new TCP data to acknowledge. tcp_send_delayed_ack() still sets ICSK_ACK_SCHED | ICSK_ACK_TIMER and arms icsk_delack_timer.

The patch targets the case where the peer has nothing more to send. If nothing goes out on this subflow within ato, the timer fires and tcp_delack_timer_handler() treats it as a missed delayed ACK:

net/ipv4/tcp_timer.c:tcp_delack_timer_handler() {
    ...
	if (inet_csk_ack_scheduled(sk)) {
		if (!inet_csk_in_pingpong_mode(sk)) {
			/* Delayed ACK missed: inflate ATO. */
			icsk->icsk_ack.ato = min3((u32)icsk->icsk_ack.ato << 1,
						  icsk->icsk_rto,
						  (u32)TCP_DELACK_MAX);
		} else {
			...
			inet_csk_exit_pingpong_mode(sk);
			icsk->icsk_ack.ato      = TCP_ATO_MIN;
		}
		...
		__NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKS);
	}
}

This can happen every time data lands in the msk backlog while the msk is owned, for example when recvmsg() or the worker overlaps incoming data. Each time, the subflow's ato can be inflated or pingpong mode can be exited for a reason that has nothing to do with TCP. TcpExtDelayedACKs is also incremented.

The commit message only says the DATA_ACK is sent "when the delayed ACK timer expires". Could it mention these effects? Alternatively, could the DATA_ACK be sent without going through the TCP delayed-ACK state?

Quoted 22 lines
net/mptcp/protocol.c +7 -0
+	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;

net/mptcp/protocol.c static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delt · line 2457

Quoted 5 lines
net/mptcp/protocol.c +2 -0
@@ -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);

[Severity: Medium]
Only one subflow is tried here. What happens when that subflow cannot carry the updated DATA_ACK?

In two cases nothing gets scheduled even though msk->ack_seq has moved forward.

First, a subflow may be closed with MPTCP_CF_PUSH while the msk is owned, for example by a PM subflow destroy or a worker close. If data arrived on that subflow before the close, mptcp_cleanup_ssk_backlog() clears skb->sk on its backlog skbs:

net/mptcp/protocol.c:mptcp_cleanup_ssk_backlog() {
    ...
		atomic_sub(skb->truesize, &skb->sk->sk_rmem_alloc);
		skb->sk = NULL;
    ...
}

If all spooled skbs came from that subflow, ssk stays NULL in __mptcp_move_skbs() and mptcp_subflow_schedule_ack() is never called.

Second, the last skb's subflow may move to TCP_CLOSE after its data was queued and before spooling, for example after an RST and before __mptcp_close_ssk() runs. tcp_can_send_ack(ssk) then returns false inside mptcp_subflow_schedule_ack(), and nothing is scheduled.

In both cases no other entry in msk->conn_list is tried, even if another subflow is ESTABLISHED and could carry the connection-level DATA_ACK.

The later mptcp_cleanup_rbuf(msk, 0) from release_cb doesn't seem to cover this. With copied == 0 it only acts on subflows that already have an ACK scheduled and more than rcv_mss of unacked data. So the peer would keep the stale DATA_ACK and could still do the spurious retransmission this patch is meant to avoid.

The v2 note covers the second case, but the commit message itself mentions neither case. Would it make sense to fall back to another subflow in conn_list that can send ACKs?

Quoted 4 lines
net/mptcp/protocol.c +1 -0
+
 	/* Only the worker can close an orphan, as it must then destroy it */
 	if (!sock_flag(sk, SOCK_DEAD))
 		mptcp_check_data_fin(sk);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#85 lore raw

PATCH v3 41/50 selftests: mptcp: join: infinite map: no spurious rtx

In reply to 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")

---
v2: new, for a flaky selftest

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +6 -0
index 4c045532f137..3d48b02ee8c9 100755
@@ -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 \
Signature · 1 line
2.55.0
author maintainer
#86 lore raw

PATCH v3 42/50 selftests: mptcp: connect: trunc: wait for acks

In reply to 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")

---
v2: new, for a flaky selftest

---
 tools/testing/selftests/net/mptcp/mptcp_connect.c | 24 ++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +23 -1
index 8c788977e594..861fa2bd70d0 100644
@@ -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 */
Signature · 1 line
2.55.0
author maintainer
#87 lore raw

PATCH v3 43/50 mptcp: order write_seq and DATA_FIN flag

In reply to 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")

---
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(-)
net/mptcp/protocol.c +2 -1
index 2f89719e8454..e0f39931493e 100644
@@ -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);
 }
net/mptcp/protocol.h +2 -1
index 7cdd0a7e8296..a9daa047203c 100644
@@ -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);
 }
 
Signature · 1 line
2.55.0
#88 lore raw

Re: [PATCH mptcp-net v3 43/50] mptcp: order write_seq and DATA_FIN flag

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] This commit adds smp_store_release(&msk->snd_data_fin_enable, 1) in __mptcp_wr_shutdown() (net/mptcp/protocol.c), but pairs it with an…

--

mptcp: order write_seq and DATA_FIN flag

This commit changes __mptcp_wr_shutdown() so that it sets snd_data_fin_enable with smp_store_release() after it bumps write_seq. It also makes mptcp_data_fin_enabled() read the flag with smp_load_acquire(). Lockless readers in the subflow TX path should then see the new write_seq whenever they see the DATA_FIN flag set.

net/mptcp/protocol.c static void __mptcp_wr_shutdown(struct sock *sk) · line 3698

Quoted 11 lines
net/mptcp/protocol.c +2 -1
index 2f89719e84545..e0f39931493ea 100644
@@ -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);

[Severity: Low]
Is mptcp_data_fin_enabled() the only lockless reader that needs to pair with this release?

mptcp_try_fallback() in net/mptcp/protocol.h runs in BH and reads the same two fields. It still reads the flag with a plain READ_ONCE():

net/mptcp/protocol.h:mptcp_try_fallback() {
    ...
	/* no FIN before new data: see mptcp_check_send_data_fin() */
	if (READ_ONCE(msk->snd_data_fin_enable) &&
	    !before64(READ_ONCE(msk->snd_nxt) + 1, READ_ONCE(msk->write_seq)) &&
	    !(ssk->sk_shutdown & SEND_SHUTDOWN)) {
		...
		ssk->sk_shutdown |= SEND_SHUTDOWN;
		tcp_shutdown(ssk, SEND_SHUTDOWN);
		...
	}
    ...
}

Nothing orders the flag read before the write_seq read here. On a weakly ordered CPU, could this path see the flag set but still read the old write_seq?

If exactly one byte of data is still unsent, the before64() check would pass. The subflow FIN would then be sent before that byte.

The next patch in this series, "mptcp: order write_seq and DATA_FIN flag for fallback", changes mptcp_try_fallback() to use smp_load_acquire(). It also updates this comment to name both mptcp_data_fin_enabled() and mptcp_try_fallback(). So the gap only exists at this intermediate commit. The split looks intentional, since each patch carries its own Fixes tag.

Until that patch lands, the comment above names only one of the two readers.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#89 lore raw

PATCH v3 44/50 mptcp: order write_seq and DATA_FIN flag for fallback

In reply to 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")

---
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(-)
net/mptcp/protocol.c +3 -1
index e0f39931493e..f361cd40a8e4 100644
@@ -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);
net/mptcp/protocol.h +4 -2
index a9daa047203c..59ddf3dafeba 100644
@@ -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;
Signature · 1 line
2.55.0
author maintainer
#90 lore raw

PATCH v3 45/50 Squash to "bpf: Add mptcp packet scheduler struct_ops"

In reply to 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.

---
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(-)
net/mptcp/protocol.c +4 -4
index f361cd40a8e4..a3c2d8f93bd7 100644
@@ -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) {
Signature · 1 line
2.55.0
#91 lore raw

Re: [PATCH mptcp-net v3 45/50] Squash to "bpf: Add mptcp packet scheduler struct_ops"

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] This squash moves undocumented changes to the core push loop into a commit whose message is only about BPF.

--

Squash to "bpf: Add mptcp packet scheduler struct_ops"

This squash fixes two infinite push loops that can happen when a BPF scheduler picks no subflow, or keeps picking a subflow that cannot send. In __mptcp_subflow_push_pending(), the loop now stops when no subflow is scheduled. In __mptcp_push_pending(), push_count is now decremented after any failure.

Quoted 17 lines
net/mptcp/protocol.c +1 -4
index f361cd40a8e40..a3c2d8f93bd71 100644
@@ -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;

net/mptcp/protocol.c static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool · line 1966

Quoted 9 lines
net/mptcp/protocol.c +3 -0
@@ -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) {

[Severity: Low]
This isn't a bug, but after the squash, will the message of "bpf: Add mptcp packet scheduler struct_ops" still match what that commit does?

Right now that commit only modifies net/mptcp/bpf.c. Its message covers registering the bpf_struct_ops and allowing write access to the scheduled flag through .btf_struct_access.

With this squash, it would also change the generic transmit path in net/mptcp/protocol.c. All schedulers use that path, including the default one:

- __mptcp_push_pending() drops the -EAGAIN exception for FIN_WAIT1, FIN_WAIT2 and CLOSE. That exception came from commit 0fa1b3783a17 ("mptcp: use get_send wrapper"). push_count is now always decremented.

- __mptcp_subflow_push_pending() gets a new else branch that sets keep_pushing to false.

The code changes themselves look fine. The explanation of why both are needed, and why the default scheduler is not affected, is only in this squash message. Nothing asks for it to be carried over into the target commit message. Later patches in the series do not seem to cover this either.

Could this explanation be added to the target commit message? That way, git blame and bisect users can find out why the -EAGAIN retry from 0fa1b3783a17 was dropped.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#92 lore raw

PATCH v3 46/50 Squash to "bpf: Export mptcp packet scheduler helpers"

In reply to 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.

---
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(+)
net/mptcp/sched.c +5 -0
index 1e59072d478c..01500f9f9f8a 100644
@@ -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);
 }
 
Signature · 1 line
2.55.0
#93 lore raw

Re: [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers"

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 --

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) <[email protected]>

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.

Quoted 16 lines
net/mptcp/sched.c +4 -0
index 1e59072d478c9..01500f9f9f8a6 100644
@@ -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;

net/mptcp/sched.c int mptcp_sched_get_send(struct mptcp_sock *msk) · line 198

Quoted 6 lines
net/mptcp/sched.c +1 -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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=46
#94 lore raw

Re: [PATCH mptcp-net v3 46/50] Squash to "bpf: Export mptcp packet scheduler helpers"

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] mptcp: mptcp_sched_get_send() skips mptcp_set_timeout() on scheduled subflow

--

Quoted 4 lines

net/mptcp/sched.c int mptcp_sched_get_send(struct mptcp_sock *msk) · line 191

Quoted 10 lines
net/mptcp/sched.c +4 -0
@@ -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;

[Severity: Medium]
The v3 change covers the already-scheduled case for BPF schedulers only, but the same early return is taken with the default scheduler too. In that case mptcp_sched_default_get_send() is not called, so mptcp_subflow_get_send() does not run. Neither msk->timer_ival nor msk->snd_burst is refreshed.

Can a subflow keep subflow->scheduled set after all data has been acked, with msk->timer_ival reset to 0 by mptcp_stop_rtx_timer()? It looks possible. In ack_update_msk(), __mptcp_check_push() runs before __mptcp_data_acked(). During recovery, the default scheduler can then mark and delegate another subflow. Right after that, __mptcp_clean_una() clears msk->first_pending and stops the timer.

When the delegated action later runs __mptcp_subflow_push_pending(sk, ssk, true), mptcp_send_head() is NULL. The loop is skipped, and the scheduled flag is never cleared.

On the next push, mptcp_sched_get_send() then returns 0 with msk->timer_ival == 0. __subflow_push_pending() can bail out before its own mptcp_set_timeout() call. That happens if mptcp_sendmsg_frag() fails, or if msk->snd_burst is <= 0 after the first fragment. In that case mptcp_reset_rtx_timer() arms the rtx timer with a 0 interval, and it fires every jiffy. This is the same issue this patch is trying to fix, only with the default scheduler.

Would it make sense to call mptcp_set_timeout() unconditionally before the scheduled loop, whatever the scheduler? Or is the stale scheduled flag the real bug, to be cleared elsewhere?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#95 lore raw

PATCH v3 47/50 mptcp: push pending data after a fallback on reception

In reply to 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")

---
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(+)
net/mptcp/protocol.c +4 -0
index a3c2d8f93bd7..016b16b3cc92 100644
@@ -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);
 }
 
Signature · 1 line
2.55.0
author maintainer
#96 lore raw

PATCH v3 48/50 mptcp: report errors as TCP does when closing

In reply to 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.

---
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(-)
net/mptcp/protocol.c +67 -21
index 016b16b3cc92..0a7600aea181 100644
@@ -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));
Signature · 1 line
2.55.0
#97 lore raw

Re: [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing

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…

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) <[email protected]>

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().

Quoted 47 lines
net/mptcp/protocol.c +39 -0
index 016b16b3cc925..0a7600aea181e 100644
@@ -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)
+{

net/mptcp/protocol.c static void mptcp_close_wake_up(struct sock *sk) · line 569

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+	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().

[ ... ]

net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2963

Quoted 8 lines
net/mptcp/protocol.c +2 -0
@@ -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.

net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2971

Quoted 12 lines
net/mptcp/protocol.c +4 -4
 			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.

[ ... ]

net/mptcp/protocol.c static void mptcp_worker(struct work_struct *work) · line 3489

Quoted 8 lines
net/mptcp/protocol.c +1 -2
@@ -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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=48
#98 lore raw

Re: [PATCH mptcp-next mptcp-net v3 48/50] mptcp: report errors as TCP does when closing

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] Spurious ECONNRESET after a clean MPTCP-level close, in __mptcp_close_ssk() (net/mptcp/protocol.c:2962-2968).
- [Medium] mptcp: skipped mptcp_check_rcv_close() in __mptcp_close_ssk() when ESTABLISHED
- [Medium] mptcp: premature TCP_CLOSE and wakeup before mptcp_close_err() on timeout
- [Low] The barrier-pairing comments disagree.

--

mptcp: report errors as TCP does when closing

This patch makes the MPTCP socket set SHUTDOWN_MASK and an error when it moves to TCP_CLOSE. This covers the close timeout (ETIMEDOUT), the last subflow closing outside ESTABLISHED, and the late cleanup in accept(). In those cases the error is the last subflow's error, or one picked from the MPTCP-level state, matching tcp_done_with_error().

Quoted 23 lines
net/mptcp/protocol.c +15 -0
index 016b16b3cc925..0a7600aea181e 100644
@@ -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;
+	}

net/mptcp/protocol.c static void mptcp_close_wake_up(struct sock *sk) · line 545

Quoted 10 lines
net/mptcp/protocol.c +10 -0
+
+	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();

[Severity: Low]

This isn't a bug, but the comment on the reader side in mptcp_poll() still names only __mptcp_error_report() as the matching writer:

	/* This barrier is coupled with smp_wmb() in __mptcp_error_report() */
	smp_rmb();

__mptcp_error_report() has no smp_wmb() of its own. The writers are __mptcp_subflow_error_report() and now mptcp_close_err().

The ordering itself looks correct. Could the mptcp_poll() comment be updated to name the new writer too?

Quoted 25 lines
net/mptcp/protocol.c +25 -0
+	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);
+}
+

[ ... ]

Quoted 7 lines
net/mptcp/protocol.c +2 -0
@@ -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 ||

net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2968

Quoted 10 lines
net/mptcp/protocol.c +4 -4
 			   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);

[Severity: Medium]
Can waiters be woken here before the error is set, on the close timeout path?

When mptcp_close_tout_expired() is true in mptcp_worker(), mptcp_do_fastclose() moves the msk to TCP_CLOSE first, while sk_err is still 0 and sk_shutdown is not SHUTDOWN_MASK. The loop then calls __mptcp_close_ssk() on each subflow. Once only msk->first is left, in TCP_CLOSE, this new branch calls mptcp_close_wake_up() on a socket that is not SOCK_DEAD. That runs sk_state_change() before mptcp_close_err(sk, ETIMEDOUT) has written sk_err and sk_shutdown.

mptcp_poll() and getsockopt(SO_ERROR) do not take the msk socket lock. A waiter woken on another CPU can therefore see TCP_CLOSE with sk_shutdown at 0 and sk_err at 0. It gets EPOLLHUP without EPOLLERR, EPOLLIN or EPOLLOUT, and SO_ERROR returns 0 instead of ETIMEDOUT. An application acting on that first wakeup would miss the timeout this patch is meant to report. mptcp_close_err() then wakes everybody a second time.

The ordering mptcp_close_err() sets up (sk_err, smp_wmb(), SHUTDOWN_MASK, then TCP_CLOSE) does not help here, as the state was already published by mptcp_do_fastclose(). mptcp_check_fastclose() has a similar, older inversion: TCP_CLOSE is set before SHUTDOWN_MASK, and there is no smp_wmb() after sk_err.

Should the wake up in __mptcp_close_ssk() be left to mptcp_close_err() on the close timeout path? Or should sk_err and sk_shutdown be set before mptcp_do_fastclose() changes the state?

[Severity: Medium]
Can a DATA_FIN still sitting in msk->backlog_list be missed here?

Suppose the peer sends its last data with a DATA_FIN, then closes or resets the only subflow, while mptcp_worker() owns the msk socket lock. The skb is queued in msk->backlog_list and msk->rcv_data_fin is set, but msk->ack_seq has not reached msk->rcv_data_fin_seq yet. The mptcp_check_data_fin() call in mptcp_worker() does not spool the backlog, so sk_state is still TCP_ESTABLISHED when __mptcp_close_subflow() reaches __mptcp_close_ssk().

mptcp_close_ssk() only spools the backlog for the first subflow after a fallback. The TCP_ESTABLISHED test above also runs before mptcp_check_rcv_close() gets a chance to, so this ends up in the mptcp_start_tout_timer() branch. The backlog is only moved later, from mptcp_release_cb(), which then processes the DATA_FIN and moves the msk to TCP_CLOSE_WAIT with no subflow left.

The msk then sits in TCP_CLOSE_WAIT until the close timeout expires. With this patch, mptcp_worker() then reports ETIMEDOUT through mptcp_close_err(), on a connection the peer closed cleanly. Had the DATA_FIN been processed first, mptcp_close_last_err() would have closed it at once with EPIPE. An MP_FASTCLOSE received in the same window looks to be skipped the same way.

The TCP_ESTABLISHED gating predates this patch, but the new error reporting makes the difference visible to applications. Should mptcp_check_rcv_close() be called before sk_state is tested here, or is the pending DATA_FIN expected to be handled somewhere else?

[Severity: Medium]

Can this report ECONNRESET after a clean MPTCP-level close?

mptcp_check_rcv_close() only handles the receive side, through mptcp_check_data_fin() and mptcp_check_fastclose(). When our own DATA_FIN is acked, the move to TCP_CLOSE is done only by mptcp_check_data_fin_ack(), which is called only from mptcp_worker():

net/mptcp/protocol.c:mptcp_check_data_fin_ack() {
    ...
	if (mptcp_pending_data_fin_ack(sk)) {
		...
		case TCP_CLOSING:
		case TCP_LAST_ACK:
			mptcp_shutdown_subflows(msk);
			mptcp_set_state(sk, TCP_CLOSE);
    ...
}

When the DATA_ACK arrives, __mptcp_clean_una() only schedules the worker:

	if (mptcp_pending_data_fin_ack(sk))
		mptcp_schedule_work(sk);

So until the worker runs, the msk can still be in TCP_LAST_ACK or TCP_CLOSING with our DATA_FIN already acked.

Suppose msk->first is already in TCP_CLOSE and the one other subflow is removed in that window. One way is a peer RM_ADDR, handled earlier in the same worker run:

mptcp_worker()
mptcp_pm_worker()

    mptcp_pm_rm_addr_recv()
      mptcp_pm_rm_addr_or_subflow()
        mptcp_close_ssk()
          __mptcp_close_ssk()

...
mptcp_check_data_fin_ack() <- runs only after this

mptcp_pm_rm_addr_or_subflow() skips only subflows in FIN_WAIT1, FIN_WAIT2, CLOSING or CLOSE, so an ESTABLISHED or CLOSE_WAIT subflow is still removed. A netlink endpoint delete or flush, or a userspace PM subflow destroy, can also reach mptcp_close_ssk() directly under the msk lock.

In that case ssk_err is 0, and for a socket that is not SOCK_DEAD (for example after shutdown(SHUT_WR)) the result is:

mptcp_close_last_err(sk, 0)
mptcp_reset_err(sk) -> ECONNRESET for LAST_ACK / CLOSING
mptcp_close_err(sk, ECONNRESET)

When mptcp_check_data_fin_ack() runs later, the msk is already in TCP_CLOSE, mptcp_pending_data_fin_ack() returns false, and sk_err stays at ECONNRESET. mptcp_poll() then reports EPOLLERR and SO_ERROR returns ECONNRESET on a connection that finished its DATA_FIN exchange cleanly.

Before this patch, this path moved to TCP_CLOSE without setting sk_err. TCP also sets no error when the final ACK arrives in LAST_ACK or CLOSING.

Should the pending DATA_FIN ack be processed first, either through mptcp_check_data_fin_ack() or a mptcp_pending_data_fin_ack() test, before the error is picked? This doesn't seem to be addressed by the later patches in the series.

Quoted 3 lines
net/mptcp/protocol.c +0 -0
 		} else {
 			mptcp_start_tout_timer(sk);
 		}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
author maintainer
#99 lore raw

PATCH v3 49/50 mptcp: trace: name all the mapping statuses

In reply to 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.

---
v3: new, for an issue spotted by Clashiko

---
 include/trace/events/mptcp.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/trace/events/mptcp.h +3 -1
index c47fa2672b84..ebc7408c1fa6 100644
@@ -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,
 
Signature · 1 line
2.55.0
author maintainer
#100 lore raw

RFC PATCH v3 50/50 mptcp: reset when the DSS disappears after a DATA_ACK

In reply to 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.

---
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(-)
include/trace/events/mptcp.h +2 -1
index ebc7408c1fa6..527eb7a18528 100644
@@ -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,
 
net/mptcp/options.c +7 -4
index 41eb39968a9a..e561143dd121 100644
@@ -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
net/mptcp/protocol.h +2 -1
index 59ddf3dafeba..70cd119bdbb8 100644
@@ -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? */
net/mptcp/subflow.c +25 -4
index 190c75311ff6..efbd3efd379e 100644
@@ -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
 			 */
Signature · 1 line
2.55.0
#101 lore raw

Re: [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK

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 --

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) <[email protected]>

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.

Quoted 4 lines
net/mptcp/subflow.c +0 -0
index 190c75311ff69..efbd3efd379ed 100644

[ ... ]

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1550

Quoted 11 lines
net/mptcp/subflow.c +3 -1
@@ -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);
	}
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=50
#102 lore raw

Re: [PATCH RFC mptcp-next mptcp-net v3 50/50] mptcp: reset when the DSS disappears after a DATA_ACK

In reply to Matthieu Baerts (NGI0)
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch is incomplete: after a DATA_ACK confirmation, an skb that runs past the end of its mapping still makes the receiver fall…
- [Medium] The MAPPING_INFINITE exemption ('but not for an infinite mapping, the fallback signal from the RFC') does not work when the…

--

mptcp: reset when the DSS disappears after a DATA_ACK

Following RFC 8684 section 3.7, this commit resets a subflow when it receives data without a DSS, or with an invalid mapping, after a DATA_ACK on that subflow acknowledged sent data. The exception is an MP_FAIL exchange in progress. ack_update_msk() sets a new dss_confirmed flag, and infinite mappings get a new MAPPING_INFINITE status so they still fall back.

Quoted 4 lines
net/mptcp/options.c +0 -0
index 41eb39968a9a6..e561143dd1219 100644

[ ... ]

net/mptcp/options.c bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) · line 1366

Quoted 11 lines
net/mptcp/options.c +2 -2
@@ -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

[Severity: Medium]
What happens if the peer sends its infinite mapping on a zero-length segment? For example, a pure ACK could carry a DSS with data_len == 0 and a DATA_ACK that acknowledges our data.

dss_confirmed is set here, before the zero-length check that comes next in mptcp_incoming_options():

	if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
		if (mp_opt.data_fin && mp_opt.data_len == 1 &&
		    mptcp_update_rcv_data_fin(msk, mp_opt.data_seq, mp_opt.dsn64))
			mptcp_schedule_work((struct sock *)msk);

		return true;
	}

No mptcp_ext is attached in that case, so get_mapping_status() never returns MAPPING_INFINITE for this segment. The peer's next data, sent without a DSS, then gives MAPPING_NODSS.

Without a prior MP_FAIL, allow_subflows is still set. So subflow_nodss_is_fatal() returns true, and subflow_check_data_avail() resets the subflow with MPTCP_RST_EMIDDLEBOX instead of calling mptcp_try_fallback(). Before this patch, the same sequence fell back to TCP.

Linux itself only attaches the infinite mapping to data skbs, after an MP_FAIL, so this depends on how other implementations send it.

Should the MAPPING_INFINITE exemption described in the commit message also cover this case?

Quoted 4 lines
net/mptcp/subflow.c +0 -0
index 190c75311ff69..efbd3efd379ed 100644

[ ... ]

net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1550

Quoted 11 lines
net/mptcp/subflow.c +3 -1
@@ -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: High]
Does this cover all the invalid mappings that the commit message mentions? The message says:

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, ...

validate_mapping() only checks the start of the skb against the mapping:

	u32 ssn = tcp_sk(ssk)->copied_seq - subflow->ssn_offset;
	...
	if (unlikely(!before(ssn, subflow->map_subflow_seq +
				  subflow->map_data_len))) {

Take an skb whose payload runs past the end of its mapping, for example two segments merged by a middlebox that keeps only the first DSS. It gets MAPPING_OK here, and with checksums disabled (the default) it is accepted.

The mismatch is only caught later, in __mptcp_move_skbs_from_subflow():

			if (unlikely(map_remaining < len)) {
				DEBUG_NET_WARN_ON_ONCE(1);
				mptcp_dss_corruption(msk, ssk);
			}

mptcp_dss_corruption() still falls back without looking at dss_confirmed:

	if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
		MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSCORRUPTIONRESET);
		mptcp_subflow_reset(ssk);
	}

The non-FIN branch in __mptcp_move_skbs_from_subflow() calls it in the same way.

On a single subflow with allow_infinite_fallback still set, can the receiver then fall back on its own after the DSS was confirmed in both directions?

That is the late receiver-only fallback this patch is meant to remove. An older sender keeps resending data at the MPTCP level, and the receiver delivers it as new data.

Commit e32d262c89e2 ("mptcp: handle consistently DSS corruption") notes that buggy peers can send corrupted DSS options that hit these paths. So they look reachable from remote input.

The note after the --- marker already says that mptcp_dss_corruption() still falls back after a DATA_ACK, but that note won't be in the committed changelog.

Should mptcp_dss_corruption() also apply the dss_confirmed check? Or should validate_mapping() reject an skb that extends past the end of the mapping?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-mptcp-cmason-fixes-v3-0-416c0920c73f%40kernel.org
#103 lore raw
In reply to Matthieu Baerts (NGI0)

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)

author maintainer
#104 lore raw
In reply to Matthieu Baerts (NGI0)

Hello,

Quoted 1 line · On 24/11/2026 22:59, Matthieu Baerts (NGI0) wrote:

Here are various fixes, some from Chris Mason and Josef Bacik:

In order to help to trim this series down, and avoid blocking other ones for too long, I suggest applying the 37 first patches. So up to "mptcp:
continue the last mapping after a fallback", which is the last patch from Chris.

I applied Mat and Clashiko's comments (minor tweaks in the commit messages and comments), and I will send a v4 with the rest.

Of course, I can always change patches applied in our tree with squash-to patches, and add RvB tags.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.