mptcp: misc fixes
Subsystems (5)
Matthieu Baerts (NGI0)
maintainerv2 cover mptcp: misc fixes
Here are various fixes, many from Chris Mason and Josef Bacik:
- Patches 1-2: drain the queues of a TCP or MPTCP socket when listen() fails, not to leak sockets and their netns. Fixes for v4.4 and v5.11.
- Patch 3: clear inet_opt in the child of an IPv6 listener, to avoid a double free with SELinux and NetLabel. A fix for v5.6.
- Patches 4-7: do not lose an RM_ADDR, when received in a row, sent with a pending ADD_ADDR echo, or when computing the MSS. Fixes for v5.13, v5.10, v5.15 and v5.10.
- Patches 8-9: do not leave data unsent after a memory shortage. Fixes for another fix introduced in v6.19 and targeting v5.15, and for v5.11.
- Patches 10-11: do not leak an orphan moved to the CLOSE state outside the worker. Fixes for v6.15, and for another fix introduced in v6.6 and targeting v5.11.
- Patches 12-17: 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 18-20: 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 21-24: 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: the reader could miss the end of file or the reset. Fixes for v5.9, v6.6, v6.19 and v6.3.
- Patch 25: clear the socket error on connect(), as TCP does. A fix for v5.17.
- Patches 26-27: 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 28: 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 29-30: keep listening 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 31: drop the ACKs with a SYN cookie and no MP_JOIN on PM listeners, which could stop accepting new subflows. A fix for v5.12.
- Patches 32-33: do not let PM listeners pin their netns, leaked otherwise. A fix for v5.12.
- Patch 34: close a subflow reset because of a bad mapping, not to keep the MPTCP socket established without subflows. A fix for v5.12.
- Patch 35: initialize drop_req, not to leak sockets with SO_REUSEPORT migration. A fix for v5.14.
- Patches 36-37: 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 38-39: 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 40-42: 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 43-44: 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.
- Patch 45: do not pass a BPF request sock to an MPTCP listener, to avoid a slab-out-of-bounds write. A fix for v6.9.
- Patches 46-49: reclaim the forward memory after coalescing skbs, and do not overcharge the memcg at accept(). Fixes for v6.19.
- Patch 50: after a fallback, continue the last mapping. A fix for v6.19.
- Patches 51-52: 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 53: with MSG_PEEK, do not skip data after a partly peeked skb:
the peeked data was corrupted. A fix for v6.18.
- Patch 54: 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 55-56: 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.
- Patch 57: order the write_seq and DATA_FIN flag updates, not to send a FIN before the last byte of data after a fallback, on weakly ordered CPUs. A fix for another fix, now in net, and targeting v5.19.
- Patches 58-59: Squash-to patches for the BPF packet schedulers, in the MPTCP tree only: stop pushing when they pick no subflow, instead of spinning in softirq, and set the rtx timer interval before calling them, not to fire the timer every jiffy.
- Patch 60: 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 61: 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 62: 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 61: the Packetdrill patches adapting them will be shared later.
---
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 (16):
tcp: drain the queues of a listen() that fails
mptcp: drain the queues of a listen() that fails
mptcp: clear inet_opt in the child of an IPv6 listener
mptcp: arm the rtx timer if a push leaves data behind
mptcp: force the charge for the first skb of a subflow
mptcp: leave an orphan's DATA_FIN to the worker
mptcp: drop non-MP_JOIN cookie ACKs on PM listeners
mptcp: close a subflow reset for a bad mapping
mptcp: initialize drop_req in subflow_init_req()
mptcp: do not fallback while old data is in flight
mptcp: stop resending data to a peer that fell back
tcp: do not pass a BPF reqsk to an MPTCP listener
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 (5):
mptcp: pm: work on a copy of the received RM_ADDR list
mptcp: pm: don't drop an RM_ADDR behind a pending one
mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR
mptcp: pm: don't let listeners pin their netns
mptcp: pm: kernel: don't count signal+subflow ID 0 endp
Matthieu Baerts (NGI0) (41):
mptcp: pm: keep an RM_ADDR when computing the MSS
mptcp: don't leak an orphan when the PM closes its last subflow
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: 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: keep listening after MSG_FASTOPEN errors
mptcp: don't inherit fastopening from a listener
net: add __sk_net_refcnt_upgrade() with a GFP mask
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 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 [RFC mptcp-next] mptcp: reset when the DSS disappears after a DATA_ACK
include/net/sock.h | 1 + net/core/sock.c | 9 +- net/ipv4/inet_connection_sock.c | 12 +- net/ipv4/syncookies.c | 3 +- net/mptcp/mib.h | 2 +- net/mptcp/options.c | 53 ++- net/mptcp/pm.c | 50 ++- net/mptcp/pm_kernel.c | 15 +- net/mptcp/protocol.c | 476 ++++++++++++++++++---- net/mptcp/protocol.h | 30 +- net/mptcp/sched.c | 3 + net/mptcp/subflow.c | 115 +++++- tools/testing/selftests/net/mptcp/mptcp_connect.c | 24 +- tools/testing/selftests/net/mptcp/mptcp_join.sh | 19 +- 14 files changed, 671 insertions(+), 141 deletions(-)
---
base-commit: b9620afcd7c2a78410eb68fa5fe70b9da8ce088e
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]>
Matthieu Baerts (NGI0)
maintainerPATCH v2 1/62 tcp: drain the queues of a listen() that fails
From: Chris Mason <[email protected]>
If listen() fails on a TCP socket that has listened before, the sockets of connections from the earlier listen() can leak, together with their network namespace.
inet_csk_listen_start() sets TCP_LISTEN before it calls get_port() and hash(), and its error path sets TCP_CLOSE again, then purges the Fast Open RST queue since commit 342e62fd34c2 ("tcp: purge Fast Open RST queue when listen() fails"), but not the accept queue. Pending request socks outlive an earlier listen() and still point to the socket, so in TCP_LISTEN, inet_csk_reqsk_queue_add() adds them to the accept queue, with their new child. These entries, and the sockets that they hold, are never freed, since close() drains this queue only in TCP_LISTEN and the next listen() stores NULL in rskq_accept_head.
The fix used here is to call inet_csk_listen_stop() after the error path sets TCP_CLOSE, which also purges the RST queue, except for an MPTCP subflow, which needs mptcp_subflow_queue_clean() first: only its RST queue is purged here, and mptcp_listen() has to drain its accept queue, which is done in the next patch, "mptcp: drain the queues of a listen() that fails".
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, run as an unprivileged user: listen() failing with EADDRINUSE in a loop, while the connections of an earlier listen() complete. Without this patch, sockets were leaked, and network namespaces too when each round was in its own one, without any message from the kernel:
result: request socks: 10000 made, 2535 left. Sockets: 33373 made, 5070 left [...]
result: namespaces: 1000 made, 694 taken down, 306 left
[ Shorter comments. Commit message: how the issue was found, and its
symptoms. On top of commit 342e62fd34c2, with a Fixes tag for the accept queue. ]
---
v2: on top of commit 342e62fd34c2, which purges the RST queue, still done for MPTCP subflows: Fixes tag for the accept queue.
--- net/ipv4/inet_connection_sock.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/ipv4/inet_connection_sock.c +8 -4
@@ -1371,8 +1371,8 @@ int inet_csk_listen_start(struct sock *sk)/* There is race window here: we announce ourselves listening, * but this transition is still not validated by get_port(). -* It is OK, because this socket enters to hash table only -* after validation is complete. +* This socket enters to hash table only after validation is +* complete, but reqs of an earlier listen() may queue children. */ inet_sk_state_store (sk,TCP_LISTEN ); err = sk->sk_prot->get_port (sk, inet->inet_num);
@@ -1390,9 +1390,13 @@ int inet_csk_listen_start(struct sock *sk)/* A Fast Open child accepted before a previous shutdown() of this * listener might have queued its request in rskq_rst_head while -* we were transiently in TCP_LISTEN state. +* we were transiently in TCP_LISTEN state. The accept queue of an +* MPTCP subflow is drained by mptcp_listen(). */ -reqsk_fastopen_purge_rst (&icsk->icsk_accept_queue); +if (sk_is_mptcp (sk)) +reqsk_fastopen_purge_rst (&icsk->icsk_accept_queue); +else +inet_csk_listen_stop (sk);return err; }
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 2/62 mptcp: drain the queues of a listen() that fails
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
Sockets and their network namespace can leak, if a handshake completes while listen() fails on an MPTCP socket that has listened before.
mptcp_listen() passes the first subflow through __inet_listen_sk() to inet_csk_listen_start(), which sets TCP_LISTEN, then calls get_port() and hash(), and sets TCP_CLOSE again if either fails. Until then the subflow is in TCP_LISTEN, so a request sock of a previous listen() that still points to it can get a new child and be added to the subflow's accept queue. But neither close() nor the next listen() frees what is queued, and the earlier commit "tcp: drain the queues of a listen() that fails" only purges the RST queue of an MPTCP subflow, which needs mptcp_subflow_queue_clean() before a drain.
The fix used here is to call mptcp_subflow_queue_clean() and then inet_csk_listen_stop() on the subflow in mptcp_listen(), if __inet_listen_sk() returns an error with the subflow in TCP_CLOSE.
This issue has been found with the help of an LLM, and reproduced in a VM, with the reproducer of the previous commit, modified to use MPTCP sockets, on both sides. Without this patch, sockets were leaked, and network namespaces too when each round was in its own one, without any message from the kernel:
result: request socks: 10000 made, 1151 left. Sockets: 64982 made, 5755 left [...]
result: namespaces: 1000 made, 923 taken down, 77 left
[ Shorter comment. Add a Fixes tag. Commit message: how the issue was
found, and its symptoms. ]
---
v2: commit msg: reproduced, with MPTCP sockets. Only the accept queue is left, after commit 342e62fd34c2 ("tcp: purge Fast Open RST queue when listen() fails").
--- net/mptcp/protocol.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mptcp/protocol.c +5 -0
@@ -4383,6 +4383,11 @@ static int mptcp_listen(struct socket *sock, int backlog)lock_sock (ssk); err =__inet_listen_sk (ssk, backlog); +if (err && ssk->sk_state ==TCP_CLOSE ) { +/* inet_csk_listen_start() leaves this drain to MPTCP */ +mptcp_subflow_queue_clean (sk, ssk); +inet_csk_listen_stop (ssk); + }release_sock (ssk);mptcp_set_state (sk,inet_sk_state_load (ssk));
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 3/62 mptcp: clear inet_opt in the child of an IPv6 listener
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
With SELinux, an IPv6 MPTCP listener and its children can cause a double free of one CIPSO option, and then a use-after-free read of it, if NetLabel uses CIPSO for IPv4 and selects the IPv6 labels by address.
mptcp_sk_clone_init() creates the child of a listener with sk_clone_lock(), as a byte copy of the listener, so each pointer in the copy that the socket destructor frees has to be replaced or cleared. mptcp_copy_ip_options() duplicates inet_opt, the IPv4 options, for AF_INET, and mptcp_copy_ip6_options() duplicates the IPv6 options for AF_INET6. But an AF_INET6 socket has an inet_opt pointer too, and its child keeps the listener's pointer.
MPTCP does not support setsockopt(IP_OPTIONS), so that pointer is usually NULL. But if connect() gets a struct sockaddr_in, netlbl_conn_setattr() does not look at the family of the socket, so the connect() hook of SELinux can store a CIPSO option in inet_opt of an AF_INET6 MPTCP listener. inet_sock_destruct() then passes that option to kfree_rcu() for each child and again for the listener, and after a child has freed it, another such connect() on the listener reads it in cipso_v4_sock_setattr().
The fix used here is to clear inet_opt of the child in mptcp_copy_ip6_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, with SELinux, NetLabel -- CIPSO for some IPv4 addresses, and the address-based selection used for IPv6 too -- and KASAN: an unprivileged user calls connect() with an IPv4 address on an IPv6 MPTCP listener. Without this patch, an object is freed twice:
BUG: KASAN: double-free in rcu_free_sheaf+0x23/0x100 Free of addr ffff888012c27a80 by task kworker/1:1/50 CPU: 1 UID: 0 PID: 50 Comm: kworker/1:1 Not tainted 7.4.0-rc1+ #1 PREEMPT(full) Workqueue: events mptcp_worker Call Trace: <IRQ> kasan_report_invalid_free+0xd4/0x1b0 check_slab_allocation+0xc2/0xf0 __rcu_free_sheaf_prepare+0x102/0x2a0 rcu_free_sheaf+0x23/0x100 rcu_do_batch+0x29a/0xf80 rcu_core+0x33c/0x830 handle_softirqs+0x212/0x980 do_softirq+0xb4/0xf0 </IRQ> <TASK> __local_bh_enable_ip+0x11c/0x150 mptcp_token_destroy+0x1c9/0x360 mptcp_destroy_common+0x2d9/0x430 mptcp_destroy+0x86/0x110 __mptcp_destroy_sock+0x176/0x350 mptcp_worker+0xbb5/0xf80 [...] Allocated by task 176: [...] cipso_v4_sock_setattr+0x9b/0x3d0 netlbl_conn_setattr+0x3ac/0x500 selinux_netlbl_socket_connect_locked+0x102/0x210 selinux_netlbl_socket_connect+0x23/0x40 security_socket_connect+0x2e/0x60 __sys_connect_file+0xcb/0x200 [...]
In another case, the CIPSO option is used after having been freed:
BUG: KASAN: slab-use-after-free in cipso_v4_sock_setattr+0x3c7/0x3d0 Read of size 1 at addr ffff8880161c2f18 by task python3/177 CPU: 1 UID: 65534 PID: 177 Comm: python3 Not tainted 7.4.0-rc1+ #1 PREEMPT(full) Call Trace: <TASK> kasan_report+0x101/0x140 cipso_v4_sock_setattr+0x3c7/0x3d0 netlbl_conn_setattr+0x3ac/0x500 selinux_netlbl_socket_connect_locked+0x102/0x210 selinux_netlbl_socket_connect+0x23/0x40 security_socket_connect+0x2e/0x60 __sys_connect_file+0xcb/0x200 __sys_connect+0xfd/0x130 __x64_sys_connect+0x72/0xd0 [...]
--- net/mptcp/protocol.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/protocol.c +3 -0
@@ -3720,6 +3720,9 @@ static void mptcp_copy_ip6_options(struct sock *newsk, const struct sock *sk) newnp =inet6_sk (newsk); +/* The IPv4 options belong to the listener, which frees them */ +RCU_INIT_POINTER (inet_sk (newsk)->inet_opt,NULL ); +rcu_read_lock (); opt =rcu_dereference (np->opt);if (opt) {
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 4/62 mptcp: pm: work on a copy of the received RM_ADDR list
In reply to Matthieu Baerts (NGI0)From: Josef Bacik <[email protected]>
The worker clears MPTCP_PM_RM_ADDR_RECEIVED and walks pm.rm_list_rx in place. For every subflow it closes, mptcp_pm_rm_addr_or_subflow() drops pm.lock. If the peer's next RM_ADDR arrives then, the flag is clear and mptcp_pm_rm_addr_received() overwrites the list. The walk goes on at its index in the new list: the ids of the first list that were still to come are never handled, and their subflows stay.
Hand a copy of the list to the walk.
This issue has been found with the help of an LLM. It has not been
reproduced: the next RM_ADDR has to be processed while the worker has dropped pm.lock to close a subflow, a window that a Packetdrill script cannot target. This fix is based on code inspection only, which is acceptable here: it is simple, and the issue is clear from the code.
[ Commit message: how the issue was found, and why it is fine without
a reproducer. ]
--- net/mptcp/pm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/mptcp/pm.c +4 -1
@@ -827,7 +827,10 @@ static void mptcp_pm_rm_addr_or_subflow(struct mptcp_sock *msk,static void mptcp_pm_rm_addr_recv (struct mptcp_sock *msk) { -mptcp_pm_rm_addr_or_subflow (msk, &msk->pm.rm_list_rx,MPTCP_MIB_RMADDR ); +/* pm.lock is dropped on the way: the next RM_ADDR may come in */ +struct mptcp_rm_list rm_list = msk->pm.rm_list_rx; + +mptcp_pm_rm_addr_or_subflow (msk, &rm_list,MPTCP_MIB_RMADDR ); } void mptcp_pm_rm_subflow(struct mptcp_sock *msk,
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 5/62 mptcp: pm: don't drop an RM_ADDR behind a pending one
In reply to Matthieu Baerts (NGI0)From: Josef Bacik <[email protected]>
There is room for one received list of address ids. An RM_ADDR that arrives before the worker has taken the previous one is counted as RmAddrDrop and forgotten, although the netlink events for its ids have been sent already. Two options follow each other at once if, for instance, the path manager in user space of the peer removes two of its addresses. The subflows to the second address stay.
Add the new ids to the pending list. Only the ids that do not fit in the list of MPTCP_RM_IDS_MAX ids are dropped, and the RM_ADDR is then counted as RmAddrDrop. The netlink events are not sent for the dropped ids, and they are sent before the worker can act on the others.
This issue has been found with the help of an LLM. It has not been
reproduced: the second RM_ADDR has to be processed before the PM worker gets to the first one, a window that a Packetdrill script cannot target. This fix is based on code inspection only, which is acceptable
here: the issue is clear from the code, and the fix is simple.
[ Commit message: only the ids that do not fit are dropped + how the
issue was found, and why it is fine without a reproducer. No netlink event for the dropped ids. ]
---
v2: no netlink event for the dropped ids (Clashiko), but still for the
next pending ones (Sashiko)
Note (Clashiko on v1): as before, an event is sent for each id of each received RM_ADDR, even if this id is already pending.
--- net/mptcp/pm.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
net/mptcp/pm.c +18 -5
@@ -843,17 +843,30 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list) {struct mptcp_pm_data *pm = &msk->pm; +bool drop = false;u8 i;pr_debug ("msk=%p remote_ids_nr=%d\n" , msk, rm_list->nr); -for (i =0 ; i < rm_list->nr; i++) -mptcp_event_addr_removed (msk, rm_list->ids[i]); -spin_lock_bh (&pm->lock);if (mptcp_pm_schedule_work (msk,MPTCP_PM_RM_ADDR_RECEIVED )) - pm->rm_list_rx = *rm_list; -else + pm->rm_list_rx.nr =0 ; + +/* the worker may not have got to the previous RM_ADDR yet */ +for (i =0 ; i < rm_list->nr; i++) { +u8 id = rm_list->ids[i]; + +if (!memchr (pm->rm_list_rx.ids, id, pm->rm_list_rx.nr)) { +if (pm->rm_list_rx.nr ==MPTCP_RM_IDS_MAX ) { + drop = true; +continue ; + } + pm->rm_list_rx.ids[pm->rm_list_rx.nr++] = id; + } +/* not for the dropped ids, and before the worker acts */ +mptcp_event_addr_removed (msk, id); + } +if (drop)__MPTCP_INC_STATS (sock_net ((struct sock *)msk),MPTCP_MIB_RMADDRDROP );spin_unlock_bh (&pm->lock); }
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 6/62 mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR
In reply to Matthieu Baerts (NGI0)From: Josef Bacik <[email protected]>
mptcp_pm_remove_addr() gives up, and counts RmAddrTxDrop, if any bit of pm.addr_signal is set. That dates from the time when the byte was cleared as a whole after a signal had been sent. Since commit 119c022096f5 ("mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other") an ADD_ADDR, an echo and an RM_ADDR each clear their own bit, and they have storage of their own: pm.local, pm.remote and pm.rm_list_tx. mptcp_pm_announce_addr() looks at its own bit only.
The callers have updated their state by then and ignore the result: the endpoint is gone, the announcement is forgotten, and the peer never learns that the address is not valid any more.
When the bit of an echo is set at the arrival of the peer's ADD_ADDR, it stays set until the PM worker has sent the ACK. An endpoint that is removed in between loses its RM_ADDR.
Only a pending RM_ADDR stands in the way, as rm_list_tx would be overwritten. A pure ACK carries the pending ADD_ADDR or echo first: up to three ACKs are then sent at once, preferably on a subflow that is not being removed, until one carries the RM_ADDR, and as long as they carry one of these signals. Otherwise, the RM_ADDR would go with the next packet, which could be sent on a subflow being removed, or after an ADD_ADDR re-announcing the same ID.
This issue has been found with the help of an LLM. It has not been
reproduced: the endpoint has to be removed before the PM worker sends the pending ADD_ADDR or echo, a window that a Packetdrill script cannot target. This fix is based on code inspection only, which is acceptable
here: the issue is clear from the code, and the fix is small.
[ Use mptcp_pm_should_rm_signal() instead of a comment. Fixes tag:
119c022096f5 instead of 42842a425ad6. Commit message: remove the number of attempts, say which packet carries the RM_ADDR then, and when the echo bit is set + how the issue was found, and why it is fine without a reproducer. Send the RM_ADDR at once, with up to three ACKs, instead of with the next packet. ]
---
v2: send the RM_ADDR at once, not with the next packet (Clashiko)
--- net/mptcp/pm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/mptcp/pm.c +12 -2
@@ -526,10 +526,11 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,int mptcp_pm_remove_addr (struct mptcp_sock *msk,const struct mptcp_rm_list *rm_list) {u8 rm_addr =READ_ONCE (msk->pm.addr_signal); +int i;pr_debug ("msk=%p, rm_list_nr=%d\n" , msk, rm_list->nr); -if (rm_addr) { +if (mptcp_pm_should_rm_signal (msk)) {MPTCP_ADD_STATS (sock_net ((struct sock *)msk),MPTCP_MIB_RMADDRTXDROP , rm_list->nr);return -EINVAL ;
@@ -538,7 +539,16 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_addr_send_ack_avoid_list (msk, rm_list); + +/* pending ADD_ADDR and echo take the first ACKs: one more each */ +for (i =0 ; i <3 &&mptcp_pm_should_rm_signal (msk); i++) { +u8 signal =READ_ONCE (msk->pm.addr_signal); + +mptcp_pm_addr_send_ack_avoid_list (msk, rm_list); +/* no signal sent, e.g. after a fallback: no more ACKs */ +if (READ_ONCE (msk->pm.addr_signal) == signal) +break ; + }return 0 ; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH mptcp-net v2 06/62] mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR
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] In mptcp_pm_remove_addr() (net/mptcp/pm.c:543-551), the new loop decides that an ACK carried no signal by comparing the whole…
--
mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR
With this patch, mptcp_pm_remove_addr() only refuses an RM_ADDR when another RM_ADDR is already pending. A pending ADD_ADDR or echo no longer blocks it. Up to three pure ACKs are then sent right away so that the RM_ADDR goes out after any pending ADD_ADDR or echo, preferably on a subflow that is not being removed.
Quoted 4 lines
net/mptcp/pm.c +0
-0
[ ... ]
Quoted 4 lines
net/mptcp/pm.c +0
-0@@ -538,7 +539,16 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr);
net/mptcp/pm.c int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ · line 550
Quoted 10 lines
net/mptcp/pm.c +9
-1-mptcp_pm_addr_send_ack_avoid_list (msk, rm_list); + +/* pending ADD_ADDR and echo take the first ACKs: one more each */ +for (i =0 ; i <3 &&mptcp_pm_should_rm_signal (msk); i++) { +u8 signal =READ_ONCE (msk->pm.addr_signal); + +mptcp_pm_addr_send_ack_avoid_list (msk, rm_list); +/* no signal sent, e.g. after a fallback: no more ACKs */ +if (READ_ONCE (msk->pm.addr_signal) == signal) +break ;
[Severity: Medium]
Can this comparison see an ABA on the echo bit and stop after an ACK that did carry a signal?
mptcp_pm_addr_send_ack_avoid_list() ends up in mptcp_pm_send_ack(), and that function drops pm.lock while the ACK is sent:
net/mptcp/pm.c:mptcp_pm_send_ack() {
spin_unlock_bh(&msk->pm.lock);
__mptcp_pm_send_ack(msk, subflow, prio, backup);
spin_lock_bh(&msk->pm.lock);
}Say the loop starts with signal == ECHO|RM. The pure ACK carries the echo first, and mptcp_pm_add_addr_signal() clears ECHO. While pm.lock is dropped, another HMAC-valid ADD_ADDR from the peer could arrive on a different CPU, for example a retransmission because our echo was late. mptcp_pm_add_addr_received() handles it in softirq under pm.lock. On the userspace PM path or the in-kernel reject path it calls:
mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk);
mptcp_pm_announce_addr() only checks BIT(MPTCP_ADD_ADDR_ECHO), so this succeeds and ECHO is set again.
Once the loop takes the lock back, addr_signal is again ECHO|RM, which is equal to signal. The loop then breaks on the "no signal sent" path while the RM_ADDR is still pending. The same thing can happen with SIG|ECHO|RM pending.
In mptcp_nl_remove_subflow_and_signal_addr(), mptcp_pm_rm_subflow() runs right after this. mptcp_subflow_shutdown() then sends a pure ACK on the subflow being removed. That ACK takes the re-set echo, so the RM_ADDR is left for the next packet on that subflow, such as its FIN.
The commit message describes the v2 loop as avoiding exactly this:
Otherwise, the RM_ADDR would go with the next packet, which could be sent on a subflow being removed
If that path is dead, which is a common reason to remove an endpoint, the peer would never learn about the RM_ADDR. TCP retransmissions would not resend it, because the signal bit has already been cleared.
Would it be more robust to check whether progress was made, for example with a counter of sent signals, or by checking the RM bit itself, instead of comparing the whole byte? Even with such a check, the fixed limit of three ACKs could still run out if new signals keep being set.
Quoted 3 lines
net/mptcp/pm.c +1
-0+ }return 0 ; }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 06/62] mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR
Hello,
Quoted 17 lines · On 23/11/2026 07:32, [email protected] wrote:
Quoted 4 lines
net/mptcp/pm.c +0
-0[ ... ]
Quoted 10 lines
net/mptcp/pm.c +5
-1@@ -538,7 +539,16 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ msk->pm.rm_list_tx = *rm_list; rm_addr |=BIT (MPTCP_RM_ADDR_SIGNAL );WRITE_ONCE (msk->pm.addr_signal, rm_addr); -mptcp_pm_addr_send_ack_avoid_list (msk, rm_list); + +/* pending ADD_ADDR and echo take the first ACKs: one more each */ +for (i =0 ; i <3 &&mptcp_pm_should_rm_signal (msk); i++) { +u8 signal =READ_ONCE (msk->pm.addr_signal); +
Quoted 8 lines
net/mptcp/pm.c int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_ · line 550
Quoted 4 lines
net/mptcp/pm.c +4
-0+mptcp_pm_addr_send_ack_avoid_list (msk, rm_list); +/* no signal sent, e.g. after a fallback: no more ACKs */ +if (READ_ONCE (msk->pm.addr_signal) == signal) +break ;[Severity: Medium]
Can this comparison see an ABA on the echo bit and stop after an ACK that did carry a signal?
Mmh, I shouldn't have changed this patch to address a comment from Clashiko from v1 that was not really important. It is fine to delay RM_ADDR or drop it at the end of the connection in case of ADD_ADDR (echo) to send first: a very rare/unlucky situation, it is not a big deal if a RM_ADDR is missed.
Back to v1 then.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 7/62 mptcp: pm: keep an RM_ADDR when computing the MSS
In reply to Matthieu Baerts (NGI0)tcp_current_mss() calls mptcp_established_options() without skb, to know the size of the options. A pending RM_ADDR was then taken: its signal bit was cleared, and RmAddrTx was incremented, but it was not sent. The peer then never learnt that the address was not valid any more. An ADD_ADDR is not affected: it is only sent with a pure ACK.
Without skb, only reserve the size of the RM_ADDR, and keep it pending for the packet that will be sent.
This issue has been reported by Clashiko, while reviewing commit "mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR", and confirmed with a script on an earlier version of that commit, where the RM_ADDR stayed pending longer: data was sent while it was pending. RmAddrTx was then 1 on the sender, but RmAddr 0 on the receiver. With that commit, the window is narrower: tcp_current_mss() has to be called between the moment the RM_ADDR is pending, and the moment the ACK is sent.
---
v2: new, for an issue spotted by Clashiko
--- net/mptcp/options.c | 12 +++++++++--- net/mptcp/pm.c | 8 ++++++-- net/mptcp/protocol.h | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-)
net/mptcp/options.c +9 -3
@@ -762,7 +762,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk,return true; } -static bool mptcp_established_options_rm_addr (struct sock *sk,int *size, +static bool mptcp_established_options_rm_addr (struct sock *sk, +struct sk_buff *skb,int *size,unsigned int remaining,struct mptcp_out_options *opts) {
@@ -772,9 +773,13 @@ static bool mptcp_established_options_rm_addr(struct sock *sk, int *size,int i;if (!mptcp_pm_should_rm_signal (msk) || - !(mptcp_pm_rm_addr_signal (msk, remaining, &rm_list, size))) + !(mptcp_pm_rm_addr_signal (msk, remaining, &rm_list, size, !skb)))return false; +/* without skb, only the size is needed: keep it for the next packet */ +if (!skb) +return true; + opts->suboptions |=OPTION_MPTCP_RM_ADDR ; opts->rm_list = rm_list;
@@ -933,7 +938,8 @@ int mptcp_established_options(struct sock *sk, struct sk_buff *skb, total_size += opt_size; remaining -= opt_size; ret = true; - }else if (mptcp_established_options_rm_addr (sk, &opt_size, remaining, opts)) { + }else if (mptcp_established_options_rm_addr (sk, skb, &opt_size, + remaining, opts)) { total_size += opt_size; remaining -= opt_size; ret = true;
net/mptcp/pm.c +6 -2
@@ -1026,7 +1026,8 @@ static int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list) }bool mptcp_pm_rm_addr_signal (struct mptcp_sock *msk,unsigned int remaining, -struct mptcp_rm_list *rm_list,int *size) +struct mptcp_rm_list *rm_list,int *size, +bool size_only) {int ret = false, len;u8 rm_addr;
@@ -1047,9 +1048,12 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, goto out_unlock; *size = len; + ret = true; +if (size_only) + goto out_unlock; + *rm_list = msk->pm.rm_list_tx;WRITE_ONCE (msk->pm.addr_signal, rm_addr); - ret = true; out_unlock:spin_unlock_bh (&msk->pm.lock);
net/mptcp/protocol.h +2 -1
@@ -1248,7 +1248,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, int *size, int remaining, struct mptcp_addr_info *addr, bool *echo, bool *drop_ts);bool mptcp_pm_rm_addr_signal (struct mptcp_sock *msk,unsigned int remaining, -struct mptcp_rm_list *rm_list,int *len); +struct mptcp_rm_list *rm_list,int *len, +bool size_only);int mptcp_pm_get_local_id (struct mptcp_sock *msk,struct sock_common *skc);bool mptcp_pm_is_backup (struct mptcp_sock *msk,struct sock_common *skc); int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 8/62 mptcp: arm the rtx timer if a push leaves data behind
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
In a memory shortage, send() on an idle MPTCP socket can succeed but leave its data unsent, and the connection stays stalled after the shortage has ended.
send() puts its data in the write queue of the MPTCP socket, and the push to a subflow leaves the data there if the memory charge to the subflow is refused or no skb can be allocated. A push that leaves data in the write queue has to be tried again, on the acknowledgment of data in flight or from the handler of the MPTCP retransmission (rtx) timer. But __mptcp_push_pending() and __mptcp_subflow_push_pending() arm that timer only if they have pushed data, so with no data in flight and no timer pending, the data waits for another event, such as the next send().
The fix used here is to also arm the timer, in both functions, if unsent data is left in the write queue.
This does not help a socket that has fallen back to TCP, as its rtx timer is disabled since commit e2ab913f68c7 ("mptcp: do not reschedule the RTX timer for fallback sockets"). "mptcp: force the charge for the first skb of a subflow" avoids a refused charge in this case, but not a failed skb allocation.
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, with fault injection: one skb allocation made to fail during a send(). Without this patch, the data accepted by this send() was only sent with the next one, 60 seconds later here:
3.007 s: CLIENT send() of 1,000 bytes returned 1000. Allocations that were made to fail in it: 1 [...]
63.008 s: CLIENT the second send(), of 100 bytes, returned 100
63.008 s: SERVER has 1200 bytes
RESULT-FAILSLAB [...] the_1000_bytes_at_the_server_at=never [...]
[...] arrived_before_the_second_send=no [...]
[ Shorter comment. Commit message: sockets that fell back to TCP are not
covered + how the issue was found, and its symptoms. ]
---
Note (Clashiko on v1): timer_ival cannot be 0 here in net: the in-kernel scheduler sets it before it can fail, and the timer is disabled after a fallback. Only the BPF schedulers, not in net, are affected.
--- net/mptcp/protocol.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
net/mptcp/protocol.c +8 -9
@@ -1850,14 +1850,11 @@ void __mptcp_push_pending(struct sock *sk, unsigned int flags)if (ssk)mptcp_push_release (ssk, &info); -/* Avoid scheduling the rtx timer if no data has been pushed; the timer -* will be updated on positive acks by __mptcp_cleanup_una(). -*/ -if (copied) { -if (!mptcp_rtx_timer_pending (sk)) -mptcp_reset_rtx_timer (sk); +/* also retry later if unsent data is left: no ack may trigger it */ +if ((copied ||mptcp_send_head (sk)) && !mptcp_rtx_timer_pending (sk)) +mptcp_reset_rtx_timer (sk); +if (copied)mptcp_check_send_data_fin (sk); - } }static void __mptcp_subflow_push_pending (struct sock *sk,struct sock *ssk,bool first)
@@ -1919,13 +1916,15 @@ static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, boolif (copied) {tcp_push (ssk,0 , info.mss_now,tcp_sk (ssk)->nonagle, info.size_goal); -if (!mptcp_rtx_timer_pending (sk)) -mptcp_reset_rtx_timer (sk);if (msk->snd_data_fin_enable && msk->snd_nxt +1 == msk->write_seq)mptcp_schedule_work (sk); } + +/* see __mptcp_push_pending() */ +if ((copied ||mptcp_send_head (sk)) && !mptcp_rtx_timer_pending (sk)) +mptcp_reset_rtx_timer (sk); }static int mptcp_disconnect (struct sock *sk,int flags);
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 9/62 mptcp: force the charge for the first skb of a subflow
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
After a fallback to TCP, an MPTCP connection can stay stalled once TCP memory use is back below the hard limit of net.ipv4.tcp_mem, and above that limit send() on an idle MPTCP socket can leave its data unsent.
A push moves data from the write queue of the MPTCP socket to a subflow, and charges the subflow twice: for a new skb in __mptcp_alloc_tx_skb() and for the payload in mptcp_sendmsg_frag(). On an idle socket, with nothing queued, TCP forces both charges past the limit, in tcp_stream_alloc_skb() and tcp_wmem_schedule(), since no ACK would ever restart such a socket. But a push forces neither, so above the hard limit both can be refused, and the push then moves no data.
The earlier commit "mptcp: arm the rtx timer if a push leaves data behind" repeats such a push from the MPTCP retransmission (rtx) timer. But each attempt fails while memory use stays above the limit. After a fallback that timer is disabled, so the data stays unsent until another event, such as the next send(), repeats the push.
The fix used here is to:
- force the charge for the skb if the subflow has nothing queued
- charge the payload with tcp_wmem_schedule()
- send only the bytes that tcp_wmem_schedule() grants
The first skb of an MPTCP-level reinjection is then forced too, as it is sent on a subflow with nothing queued. This is bounded the same way.
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 TCP memory shortage, for 30 seconds, during which each of ten idle MPTCP clients calls send() once. Without this patch, only 5 of them had their answer during the shortage, versus 8 with it: the 2 others are blocked in send() during the shortage, which is not fixed here. Some answers only came after the next send(), 300 seconds later, because of the issue fixed by the previous commit:
IDLE label=behind-the-second-send t=338.9 conn=0 [...] answer_at=336.4 IDLE label=behind-the-second-send t=338.9 conn=1 [...] answer_at=4.2
[ Shorter comments. Commit message: the first skb of a reinjection is
forced too + how the issue was found, and its symptoms. ]
---
Note (Sashiko on v1): info.mss_now and size_goal cannot be stale in net:
the in-kernel scheduler only picks a subflow that can send, which can then only move to TCP_CLOSE, where tcp_push() does nothing.
--- net/mptcp/protocol.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
net/mptcp/protocol.c +16 -7
@@ -1387,13 +1387,17 @@ static struct sk_buff *__mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gif (!skb)return NULL ; -if (likely (sk_wmem_schedule (ssk, skb->truesize))) { -tcp_skb_entail (ssk, skb); -return skb; +/* like TCP, force the charge if nothing is queued */ +if (tcp_rtx_and_write_queues_empty (ssk)) { +sk_forced_mem_schedule (ssk, skb->truesize); + }else if (unlikely (!sk_wmem_schedule (ssk, skb->truesize))) { +tcp_skb_tsorted_anchor_cleanup (skb); +kfree_skb (skb); +return NULL ; } -tcp_skb_tsorted_anchor_cleanup (skb); -kfree_skb (skb); -return NULL ; + +tcp_skb_entail (ssk, skb); +return skb; }static struct sk_buff *mptcp_alloc_tx_skb (struct sock *sk,struct sock *ssk,bool data_lock_held)
@@ -1449,6 +1453,7 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,bool reuse_skb = true;struct sk_buff *skb;size_t copy; +int avail;int i; pr_debug("msk=%p ssk=%p sending dfrag at seq=%llu len=%u already sent=%u\n",
@@ -1522,10 +1527,14 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, } copy =min_t (size_t, copy, info->limit - info->sent); -if (!sk_wmem_schedule (ssk, copy)) { + +/* like TCP, allow some progress up to tcp_wmem[0] */ + avail =tcp_wmem_schedule (ssk, copy); +if (avail <=0 ) {tcp_remove_empty_skb (ssk);return -ENOMEM ; } + copy = avail;if (can_coalesce) {skb_frag_size_add (&skb_shinfo (skb)->frags[i -1 ], copy);
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 10/62 mptcp: leave an orphan's DATA_FIN to the worker
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
Closed MPTCP sockets can leak until reboot, with the data in their receive queues, which can exhaust tcp_mem and stall other TCP connections.
Once close() has returned, only mptcp_worker() destroys an orphaned msk, and only in the run that moves it to TCP_CLOSE: a later run returns at once, and mptcp_schedule_work() queues no work for an msk in that state. The receive path, in softirq, puts data on the backlog while the msk is owned, and release_sock() calls mptcp_release_cb(), which passes the backlog to __mptcp_move_skbs(). But __mptcp_move_skbs() calls mptcp_check_data_fin(), which can move the msk to TCP_CLOSE, and by then the lock owner, here the worker, no longer looks at the state:
receive path, softirq mptcp_worker()
===================== ==============
not in TCP_CLOSE: no destroy
last data, with the DATA_FIN
the msk is owned: backlog
release_sock()
mptcp_release_cb()
__mptcp_move_skbs()
mptcp_check_data_fin()
TCP_CLOSE, never destroyed
The fix used here is to queue the worker in __mptcp_move_skbs() if an orphaned msk has a DATA_FIN to handle, instead of calling mptcp_check_data_fin().
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:
200,000 connections in which the server accept()s and close()s, while the client reads the end of file, sends one byte, and closes. Without this patch, some MPTCP sockets of the server stayed in the CLOSE state for good, with their network namespace:
=== connections so far : MPTCP sockets of the server in the state CLOSE: 200000:722, [...]
RESULT [...] | left 300 s behind the end: slab_MPTCP=722 sockets_MPTCP=722 [...] [...] | veth_end_left=1 slab_net_namespace_left=2 | [...]
[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]
--- net/mptcp/protocol.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +9 -3
@@ -2364,9 +2364,15 @@ static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delt }__mptcp_ofo_queue (msk); -if (moved) -mptcp_check_data_fin ((struct sock *)msk); -return moved; +if (!moved) +return false; + +/* Only the worker can close an orphan, as it must then destroy it */ +if (!sock_flag (sk,SOCK_DEAD )) +mptcp_check_data_fin (sk); +else if (mptcp_pending_data_fin (sk,NULL )) +mptcp_schedule_work (sk); +return true; }static bool mptcp_can_spool_backlog (struct sock *sk,struct list_head *skbs)
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 11/62 mptcp: don't leak an orphan when the PM closes its last subflow
In reply to Matthieu Baerts (NGI0)Once close() has returned, an orphaned MPTCP socket is only destroyed by mptcp_worker(), in the run that sees it in TCP_CLOSE: later on, the worker returns at once for an msk in this state, and mptcp_schedule_work() no longer queues it.
__mptcp_close_ssk() moves an orphan to TCP_CLOSE when, after the closure of a subflow, only the initial one remains, and it is closed. This function is not only called by the worker: path manager commands also close subflows of any msk of the netns, orphans included, under the msk
lock: e.g. 'ip mptcp endpoint delete' or 'flush' with the in-kernel PM, or MPTCP_PM_CMD_SUBFLOW_DESTROY with the userspace one. In this case, nothing destroys the orphan: it stays in TCP_CLOSE until the reboot, with its token, its initial subflow, and its reference to the netns, which is then never freed.
This can happen when the initial subflow has been reset or has timed out, and the connection is closed -- the orphan then waits for the end of the DATA_FIN exchange, up to TCP_TIMEWAIT_LEN -- before the endpoint used by another subflow is removed, e.g. when an interface goes down.
Only the worker can close an orphan, as it must then destroy it. So here, mark its close timeout as expired, and queue the worker, like it is done for an msk in the accept queue. The worker then closes the orphan with mptcp_do_fastclose() -- nothing is sent: the only subflow left is closed -- and destroys it. If __mptcp_close_ssk() was called by the worker, this happens later in the same run.
This issue has been found by an AI code review agent, while reviewing the code of the commit "mptcp: leave an orphan's DATA_FIN to the worker", and confirmed with a new Packetdrill test: the initial subflow of an orphan waiting for the end of the DATA_FIN exchange is reset, then the endpoint of the other subflow is removed. Without this patch, the orphan stayed:
UNCONN 0 0 192.168.0.1:8080 192.0.2.1:39933
kernel_orphan_last_subflow.pkt:39: error executing ! ss -HMan | grep -v LISTEN command: non-zero status 1
--- net/mptcp/protocol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +7 -2
@@ -2795,8 +2795,13 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,*/ if (list_is_singular (&msk->conn_list) && msk->first &&inet_sk_state_load (msk->first) ==TCP_CLOSE ) { -if (sk->sk_state !=TCP_ESTABLISHED || - msk->in_accept_queue ||sock_flag (sk,SOCK_DEAD )) { +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); + }else if (sk->sk_state !=TCP_ESTABLISHED || + msk->in_accept_queue) {mptcp_set_state (sk,TCP_CLOSE );mptcp_close_wake_up (sk); }else {
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 12/62 mptcp: keep an orphan while it can send its data
In reply to Matthieu Baerts (NGI0)The close timeout of an orphaned MPTCP socket started at close(), and its expiry reset the connection, while some data could still be waiting for the peer to open its window: a peer reading slowly or pausing got a reset 60 seconds after close(), and lost the end of the data, while TCP delivers it.
This timeout is there for the DATA_FIN exchange, see commit d866ae9aaa43 ("mptcp: add a new sysctl for make after break timeout"), and for an orphan that can no longer send anything. So restart it when the DATA_FIN is sent, and when it expires before, as long as a subflow can still send the data, which is then pushed again: an established subflow, on which the peer acked something recently, at least the window probes. Until then, as for a TCP socket that is not orphaned, nothing limits how long the peer can keep its window closed, while it acks the window probes. The timeout still starts at close(): the subflows are not TCP orphans, so its expiry is the only check that the orphan can still send.
This was reported on GitHub, with a reproducer: a server writes 2 MB, then calls close(), while the client pauses before reading the rest. After a pause of 90 seconds, the client got ECONNRESET, while TCP delivered everything, as MPTCP now does. If the client vanishes instead, the orphan is now reset as TCP does.
---
v2: new, for issue #647 reported on GitHub
--- net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
net/mptcp/protocol.c +31 -0
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 12/62] mptcp: keep an orphan while it can send its 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] The patch adds an unconditional close-timeout restart for orphans in mptcp_check_send_data_fin() (net/mptcp/protocol.c:3479-3481).
--
mptcp: keep an orphan while it can send its data
Before this patch, the close timeout of an orphaned MPTCP socket ran from close() and reset the connection when it expired, even if data was still waiting for the peer's window to open. The patch restarts the timeout when the DATA_FIN is sent. It also restarts the timeout and pushes the pending data again when the timeout expires before the DATA_FIN, as long as an active subflow has recently heard from the peer.
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
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 overwrite the forced expiry that __mptcp_close_ssk() sets when the last subflow of an orphan reaches TCP_CLOSE?
__mptcp_close_ssk() expects the worker to destroy the orphan on its next run:
net/mptcp/protocol.c:__mptcp_close_ssk() {
...
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);
...
}In mptcp_worker(), mptcp_pm_worker() runs before mptcp_check_send_data_fin(), and both run before the mptcp_close_tout_expired() checks.
When an orphan's last data is pushed from BH, __mptcp_subflow_push_pending() leaves the DATA_FIN to the worker:
if (msk->snd_data_fin_enable && msk->snd_nxt + 1 == msk->write_seq) mptcp_schedule_work(sk);
Suppose an RM_ADDR from the peer is queued before that worker runs. A userspace PM subflow destroy has the same effect. Then a single worker run does this:
mptcp_worker()
mptcp_pm_worker()
mptcp_pm_rm_addr_recv()
mptcp_pm_rm_addr_or_subflow()
mptcp_close_ssk()
__mptcp_close_ssk()
/* last subflow to TCP_CLOSE, close tout forced into the past */
mptcp_check_send_data_fin()
/* gate still open, snd_nxt = write_seq, SOCK_DEAD set */
mptcp_start_tout_timer()
/* probe_timestamp = tcp_jiffies32 */
mptcp_close_tout_expired()
/* now false, so __mptcp_destroy_sock() is skipped */Without this patch the orphan was destroyed in that same worker run. With it, the msk and its rtx queue stay around for another TCP_TIMEWAIT_LEN, although no subflow is left to carry the DATA_FIN exchange the new comment refers to. The orphan is freed only when the tout timer fires, because mptcp_orphan_keep() then returns false (snd_nxt == write_seq).
The delay is bounded and happens only once, so this is not a leak.
Would it make sense to restart only if the timeout has not already expired, for example:
if (sock_flag(sk, SOCK_DEAD) && !mptcp_close_tout_expired(sk)) mptcp_start_tout_timer(sk);
or to restart only while a subflow can still send?
Quoted 3 lines
net/mptcp/protocol.c +0
-0mptcp_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/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 13/62 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.
---
v2: new, to limit the orphans kept by the previous patch, with the same
Fixes tag to backport them together.
--- net/mptcp/protocol.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +28 -1
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 13/62] mptcp: limit an orphan probing a zero window
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_subflow_probe_timed_out() (net/mptcp/protocol.c:2875-2898) can only report a timeout while the…
--
mptcp: limit an orphan probing a zero window
This patch adds mptcp_subflow_probe_timed_out(). It reports whether TCP would have aborted a subflow that is probing a zero window, or that has data in flight after the peer shrank its window to zero. mptcp_orphan_keep() uses the new helper so that such an orphan is no longer kept once its close timeout expires.
Quoted 11 lines
net/mptcp/protocol.c +3
-0@@ -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) +{
[ ... ]
Quoted 16 lines
net/mptcp/protocol.c +16
-0+ 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; +} +
[ ... ]
net/mptcp/protocol.c static bool mptcp_orphan_keep(struct sock *sk) · line 2918
Quoted 9 lines
net/mptcp/protocol.c +2
-1@@ -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; }
[Severity: Medium]
Can a remote peer still keep this orphan forever if the subflow is idle at TCP level?
mptcp_subflow_probe_timed_out() only returns true when the subflow has data at TCP level. That means either data in flight with a zero snd_wnd, or a send head. With packets_out == 0 and tcp_send_head() == NULL, ret is always false.
Consider a peer that TCP-ACKs all subflow data with an open TCP window but never moves its DATA_ACK. msk->snd_una stays fixed, so the msk fills up to wnd_end and stops sending. mptcp_sendmsg_frag() then queues no MPTCP zero window probe:
net/mptcp/protocol.c:mptcp_sendmsg_frag() {
...
if (snd_una != msk->snd_nxt || skb->len ||
skb != tcp_send_head(ssk)) {
tcp_remove_empty_skb(ssk);
return 0;
}
...
}The subflow therefore stays idle at TCP level. Reinjections from __mptcp_retrans() are TCP-ACKed as well, and __mptcp_retrans() never gives up.
The peer can also pass the "live peer" check cheaply. tcp_ack() refreshes tp->rcv_tstamp on any non-old ACK, including a pure duplicate ACK. One segment sent more often than every 2 * TCP_RTO_MAX is enough.
mptcp_worker() then re-arms the close timeout each time it expires:
if (mptcp_close_tout_expired(sk) && mptcp_orphan_keep(sk)) {
mptcp_start_tout_timer(sk);
__mptcp_push_pending(sk, 0);
}None of these checks look at progress at the MPTCP level (snd_una or DATA_ACK).
There is a related case. mptcp_orphan_keep() returns true for the first subflow that passes the checks. Could an idle MP_JOIN subflow kept fresh this way keep the orphan alive after the probing subflow has timed out?
Before this series, these orphans were freed when the close timeout (TCP_TIMEWAIT_LEN) expired. The later patch "mptcp: count orphans as TCP does" caps the total through tcp_check_oom() (tcp_max_orphans and tcp_mem[2]). Below those limits, each orphan can still be kept as long as the peer wants, together with its subflows and queued send data.
The commit message also says:
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.
Is this accurate? mptcp_pm_chk_stale() in net/mptcp/pm.c skips idle subflows:
/* No data outstanding at TCP level? not stale */ if (tcp_rtx_and_write_queues_empty(ssk)) continue;
Also, mptcp_orphan_keep() uses __mptcp_subflow_active(), which does not check subflow->stale. So the idle subflow case seems to happen with default settings too.
The commit message also says "It is now reset as TCP does, respecting tcp_retries2." TCP gives up through tcp_write_timeout() when its data is never acknowledged. Here, MPTCP-level data that is never DATA_ACKed does not lead to a reset. Should either the check or the commit message be updated?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 13/62] mptcp: limit an orphan probing a zero window
Quoted 4 lines · On 23/11/2026 07:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
(...)
Quoted 16 lines
net/mptcp/protocol.c static bool mptcp_orphan_keep(struct sock *sk) · line 2918
Quoted 13 lines
net/mptcp/protocol.c +2
-1@@ -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; }[Severity: Medium]
Quoted 2 lines
Can a remote peer still keep this orphan forever if the subflow is idle at TCP level?
Only a misbehaving one, acking the data at the TCP level only, and these orphans are bounded by tcp_max_orphans and tcp_mem since the next patch, as with TCP.
(...)
Quoted 7 lines
The commit message also says:
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, andtcp_orphan_retriesis ignored.Is this accurate?
Yes: mptcp_subflow_active(), used by the scheduler, checks subflow->stale, and the data of a stale subflow is reinjected on the idle one, which then probes too. I will add a note in v3.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 14/62 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.
---
v2: new, spotted by a review agent
--- net/mptcp/protocol.c | 24 ++++++++++++++++++++++-- net/mptcp/protocol.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +22 -2
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 14/62] mptcp: count orphans as TCP does
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] When MPTCP resets an orphan because of memory pressure or too many orphans, the counter and the reset reason disagree.
--
mptcp: count orphans as TCP does
MPTCP sockets orphaned by close() are now counted in tcp_orphan_count. Like TCP orphans, they are reset when tcp_check_oom() reports too many orphans or too much TCP memory, both at close() and when the close timeout expires while the orphan is kept to send its data. These resets are counted in TCPAbortOnMemory.
Quoted 18 lines
net/mptcp/protocol.c +10
-0@@ -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; +} +
[ ... ]
net/mptcp/protocol.c bool __mptcp_close(struct sock *sk, long timeout) · line 3659
Quoted 13 lines
net/mptcp/protocol.c +7
-1@@ -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);
[Severity: Low]
Should this reset carry the abort on memory reason instead of the abort on close one?
mptcp_orphan_oom() counts the event in LINUX_MIB_TCPABORTONMEMORY. The reset is then sent by mptcp_do_fastclose(), which hard-codes the reason for every subflow:
net/mptcp/protocol.c:mptcp_do_fastclose() {
...
tcp_send_active_reset(ssk, SK_RST_REASON_TCP_ABORT_ON_CLOSE);
...
}include/net/rstreason.h maps SK_RST_REASON_TCP_ABORT_ON_CLOSE to LINUX_MIB_TCPABORTONCLOSE, and SK_RST_REASON_TCP_ABORT_ON_MEMORY to LINUX_MIB_TCPABORTONMEMORY. The TCP orphan path in __tcp_close(), which the commit message says this follows, keeps the two together:
tcp_send_active_reset(sk, SK_RST_REASON_TCP_ABORT_ON_MEMORY); __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY);
With this patch, a single MPTCP memory abort shows up as TcpExtTCPAbortOnMemory in nstat, but as TCP_ABORT_ON_CLOSE in the tcp_send_reset tracepoint.
The worker path has the same mismatch. There, mptcp_orphan_keep() returns false after mptcp_orphan_oom() fires, and the close timeout path then calls mptcp_do_fastclose().
The code is the same at the end of the series. Could the reset reason be passed into mptcp_do_fastclose(), so that these OOM paths can use SK_RST_REASON_TCP_ABORT_ON_MEMORY?
Quoted 4 lines
net/mptcp/protocol.c +1
-0+ }sock_hold (sk);pr_debug ("msk=%p state=%d\n" , sk, sk->sk_state);
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 15/62 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 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.
---
v2: new, for issue #647 reported on GitHub
--- net/mptcp/protocol.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
net/mptcp/protocol.c +16 -0
@@ -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 ;
@@ -2938,6 +2948,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 +3812,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 15/62] mptcp: return EOF after a DATA_FIN, as TCP does
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mptcp: mptcp_check_data_fin() misses SOCK_DONE after subflow disconnect - [Medium] mptcp: early…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] mptcp: mptcp_check_data_fin() misses SOCK_DONE after subflow disconnect
- [Medium] mptcp: early return in mptcp_check_fastclose() skips subflow close in FIN_WAIT2
--
commit b22772fa5573efd7e1960e51f06a318dfce6573b
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: return EOF after a DATA_FIN, as TCP does
This commit sets SOCK_DONE on the MPTCP socket when a DATA_FIN (or a TCP FIN after fallback) is processed and checks SOCK_DONE before sock_error() in mptcp_recvmsg() so that a subsequent reset still returns EOF after the queued data.
Quoted 16 lines
net/mptcp/protocol.c +4
-0@@ -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) {
net/mptcp/protocol.c static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk) · line 984
Quoted 9 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: Medium]
On a fallback connection, can __mptcp_close_ssk() clear SOCK_DONE on msk->first via tcp_disconnect() before mptcp_check_data_fin() or __mptcp_subflow_error_report() observes it?
mptcp_worker <softirq>lock_sock(sk)
tcp_fin(ssk)
sock_set_flag(ssk, SOCK_DONE)
mptcp_data_ready()
__mptcp_move_skbs_from_subflow()
/* queued to msk->backlog_list */
subflow_sched_work_if_closed()
msk->rcv_data_fin = 1
set_bit(MPTCP_WORK_CLOSE_SUBFLOW)
tcp_reset(ssk)
subflow_error_report()
__set_bit(MPTCP_ERROR_REPORT)mptcp_check_data_fin(sk)
/* backlog not spooled yet:
* ack_seq < rcv_data_fin_seq
*/__mptcp_close_subflow(sk)
__mptcp_close_ssk()
/* ssk == msk->first: !dispose_it */
__mptcp_subflow_disconnect()
tcp_disconnect(ssk, 0)
sock_reset_flag(ssk, SOCK_DONE)
goto out;
release_sock(sk)
mptcp_release_cb()
__mptcp_move_skbs()
mptcp_check_data_fin()
sock_flag(msk->first, SOCK_DONE) <-- false
__mptcp_error_report()
__mptcp_subflow_error_report()
sock_flag(ssk, SOCK_DONE) <-- falseBecause msk->backlog_list is not spooled before mptcp_worker() runs mptcp_check_data_fin() and __mptcp_close_subflow(), ssk->sk_receive_queue is already empty while msk->ack_seq has not yet caught up to msk->rcv_data_fin_seq. __mptcp_close_ssk() then disconnects msk->first and clears SOCK_DONE on ssk before mptcp_release_cb() processes the backlog and MPTCP_ERROR_REPORT, leaving SOCK_DONE unset on sk so mptcp_recvmsg() returns the reset error instead of EOF.
[ ... ]
net/mptcp/protocol.c static void mptcp_check_fastclose(struct mptcp_sock *msk) · line 2958
Quoted 12 lines
net/mptcp/protocol.c +5
-0@@ -2938,6 +2948,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) {
[Severity: Medium]
When sk is in TCP_FIN_WAIT2 and has both a pending DATA_FIN and an MP_FASTCLOSE, does calling mptcp_check_data_fin(sk) here cause mptcp_check_fastclose() to return early without setting MPTCP_WORK_CLOSE_SUBFLOW?
In TCP_FIN_WAIT2, mptcp_check_data_fin(sk) calls mptcp_shutdown_subflows(msk) and mptcp_send_ack(msk) (queuing a TCP FIN and transmitting FIN/ACK segments on subflows that are about to be reset) and transitions sk->sk_state to TCP_CLOSE:
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
case TCP_FIN_WAIT2:
mptcp_shutdown_subflows(msk);
mptcp_set_state(sk, TCP_CLOSE);
break;
...
}After the subflow loop sends active resets and calls tcp_set_state(tcp_sk, TCP_CLOSE), switch (sk->sk_state) in mptcp_check_fastclose() hits case TCP_CLOSE and returns before setting MPTCP_WORK_CLOSE_SUBFLOW, leaving the subflow sockets uncleaned on msk->conn_list until the parent MPTCP socket is closed.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
[email protected]
AI reviewRe: [PATCH mptcp-net v2 15/62] 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 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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] In mptcp_check_fastclose() (net/mptcp/protocol.c), the patch reads msk->rcv_data_fin, drains msk->backlog_list with…
- [Medium] mptcp: early return in mptcp_check_fastclose() skips subflow close in FIN_WAIT2
- [Medium] mptcp: mptcp_check_data_fin() misses SOCK_DONE after subflow disconnect
--
mptcp: return EOF after a DATA_FIN, as TCP does
When an MPTCP socket processes a DATA_FIN, this commit sets SOCK_DONE, as TCP does with a FIN. mptcp_recvmsg() then checks SOCK_DONE before the socket error, so recv() returns EOF instead of an error after a later reset. On MP_FASTCLOSE, the backlog is drained first so the DATA_FIN is not missed.
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
net/mptcp/protocol.c static void mptcp_check_fastclose(struct mptcp_sock *msk) · line 2958
Quoted 12 lines
net/mptcp/protocol.c +5
-0@@ -2938,6 +2948,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) {
[Severity: Medium]
On fallback, this check relies on SOCK_DONE still being set on msk->first when the DATA_FIN is finally processed on the msk. Can tcp_disconnect() clear it before that happens?
Consider data + FIN, then a RST, arriving on the fallback subflow while mptcp_worker() owns the msk socket lock. This can happen, for example, right after shutdown(SHUT_WR) has scheduled the worker:
softirq, msk owned by mptcp_worker():
tcp_fin(ssk) <- SOCK_DONE set on ssk
mptcp_data_ready()
__mptcp_move_skbs_from_subflow(msk, ssk, false)
payload moved to msk->backlog_list, ack_seq not advanced
subflow_sched_work_if_closed()
MPTCP_WORK_CLOSE_SUBFLOW set, rcv_data_fin = 1
RST: ssk moves to TCP_CLOSE, subflow_error_report() only defers via MPTCP_ERROR_REPORT
mptcp_worker():
mptcp_check_data_fin(sk)
backlog not spooled, ack_seq != rcv_data_fin_seq: no-op
__mptcp_close_subflow(sk)
mptcp_close_ssk()
__mptcp_close_ssk() <- ssk == msk->first, !dispose_it
__mptcp_subflow_disconnect()
tcp_disconnect(ssk, 0) <- SOCK_DONE cleared on ssk
goto out <- no error report here
release_sock(sk)
mptcp_release_cb()
backlog spooled -> mptcp_check_data_fin(sk)
sock_flag(msk->first, SOCK_DONE) is now false
MPTCP_ERROR_REPORT -> __mptcp_subflow_error_report(sk, ssk)
sock_flag(ssk, SOCK_DONE) is false as wellThe msk never gets SOCK_DONE. mptcp_recvmsg() then returns the data followed by EPIPE or ECONNRESET. That is the fallback case this patch is meant to fix with v1_connect_tcpfallback_fin_reset.pkt.
The mptcp_check_rcv_close() call added at the out label of __mptcp_close_ssk() later in the series, by "mptcp: no sf left:
process pending DATA_FIN", seems to see the same cleared flag.
A bare FIN + RST landing between mptcp_check_data_fin() and __mptcp_close_subflow() in mptcp_worker() looks like it can reach the same path.
Should the FIN seen on the first subflow be recorded on the msk side before the disconnect, e.g. in __mptcp_close_ssk() before calling __mptcp_subflow_disconnect()? That would avoid reading SOCK_DONE from msk->first later. Or should mptcp_worker() spool the backlog before its mptcp_check_data_fin() call, as mptcp_check_fastclose() now does?
[Severity: Medium]
What happens here if the msk is in TCP_FIN_WAIT2 and a DATA_FIN is pending when the MP_FASTCLOSE is processed? This can happen after shutdown(SHUT_WR) once the peer has sent its DATA_ACK.
In that state, mptcp_check_data_fin() takes its TCP_FIN_WAIT2 branch. It calls mptcp_shutdown_subflows() and mptcp_send_ack(), then moves the msk to TCP_CLOSE. So FIN and ACK segments get queued and sent, and the retransmit timer gets armed, on subflows that the loop just below is about to reset.
The bigger issue comes after that loop. The loop sends the resets and calls tcp_set_state(tcp_sk, TCP_CLOSE) on each subflow. The switch on sk->sk_state then hits the TCP_CLOSE case and returns early. That skips setting MPTCP_WORK_CLOSE_SUBFLOW in msk->flags.
The bit may not already be set, for example when the MP_FASTCLOSE arrived in a pure ACK or on another subflow. If so, and the msk is not SOCK_DEAD, mptcp_worker() never calls __mptcp_close_subflow(). It will not do anything more for this msk now that it is TCP_CLOSE.
tcp_set_state() alone does not stop the subflow timers or purge their write queues. The reset subflows therefore stay on msk->conn_list until userspace closes the msk. __mptcp_close() cleans them up at that point, so this is not a permanent leak. But a remote peer can trigger it by sending a DATA_FIN followed by an MP_FASTCLOSE.
Should this new block only move the pending data and set RCV_SHUTDOWN and SOCK_DONE, without going through the sk_state transitions in mptcp_check_data_fin()? Or should the TCP_CLOSE case below still make sure MPTCP_WORK_CLOSE_SUBFLOW is set when the subflows were just reset here?
[Severity: Medium]
Can a subflow running RX in BH on another CPU still race with this drain? The rcv_data_fin read, mptcp_move_skbs() and mptcp_check_data_fin() all run before the loop below takes each subflow lock with lock_sock_fast().
When a segment carries both data and a DATA_FIN, rcv_data_fin is published before the payload reaches msk->backlog_list:
subflow_data_ready()
mptcp_subflow_data_available()
get_mapping_status()
mptcp_update_rcv_data_fin() <- rcv_data_fin = 1
mptcp_data_ready()
mptcp_data_lock(sk)
__mptcp_move_skbs_from_subflow(msk, ssk, false) <- payload to backlog
Consider this interleaving:
CPU1 (subflow B, BH): parses MP_FASTCLOSE, sets rcv_fastclose, schedules the worker.
CPU2 (subflow A, BH): get_mapping_status() sets rcv_data_fin = 1.
CPU0 (mptcp_worker, msk owned): mptcp_check_fastclose() sees rcv_data_fin == 1. mptcp_move_skbs() finds the backlog still empty. mptcp_check_data_fin() then sees ack_seq != rcv_data_fin_seq and does nothing, so neither RCV_SHUTDOWN nor SOCK_DONE is set.
CPU2: takes the data lock and queues the payload on the backlog.
CPU0: lock_sock_fast(A) waits for CPU2 to finish. The subflows are then reset. The msk is still ESTABLISHED, so the switch sets sk_err to ECONNRESET and the msk moves to TCP_CLOSE.
Later, mptcp_release_cb() spools the late backlog. But the chain __mptcp_move_skbs()->mptcp_check_data_fin()->mptcp_pending_data_fin() now fails this check:
if (READ_ONCE(msk->rcv_data_fin) &&
((1 << inet_sk_state_load(sk)) &
(TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {So SOCK_DONE is never set. mptcp_recvmsg() would then return the data, followed by -ECONNRESET instead of EOF.
That is the behaviour the commit message describes as fixed: "recv() returned an error after the data ... instead of EOF as TCP does".
The later commit in the series, "mptcp: report errors as TCP does when closing", keeps the same order in mptcp_check_fastclose(). It still drains and checks first, then runs the subflow loop, then sets sk_err. So the window looks like it is still open at the end of the series.
Would it close the window to drain the backlog and call mptcp_check_data_fin() after the lock_sock_fast()/tcp_set_state(TCP_CLOSE) loop, but before the sk_state switch? By then any subflow BH already in progress has finished, and the closed subflows cannot receive anything more.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 15/62] mptcp: return EOF after a DATA_FIN, as TCP does
Quoted 5 lines · On 23/11/2026 07:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
- [Medium] In
mptcp_check_fastclose()(net/mptcp/protocol.c), the patch readsmsk->rcv_data_fin, drainsmsk->backlog_listwith…
Correct, will fix in v3.
Quoted 2 lines
- [Medium] mptcp: early return in
mptcp_check_fastclose()skips subflow close inFIN_WAIT2
No leak: reset subflows are released at close()
Quoted 2 lines
- [Medium] mptcp:
mptcp_check_data_fin()missesSOCK_DONEafter subflow disconnect
The connection will be reset by the peer anyway.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 16/62 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.
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.
---
v2: new, for a similar issue found by a review agent
--- net/mptcp/protocol.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
net/mptcp/protocol.c +16 -0
@@ -2940,6 +2940,18 @@ 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. +*/ +static bool mptcp_orphan_handover (const struct sock *sk) +{ +const struct mptcp_sock *msk =mptcp_sk (sk); + +return sock_flag (sk,SOCK_DEAD ) &&__mptcp_check_fallback (msk) && + msk->snd_nxt == msk->write_seq && !mptcp_data_avail (msk) && + !READ_ONCE (msk->backlog_len); +} +static void mptcp_check_fastclose (struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow, *tmp;
@@ -3287,6 +3299,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 16/62] mptcp: let TCP send orphan data after 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] This is a TOCTOU race in the new graceful hand-over, and the patch introduces it.
--
mptcp: let TCP send orphan data after fallback
This patch changes the close timeout path for an orphaned MPTCP socket that fell back to TCP. If all its data and the FIN were already handed to the subflow, the msk is now closed without a reset, so TCP can finish sending the remaining data. A reset is still expected when data received after close() was not read.
Quoted 20 lines
net/mptcp/protocol.c +12
-0@@ -2940,6 +2940,18 @@ 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. +*/ +static bool mptcp_orphan_handover (const struct sock *sk) +{ +const struct mptcp_sock *msk =mptcp_sk (sk); + +return sock_flag (sk,SOCK_DEAD ) &&__mptcp_check_fallback (msk) && + msk->snd_nxt == msk->write_seq && !mptcp_data_avail (msk) && + !READ_ONCE (msk->backlog_len); +} +
[ ... ]
net/mptcp/protocol.c static void mptcp_worker(struct work_struct *work) · line 3305
Quoted 8 lines
net/mptcp/protocol.c +4
-0@@ -3287,6 +3299,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 ); +
[Severity: Medium]
Can unread peer data still be dropped here without a reset being sent?
mptcp_orphan_handover() checks for unread data with only the msk socket lock held. It does not hold the data lock or any subflow lock, and the check is not repeated later. Holding the msk socket lock does not stop subflow RX in softirq.
Once the check passes, mptcp_worker() sets TCP_CLOSE and skips mptcp_do_fastclose(), going straight to __mptcp_destroy_sock(). The subflows keep feeding the msk until __mptcp_close_ssk() sets subflow->closing under the ssk lock. That only happens in mptcp_destroy_common(), after __mptcp_clear_xmit() and mptcp_backlog_purge().
A segment that arrives on the fallback subflow in that window would take this path:
subflow_data_ready()
mptcp_data_ready() /* closing still 0, msk owned by worker */
__mptcp_move_skbs_from_subflow(msk, ssk, false)
mptcp_init_skb() /* __skb_unlink() from ssk, copied_seq advanced */
__mptcp_add_backlog()
__mptcp_add_backlog() then frees it:
if (unlikely(sk->sk_state == TCP_CLOSE)) {
kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
return;
}If the skb was queued just before the state change, mptcp_backlog_purge() in mptcp_destroy_common() frees it instead.
Later, mptcp_destroy_common() calls __mptcp_close_ssk(), which calls __tcp_close(ssk, 0). __tcp_close() only sets data_was_unread for skbs still in the ssk receive queue past copied_seq. Here the skb has already been unlinked and copied_seq advanced. So no RST is sent, and the subflow closes gracefully.
After a fallback, the TCP ACK is the end-to-end acknowledgement. Would the peer then see its data acked and a clean FIN, even though the data was thrown away?
That seems to contradict this part of the commit message:
Unless data received after close() has not been read: as in __mptcp_close(), a reset is then needed.
Before this patch, an expired timeout always went through mptcp_do_fastclose() and then tcp_disconnect() on the subflow, so an RST was always sent in this case.
The window runs from the unlocked check until lock_sock_nested(ssk) in __mptcp_close_ssk().
Would it help to stop RX on each subflow (setting subflow->closing under its ssk lock) before checking for unread data? Other options would be to recheck under the data lock, or to record a drop in __mptcp_add_backlog() for a dead msk and send a reset in that case.
Quoted 3 lines
net/mptcp/protocol.c +0
-0if (mptcp_close_tout_expired (sk)) {struct mptcp_subflow_context *subflow, *tmp;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 17/62 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.
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)
---
v2: new, for an issue found by a review agent
--- net/mptcp/protocol.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/mptcp/protocol.c +1 -4
@@ -3245,10 +3245,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 17/62] 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] After this patch, an unaccepted MPTCP child that has fallen back to TCP sends two plain RSTs when its listener is closed.
- [Low] Fallen-back subflows now get an RST in states where TCP would not send one.
--
mptcp: reset the subflow on abort after fallback
This commit removes the fallback early return in mptcp_do_fastclose(). After a fallback to TCP, aborting an MPTCP socket now sends a plain TCP reset on each subflow. As a result, close() with unread data, or with SO_LINGER and a zero timeout, resets the connection instead of sending a FIN.
Quoted 6 lines
net/mptcp/protocol.c +0
-0@@ -3245,10 +3245,7 @@ static void mptcp_do_fastclose(struct sock *sk)mptcp_backlog_purge (sk);
net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3251
Quoted 10 lines
net/mptcp/protocol.c +1
-4msk->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 this early return gone, can an unaccepted child that fell back to TCP send two plain RSTs when its listener is closed?
The path looks like this:
mptcp_check_listen_stop()
mptcp_subflow_queue_clean()
__mptcp_unaccepted_force_close()
sock_set_flag(sk, SOCK_DEAD);
mptcp_do_fastclose(sk);
tcp_send_active_reset(ssk, ...); <- RST #1, ssk stays ESTABLISHED
__mptcp_destroy_sock(sk);
...
__mptcp_close_ssk()__mptcp_close_ssk() then takes the early accept-queue branch:
if (msk->in_accept_queue && msk->first == ssk &&
(sock_flag(sk, SOCK_DEAD) || sock_flag(ssk, SOCK_DEAD))) {
...
mptcp_subflow_drop_ctx(ssk);
goto out_release;
}That branch skips the transition that ae155060247b relies on to avoid duplicate resets:
if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE) tcp_set_state(ssk, TCP_CLOSE);
Back in mptcp_check_listen_stop(), inet_csk_listen_stop() -> inet_child_forget() -> tcp_disconnect() still sees the child in ESTABLISHED. tcp_need_reset() is true, so a second RST is sent.
Before this patch, a fallback msk returned early here and only the tcp_disconnect() RST went out. A peer can force the fallback on an unaccepted server socket by sending data without a DSS mapping, via subflow_check_data_avail() -> mptcp_try_fallback().
The same double reset already happened without a fallback (MP_FASTCLOSE RST, then a plain RST). This patch extends it to fallback sockets, which works against the goal of the commit in the Fixes: tag. The duplicate RST is still present at the end of the series.
Related to this, the commit message says:
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.
Should it also mention __mptcp_unaccepted_force_close()? The same goes for the orphan-OOM caller in __mptcp_close(), added earlier in this series:
if (mptcp_orphan_oom(sk)) mptcp_do_fastclose(sk);
After a fallback, that path used to close the subflow with a FIN through __tcp_close(), and it now sends an RST. That matches TCP's handling of orphans under OOM, but the commit message doesn't describe the change.
[Severity: Low]
Does this also send an RST on fallback subflows in LAST_ACK or CLOSING, where plain TCP would not?
Before this patch, fallback subflows reached tcp_disconnect() through __mptcp_subflow_disconnect() and followed its ABORT rule:
} else if (tcp_need_reset(old_state)) {
tcp_send_active_reset(sk, SK_RST_REASON_TCP_STATE);
...
} else if (tp->snd_nxt != tp->write_seq &&
(1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK)) {Now they go through the filter in mptcp_do_fastclose(), which only skips TCPF_LISTEN | TCPF_CLOSE:
if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) goto unlock;
For example:
1. After a fallback, the peer sends a FIN.
2. The application calls shutdown(SHUT_WR). The subflow sends its FIN and enters LAST_ACK with snd_nxt == write_seq.
3. Before the final ACK arrives, the application calls close() with SO_LINGER {1, 0}.
__mptcp_close() then takes the linger-0 branch and calls mptcp_do_fastclose(), which sends an RST on the LAST_ACK subflow. connect(AF_UNSPEC) in the same state does the same through mptcp_disconnect(). Plain TCP in that state sends no RST, and neither did MPTCP after a fallback before this patch.
The SYN_SENT case is fixed later in this series by "mptcp: no fastclose reset from SYN_SENT subflows". CLOSING and LAST_ACK are still affected at the end of the series.
The commit message describes the change as resetting "as TCP does". Should the filter follow tcp_need_reset() and the unsent-data check for fallback subflows? If not, should the commit message mention this difference?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 18/62 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
---
v2: new, for issue #648 reported on GitHub
--- net/mptcp/protocol.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/protocol.c +3 -0
@@ -2813,6 +2813,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);
@@ -3306,6 +3308,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 19/62 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.
---
v2: new, for a similar issue found by a review agent
--- net/mptcp/protocol.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +6 -2
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 20/62 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.
---
v2: new, for an issue found by a review agent, and Sashiko
--- net/mptcp/protocol.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/mptcp/protocol.c +8 -0
@@ -2823,6 +2823,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 20/62] mptcp: start close timeout on initial sf shutdown
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mptcp: incomplete state handling on initial sf shutdown in __mptcp_close_ssk() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mptcp: incomplete state handling on initial sf shutdown in __mptcp_close_ssk()
--
commit 3ae1ff0e0bee2b5a84597ed1abd7a652f3bfc9b1
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: start close timeout on initial sf shutdown
This commit starts the MPTCP close timeout in __mptcp_close_ssk() when only the shut-down initial subflow remains in the connection list and is not yet in TCP_CLOSE.
Quoted 8 lines
net/mptcp/protocol.c +0
-0@@ -2823,6 +2823,14 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, }else {mptcp_start_tout_timer (sk); }
net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2835
Quoted 10 lines
net/mptcp/protocol.c +8
-0+ }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); } }
[Severity: Medium]
Should this branch fold mptcp_subflow_ctx(msk->first)->closing into the inet_sk_state_load(msk->first) == TCP_CLOSE condition above so that SOCK_DEAD, sk->sk_state != TCP_ESTABLISHED, and msk->in_accept_queue are handled the same way?
Because mptcp_close_ssk() already set subflow->close_event_done = true when shutting down msk->first, the later transition of msk->first to TCP_CLOSE will return early in mptcp_close_ssk() and never run the TCP_CLOSE branch:
- If sk->sk_state != TCP_ESTABLISHED (for instance TCP_CLOSE_WAIT or TCP_FIN_WAIT1), no new subflows can join, yet sk waits for the full close timeout instead of moving to TCP_CLOSE immediately.
- If msk->in_accept_queue is set when the peer sends a TCP FIN without DATA_FIN, starting the timer instead of closing sk leaves the unaccepted socket in TCP_ESTABLISHED; if the peer ACKs our FIN before accept(), mptcp_stream_accept() later sees msk->first in TCP_CLOSE, sets newsk to TCP_CLOSE, and calls mptcp_close_ssk(), which returns early without setting SEND_SHUTDOWN.
- If sock_flag(sk, SOCK_DEAD) is set, __mptcp_close() already set icsk_mtup.probe_timestamp, so !inet_csk(sk)->icsk_mtup.probe_timestamp is false and the orphan waits for the full close timeout instead of expiring immediately.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
[email protected]
AI reviewRe: [PATCH mptcp-net v2 20/62] mptcp: start close timeout on initial sf shutdown
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] In __mptcp_close_ssk() (net/mptcp/protocol.c:2826-2834), the new else-if arms the close timeout for every msk state except…
--
mptcp: start close timeout on initial sf shutdown
This patch adds a branch to __mptcp_close_ssk() that starts the MPTCP close timeout when the initial subflow is the only one left and has been shut down but not closed. Without it, an msk whose peer sent a FIN without DATA_FIN on the only subflow could keep send() or recv() blocked forever.
Quoted 6 lines
net/mptcp/protocol.c +0
-0@@ -2823,6 +2823,14 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, }else {
net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2833
Quoted 10 lines
net/mptcp/protocol.c +8
-0mptcp_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);
[Severity: Medium]
Should this branch use the same per-state handling as the branch just above it? That branch covers the same "only the initial subflow is left" case, but it treats each msk state differently:
net/mptcp/protocol.c:__mptcp_close_ssk() {
...
* For established sockets, allow an additional timeout before closing,
* as the protocol can still create more subflows.
*/
if (list_is_singular(&msk->conn_list) && msk->first &&
inet_sk_state_load(msk->first) == TCP_CLOSE) {
if (sock_flag(sk, SOCK_DEAD)) {
...
} else if (sk->sk_state != TCP_ESTABLISHED ||
msk->in_accept_queue) {
mptcp_set_state(sk, TCP_CLOSE);
...
} else {
mptcp_start_tout_timer(sk);
}
...
}The new branch arms the timer in every state except TCP_CLOSE. That includes msks still in the accept queue and msks that are not ESTABLISHED.
Take an msk that has not been accepted yet: it is ESTABLISHED, with in_accept_queue set by mptcp_sk_clone_init(). If the peer sends a FIN without DATA_FIN on the MP_CAPABLE subflow before accept(), this path seems reachable:
subflow_sched_work_if_closed()
-> MPTCP_WORK_CLOSE_SUBFLOWmptcp_worker()
__mptcp_close_subflow()
mptcp_close_ssk()
__mptcp_close_ssk()
__mptcp_subflow_disconnect() /* only tcp_shutdown(), closing = 1 */
mptcp_start_tout_timer(sk) /* new branch */
Before this patch, a live in_accept_queue msk never had probe_timestamp set.
If accept() is not called within close_timeout (60s by default), mptcp_worker() then calls mptcp_do_fastclose(). With fastclosing set, __mptcp_close_ssk(..., 0) reaches this code:
__mptcp_subflow_disconnect() {
...
WARN_ON_ONCE(tcp_disconnect(ssk, 0));
mptcp_subflow_ctx_reset(subflow);
...
}At that point the child socket is still in the TCP listener's accept queue. Is that sequence safe? Tracing accept() and listener teardown after it did not show a crash. Still, no pre-patch path did this for in_accept_queue msks.
Now take an accepted msk that is not ESTABLISHED, for example FIN_WAIT1/2 after shutdown(SHUT_WR), or CLOSE_WAIT, LAST_ACK or CLOSING. The initial subflow can be shut down instead of disposed through mptcp_pm_rm_addr_or_subflow(). That happens on a peer RM_ADDR for id 0 or on a userspace PM subflow destroy. The new branch then waits the full close_timeout before the fastclose.
__mptcp_finish_join() refuses new subflows unless the msk is ESTABLISHED:
if (sk->sk_state != TCP_ESTABLISHED) return false;
So nothing can recover the connection during that wait, and send() or recv() stays blocked for the whole timeout. In the same states, the branch above closes the msk as soon as the subflow reaches TCP_CLOSE.
This also differs from Documentation/networking/mptcp-sysctl.rst. It says close_timeout applies "in absence of any close or shutdown syscall" and "after the last subflow removal".
Could the new branch follow the branch above? That would mean arming the timer only for an accepted ESTABLISHED msk, not for in_accept_queue, and closing the other states once the subflow reaches TCP_CLOSE.
If the different handling is intended, could the commit message say so? It currently only says "start the close timeout, if it is not running yet". The code comment and the sysctl documentation would also need an update.
Quoted 3 lines
net/mptcp/protocol.c +0
-0} }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 20/62] mptcp: start close timeout on initial sf shutdown
Quoted 2 lines · On 23/11/2026 07:32, [email protected] wrote:
- [Medium] In
__mptcp_close_ssk()(net/mptcp/protocol.c:2826-2834), the new else-if arms the close timeout for every msk state except…
I didn't manage to reproduce this, I will add a note for v3.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 21/62 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.
---
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
@@ -1218,6 +1218,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
@@ -1228,9 +1232,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 ; }
@@ -1242,7 +1243,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 22/62 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: no error is reported, and SEND_SHUTDOWN is not set. With data still to be sent, poll() then reports EPOLLHUP, but neither EPOLLOUT, nor EPOLLERR.
This issue was causing the "fastclose test" subtest from mptcp_join.sh to be flaky: after the DATA_FIN from the client, then its MP_FASTCLOSE, the server, still having data to send, was killed after the timeout, with its MPTCP socket closed with RCV_SHUTDOWN only (-->):
timeout
(...)
mptcp UNCONN 0 0 [::ffff:10.0.1.1]:10121 [::ffff:10.0.1.2]:45220 (...) -->
(...) bytes_sent:92032 bytes_received:1024 bytes_acked:57344 (...)
(...)
[FAIL] client exit code 0, server 143
The root cause has been confirmed with a debug patch keeping the worker busy while the socket is in CLOSE_WAIT, until the subflow is closed: the same failure has been seen, with the socket closed in CLOSE_WAIT (8) with a pending MP_FASTCLOSE, and without error:
(...) closed with pending events, state=8 rcv_data_fin=0 rcv_fastclose=1 err=0
To fix this, process a pending MP_FASTCLOSE before the close, if the socket is still in use. With the same debug patch, this subtest then no longer failed.
---
v2: new, for an issue causing a flaky selftest
--- net/mptcp/protocol.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mptcp/protocol.c +5 -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); +/* subflow sockets can be either outgoing (connect) or incoming * (accept). *
@@ -2816,6 +2818,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 22/62] mptcp: no sf left: process pending MP_FASTCLOSE
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 commit message describes a symptom that an earlier patch in this series has already removed.
--
mptcp: no sf left: process pending MP_FASTCLOSE
This patch calls mptcp_check_fastclose() in __mptcp_close_ssk() before the MPTCP socket moves to TCP_CLOSE. That path runs when the last subflow is closed while the socket is not in TCP_ESTABLISHED. The goal is to handle an MP_FASTCLOSE that arrives after the worker has already run mptcp_check_fastclose(), which is otherwise ignored once the socket is closed.
Quoted 10 lines
When the last subflow is closed while the MPTCP socket is no longer in the ESTABLISHED state, e.g. in
CLOSE_WAITafter aDATA_FIN, the MPTCP socket moves toTCP_CLOSE. But this subflow could have been closed by a reset carrying anMP_FASTCLOSE, not processed yet: if this reset is received while the worker is running, aftermptcp_check_fastclose(), and before__mptcp_close_subflow(). At the next run of the worker, the MPTCP socket being closed, theMP_FASTCLOSEis ignored: no error is reported, andSEND_SHUTDOWNis not set. With data still to be sent,poll()then reports EPOLLHUP, but neither EPOLLOUT, nor EPOLLERR.
Quoted 4 lines
This issue was causing the "fastclose test" subtest from
mptcp_join.shto be flaky: after theDATA_FINfrom the client, then itsMP_FASTCLOSE, the server, still having data to send, was killed after the timeout, with its MPTCP socket closed withRCV_SHUTDOWNonly (-->):
[Severity: Medium]
Is "SEND_SHUTDOWN is not set" still accurate at this point in the series?
The earlier patch "mptcp: wake up blocked senders when no sf left" already sets it in the same branch of __mptcp_close_ssk() that this patch changes. These are the context lines around the new mptcp_check_fastclose() call:
net/mptcp/protocol.c:__mptcp_close_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);
...
}With SEND_SHUTDOWN set, mptcp_poll() reports EPOLLOUT:
if (shutdown & SEND_SHUTDOWN) mask |= EPOLLOUT | EPOLLWRNORM;
The next write then gets EPIPE from mptcp_sendmsg():
ret = -EPIPE; if (unlikely(READ_ONCE(sk->sk_err) || (sk->sk_shutdown & SEND_SHUTDOWN))) goto do_error;
Can the server in the fastclose test still time out with only the earlier patch applied?
The server is started with "-f -1", which sets cfg_rcv_trunc. In that case copyfd_io_poll() in mptcp_connect.c treats EPIPE as expected:
if (cfg_rcv_trunc &&
(errno == ECONNRESET ||
errno == EPIPE)) {
fds.events &= ~POLLOUT;
continue;
}If so, the server would exit normally instead of being killed with exit code 143. The RCV_SHUTDOWN-only state ("-->") in the quoted ss output also seems to come from a kernel without the earlier patch.
On top of the earlier patch, the remaining change from this patch seems to be what mptcp_check_fastclose() does for the pending MP_FASTCLOSE:
- sk_err set to EPIPE or ECONNRESET
- SHUTDOWN_MASK and sk_error_report()
- the token destruction
- the DATA_FIN and backlog handling
Could the commit message describe that effect instead? It could also claim the flaky subtest fix only if the subtest still fails with just the earlier patch. Both patches carry the same Fixes: 27e5ccc2d5a5 tag, so the current wording may give stable backports the wrong idea about which patch fixes the selftest.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 22/62] mptcp: no sf left: process pending MP_FASTCLOSE
Quoted 5 lines · On 23/11/2026 07:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
- [Medium] The commit message describes a symptom that an earlier patch in this series has already removed.
Yes, I will rewrite the commit message.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 23/62 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.
---
v2: new, for an issue causing flaky selftests
--- net/mptcp/protocol.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +13 -3
@@ -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). *
@@ -2818,9 +2830,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 23/62] mptcp: no sf left: process pending DATA_FIN
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mptcp: tcp_disconnect() clears SOCK_DONE before mptcp_check_rcv_close() - [Medium] mptcp: pending…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] mptcp: tcp_disconnect() clears SOCK_DONE before mptcp_check_rcv_close()
- [Medium] mptcp: pending DATA_FIN skipped for TCP_ESTABLISHED in __mptcp_close_ssk()
--
commit 95271396d761d6456e08d69c39becd026df9d3ed
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 __mptcp_close_ssk() transitions the MPTCP socket to TCP_CLOSE.
Quoted 24 lines
net/mptcp/protocol.c +12
-0@@ -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 2833
Quoted 7 lines
net/mptcp/protocol.c +1
-3@@ -2818,9 +2830,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);
[Severity: Medium]
On a fallback connection, does calling mptcp_check_rcv_close(sk) here fail to propagate SOCK_DONE to sk?
When __mptcp_close_ssk() closes msk->first without disposing it, it calls __mptcp_subflow_disconnect() -> tcp_disconnect(ssk, 0) before reaching out:, which clears SOCK_DONE on msk->first. When mptcp_check_rcv_close() then calls mptcp_check_data_fin(), the fallback check cannot set SOCK_DONE:
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);
...
}If sk->sk_err is set (for example, if a RST follows the peer's FIN), mptcp_recvmsg() and mptcp_splice_read() will return the error instead of EOF after draining the spooled data.
[Severity: Medium]
Can gating mptcp_check_rcv_close(sk) behind sk->sk_state != TCP_ESTABLISHED skip a pending DATA_FIN when the peer's final data is still in msk->backlog_list?
When final data and a DATA_FIN arrive on an established, accepted socket while mptcp_worker() holds the socket lock, the data sits in msk->backlog_list. In mptcp_worker(), mptcp_check_data_fin() sees msk->ack_seq < msk->rcv_data_fin_seq and leaves sk in TCP_ESTABLISHED before __mptcp_close_subflow() runs. Because sk->sk_state is still TCP_ESTABLISHED here, __mptcp_close_ssk() skips mptcp_check_rcv_close() and starts the close timeout timer instead. When release_sock() later spools the backlog, mptcp_check_data_fin() moves sk to TCP_CLOSE_WAIT after msk->first is already closed, leaving sk in TCP_CLOSE_WAIT without SEND_SHUTDOWN until the close timeout expires.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
[email protected]
AI reviewRe: [PATCH mptcp-net v2 23/62] mptcp: no sf left: process pending DATA_FIN
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: tcp_disconnect() clears SOCK_DONE before mptcp_check_rcv_close()
--
Quoted 5 lines
net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2836
Quoted 10 lines
net/mptcp/protocol.c +1
-3@@ -2818,9 +2830,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]
On a fallback connection, I think this is called too late for mptcp_check_data_fin() to propagate SOCK_DONE to the MPTCP socket.
To reach this branch, msk->first is the only subflow and is already in TCP_CLOSE, and the msk is not SOCK_DEAD, so dispose_it is false. That means __mptcp_subflow_disconnect() has already been called on msk->first before jumping to out:. With the subflow in TCP_CLOSE, it calls tcp_disconnect(ssk, 0), which unconditionally clears SOCK_DONE on the subflow.
mptcp_check_rcv_close() then spools the backlog and calls mptcp_check_data_fin(). On fallback, that function only sets SOCK_DONE on sk if msk->first still has SOCK_DONE, which tcp_disconnect() just reset. This is the exact case the patch is fixing: the last data and the FIN were received while the worker owned the msk, so the data is still in msk->backlog_list. In that case rcv_data_fin is consumed, but SOCK_DONE is never set on sk.
That matters for mptcp_recvmsg() and mptcp_splice_read(). Suppose sk_err gets set afterwards, e.g. by a RST following the peer's FIN, or by the error set on close from FIN_WAIT1/CLOSING later in this series. Without SOCK_DONE on sk, the reader would get -ECONNRESET or -EPIPE after draining the data instead of 0 (EOF).
Should SOCK_DONE on msk->first be sampled before the subflow is disconnected? Or should mptcp_check_rcv_close() be called earlier in __mptcp_close_ssk(), before __mptcp_subflow_disconnect()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 23/62] mptcp: no sf left: process pending DATA_FIN
Quoted 5 lines · On 23/11/2026 07:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
Quoted 8 lines
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:
tcp_disconnect()clearsSOCK_DONEbeforemptcp_check_rcv_close()
This looks like the same issue as the one described in the review of patch 15. So that will be fixed there.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 24/62 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.
---
v2: new, for an issue found by a review agent
--- net/mptcp/protocol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +3 -1
@@ -4679,8 +4679,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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 24/62] mptcp: process pending close events at accept()
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mptcp: dummy fallback DATA_FIN processed on reset in mptcp_stream_accept() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mptcp: dummy fallback DATA_FIN processed on reset in mptcp_stream_accept()
--
commit 41ac450ef8d0029d02acbe4bb5044a609c4a37c5
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: process pending close events at accept()
This commit calls mptcp_check_rcv_close() in mptcp_stream_accept() before transitioning an accepted MPTCP socket whose only subflow is already closed to TCP_CLOSE.
Quoted 6 lines
net/mptcp/protocol.c +0
-0@@ -4679,8 +4679,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,* deal with bad peers not doing a complete shutdown.
net/mptcp/protocol.c static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, · line 4688
Quoted 10 lines
net/mptcp/protocol.c +3
-1*/ 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)); }
[Severity: Medium]
Can calling mptcp_check_rcv_close(newsk) here process a dummy fallback DATA_FIN when a passive socket falls back to TCP and is reset by the peer before accept()?
When a socket in the accept queue falls back to TCP (for example, on receiving data without a DSS option) and then receives a peer TCP RST without a FIN, subflow_error_report() skips propagating ssk->sk_err while sk->sk_socket is NULL, and subflow_sched_work_if_closed() emulates msk->rcv_data_fin = 1 even though SOCK_DONE is not set on msk->first.
Calling mptcp_check_rcv_close(newsk) here runs mptcp_check_data_fin():
net/mptcp/protocol.c:mptcp_check_data_fin() {
...
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) {
case TCP_ESTABLISHED:
mptcp_set_state(sk, TCP_CLOSE_WAIT);
break;
...
}Because __mptcp_close_ssk() takes the !dispose_it path for msk->first and skips __mptcp_subflow_error_report(), newsk is left with RCV_SHUTDOWN set and sk_err == 0, so a subsequent recv() returns 0 (EOF) instead of -ECONNRESET. Even with the follow-up commit "mptcp: report errors as TCP does when closing", mptcp_check_data_fin() has already moved newsk to TCP_CLOSE_WAIT without setting SOCK_DONE, causing mptcp_close_last_err() -> mptcp_reset_err() to overwrite ECONNRESET with EPIPE.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
[email protected]
AI reviewRe: [PATCH mptcp-net v2 24/62] mptcp: process pending close events at accept()
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: dummy fallback DATA_FIN processed on reset in mptcp_stream_accept()
--
Quoted 6 lines
net/mptcp/protocol.c +0
-0@@ -4679,8 +4679,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,* deal with bad peers not doing a complete shutdown.
net/mptcp/protocol.c static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, · line 4688
Quoted 10 lines
net/mptcp/protocol.c +3
-1*/ 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)); }
[Severity: Medium]
Could this new call change the result for a fallback socket that gets a TCP RST before accept()?
If the passive msk falls back to TCP after the MP_CAPABLE handshake, and the peer then resets msk->first without sending a FIN, subflow_sched_work_if_closed() sees subflow_is_done() and emulates a DATA_FIN by setting msk->rcv_data_fin. That happens even though SOCK_DONE is not set on msk->first.
While the msk is still in the accept queue, sk->sk_socket is NULL. subflow_error_report() therefore returns early, and the reset is never propagated to newsk->sk_err.
mptcp_check_rcv_close(newsk) then calls mptcp_check_data_fin(), which consumes the emulated DATA_FIN. SOCK_DONE is correctly left unset, because msk->first has no SOCK_DONE. However, RCV_SHUTDOWN is still set, and newsk moves from TCP_ESTABLISHED to TCP_CLOSE_WAIT.
mptcp_close_ssk() on msk->first then takes the !dispose_it branch in __mptcp_close_ssk(). That branch jumps to out and skips __mptcp_subflow_error_report(). newsk->sk_err stays at 0, so after the queued data, recv() returns 0 (clean EOF) rather than -ECONNRESET.
With the follow-up "mptcp: report errors as TCP does when closing" applied, mptcp_close_last_err() does pick up msk->first->sk_err. But mptcp_reset_err() now sees TCP_CLOSE_WAIT and reports EPIPE instead of ECONNRESET, while SOCK_DONE is still unset.
Should the emulated fallback DATA_FIN be ignored here when msk->first was reset without a FIN? Or should the subflow error be latched on newsk before mptcp_check_rcv_close() runs? I'm not sure which one fits better with the rest of the series.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 24/62] mptcp: process pending close events at accept()
Quoted 5 lines · On 23/11/2026 07:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
- [Medium] mptcp: dummy fallback
DATA_FINprocessed on reset inmptcp_stream_accept()
Pre-existing: I will see if I can fix that.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 25/62 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.
---
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
@@ -4428,6 +4428,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 26/62 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)
---
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
@@ -3804,6 +3804,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 27/62 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. 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. Then, 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.
---
v2: new, for an issue spotted by Sashiko
--- net/mptcp/protocol.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +13 -2
@@ -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 by tcp_abort(): 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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 27/62] mptcp: report sf aborts during deferred connect
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] mptcp_sendmsg_fastopen() (net/mptcp/protocol.c:1979-1986) adds an early return 0 for 'DEFER_CONNECT set on the msk but cleared on…
- [Low] The new comment in mptcp_sendmsg_fastopen() (net/mptcp/protocol.c:1976) says 'subflow aborted by tcp_abort(): its…
--
mptcp: report sf aborts during deferred connect
This patch adds a check to mptcp_sendmsg_fastopen(), taken after the first subflow lock is held. If DEFER_CONNECT is still set on the msk but has been cleared on the first subflow, the subflow error is passed to the msk right away, and the function returns early. mptcp_sendmsg() then reports the error via sk_stream_wait_connect() instead of returning -EISCONN.
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
net/mptcp/protocol.c static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 1978
Quoted 8 lines
net/mptcp/protocol.c +4
-0@@ -1974,6 +1972,19 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, ssk = msk->first;lock_sock (ssk); + +/* subflow aborted by tcp_abort(): its error report may be deferred. +* With MSG_FASTOPEN, the socket is disconnected below, as with TCP. +*/
[Severity: Low]
This isn't a bug, but the comment seems narrower than the condition it guards. The commit message says the same thing:
"if DEFER_CONNECT is set on the msk, but no longer on the subflow, the subflow has been aborted."
The check below matches any path that clears DEFER_CONNECT on msk->first. tcp_disconnect() also clears the bit, and it sets sk_err on a SYN_SENT socket:
net/ipv4/tcp.c:tcp_disconnect() {
...
inet_clear_bit(DEFER_CONNECT, sk);
...
}MPTCP calls it on a SYN_SENT first subflow from mptcp_subflow_shutdown(). PM subflow removal can reach that, for example through mptcp_pm_nl_subflow_destroy_doit() or mptcp_pm_rm_addr_or_subflow(). The msk bit stays set:
mptcp_subflow_shutdown() {
...
case TCP_SYN_SENT:
WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
...
}__mptcp_close_ssk() keeps msk->first for the first subflow, so the new check can still be reached after that.
tcp_abort() also clears the bit before its "Avoid closing the same socket twice" check. On a subflow that is already closed, the bit is cleared and tcp_abort() returns -ENOENT without aborting anything.
The tcp_disconnect() case still gets the right msk error, through __mptcp_close_ssk()->mptcp_close_last_err().
Could the comment and the commit message say that the check covers any clearing of DEFER_CONNECT on the first subflow, not only tcp_abort()?
net/mptcp/protocol.c static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 1986
Quoted 8 lines
net/mptcp/protocol.c +8
-0+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 ; + }
[Severity: Low]
This early return also handles the case with no race. That is when tcp_abort() hits the first subflow while the msk is not owned. The msk is then already in TCP_CLOSE with sk_err set to ECONNABORTED, but its DEFER_CONNECT bit is still set.
The commit message describes this case as:
"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."
Does this case also change what userspace sees?
Before this patch, tcp_sendmsg_fastopen() skipped tcp_connect(). It then called __inet_stream_connect() on the msk socket, which went from SS_CONNECTING to the TCP_CLOSE check and then to:
net/ipv4/af_inet.c:__inet_stream_connect() {
...
sock_error:
err = sock_error(sk) ? : -ECONNABORTED;
sock->state = SS_UNCONNECTED;
...
}After that, the fallback at the end of mptcp_sendmsg_fastopen() disconnected the msk:
if (!mptcp_disconnect(sk, 0)) {
sk->sk_disconnects++;
sk->sk_socket->state = SS_UNCONNECTED;
}So write() returned -ECONNABORTED, and connect() could be called again right away.
After this patch, write() still returns -ECONNABORTED, but it now comes from sk_stream_wait_connect(), which consumes sk_err. Nothing disconnects the socket, so sock->state stays SS_CONNECTING.
The next connect() or sendto(MSG_FASTOPEN) goes through __inet_stream_connect() again. It reaches sock_error a second time, returns -ECONNABORTED again because sk_err is now 0, and only then disconnects.
This matches plain TCP after tcp_abort(), which seems to be the intent. The patch has a Fixes: tag and will probably go to stable. Could the commit message mention this user-visible change on the non-race path?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 27/62] mptcp: report sf aborts during deferred connect
Quoted 10 lines · On 23/11/2026 07:32, [email protected] wrote:
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]
mptcp_sendmsg_fastopen()(net/mptcp/protocol.c:1979-1986) adds an earlyreturn 0for 'DEFER_CONNECTset on the msk but cleared on…
- [Low] The new comment inmptcp_sendmsg_fastopen()(net/mptcp/protocol.c:1976) says 'subflow aborted bytcp_abort(): its…
Yes, I can update the commit message and comment...
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 28/62 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: the subflow is still moved to TCP_CLOSE, and a later SYN-ACK 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)
---
v2: new, for an issue found by a review agent
--- net/mptcp/protocol.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mptcp/protocol.c +4 -0
@@ -3297,6 +3297,10 @@ static void mptcp_do_fastclose(struct sock *sk) subflow->send_fastclose =1 ; +/* no reset in SYN_SENT, as TCP does */ +if (ssk->sk_state ==TCP_SYN_SENT ) + 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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 28/62] mptcp: no fastclose reset from SYN_SENT subflows
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mptcp: race on TCP_SYN_SENT subflow in mptcp_do_fastclose() after unlock --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mptcp: race on TCP_SYN_SENT subflow in mptcp_do_fastclose() after unlock
--
commit 7e20c0b8af4ba4b67481ee3130ee19f18fec3566
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: no fastclose reset from SYN_SENT subflows
This commit skips calling tcp_send_active_reset() in mptcp_do_fastclose() when a subflow socket is in TCP_SYN_SENT.
net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3302
Quoted 11 lines
net/mptcp/protocol.c +3
-0@@ -3297,6 +3297,10 @@ static void mptcp_do_fastclose(struct sock *sk) subflow->send_fastclose =1 ; +/* no reset in SYN_SENT, as TCP does */ +if (ssk->sk_state ==TCP_SYN_SENT ) + goto unlock;
[Severity: Medium]
Can an incoming SYN-ACK race with release_sock(ssk) here because ssk is left in TCP_SYN_SENT with subflow->send_fastclose = 1 until the caller invokes __mptcp_close_ssk()?
CPU0 CPU1 (softirq)mptcp_do_fastclose()
lock_sock(ssk)
subflow->send_fastclose = 1
if (ssk->sk_state == TCP_SYN_SENT)
goto unlock;
tcp_v4_rcv() (SYN-ACK arrives)
sk_add_backlog(ssk, skb, ...)
release_sock(ssk)
__release_sock(ssk)
tcp_v4_do_rcv()
tcp_rcv_state_process()
tcp_rcv_synsent_state_process()
tcp_set_state(ssk, TCP_ESTABLISHED)
tcp_send_ack(ssk)__mptcp_close_ssk()
lock_sock_nested(ssk, ...)
if (subflow->send_fastclose &&
ssk->sk_state != TCP_CLOSE)
tcp_set_state(ssk, TCP_CLOSE) <-- silently closes without RST/FIN
If the SYN-ACK completes the handshake in that window, __mptcp_close_ssk()
sees subflow->send_fastclose == 1 and forces ssk to TCP_CLOSE before__mptcp_subflow_disconnect() or __tcp_close(), leaving the peer in ESTABLISHED without sending a RST or FIN. Conversely, if subflow_finish_connect() rejects the SYN-ACK (for example on an MP_JOIN subflow because the parent msk is already in TCP_CLOSE) and calls mptcp_subflow_reset(), having subflow->send_fastclose == 1 still attaches MP_FASTCLOSE to that reset.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
[email protected]
AI reviewRe: [PATCH mptcp-net v2 28/62] mptcp: no fastclose reset from SYN_SENT subflows
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] After this patch, a SYN-ACK that arrives during a race window can complete the handshake, and the subflow is then closed without…
--
mptcp: no fastclose reset from SYN_SENT subflows
This patch makes mptcp_do_fastclose() skip sending a reset with MP_FASTCLOSE on subflows that are still in SYN_SENT, which matches what tcp_disconnect() does through tcp_need_reset(). The subflow keeps send_fastclose set and is moved to TCP_CLOSE later.
net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3303
Quoted 12 lines
net/mptcp/protocol.c +4
-0@@ -3297,6 +3297,10 @@ static void mptcp_do_fastclose(struct sock *sk) subflow->send_fastclose =1 ; +/* no reset in SYN_SENT, as TCP does */ +if (ssk->sk_state ==TCP_SYN_SENT ) + goto unlock; +
[Severity: Medium]
The commit message says:
"Skip them again in this state, as TCP does: the subflow is still moved to TCP_CLOSE, and a later SYN-ACK gets a reset from the stack."
With this branch, a SYN_SENT subflow leaves mptcp_do_fastclose() with only send_fastclose set. It is still TCP_SYN_SENT and still hashed.
The move to TCP_CLOSE happens later, in __mptcp_close_ssk(), after it takes the ssk lock again:
if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE)
tcp_set_state(ssk, TCP_CLOSE);Can a SYN-ACK complete the handshake between these two points? There are two ways it could reach the subflow in this window. It could already be on the ssk backlog when release_sock(ssk) runs __release_sock(). It could also arrive in softirq before __mptcp_close_ssk() takes the lock. That second case can happen in mptcp_disconnect() -> mptcp_destroy_common(), after sk_stream_wait_close() in __mptcp_close(), or in the close timeout loop in mptcp_worker().
In either case the SYN-ACK would go through:
tcp_rcv_synsent_state_process()
tcp_finish_connect() /* ssk becomes ESTABLISHED */
subflow_finish_connect() /* icsk_af_ops->sk_rx_dst_set */
mptcp_finish_connect()
mptcp_pm_new_connection() /* MPTCP_EVENT_CREATED */
subflow_finish_connect() does not check whether the msk is TCP_CLOSE or whether msk->fastclosing is set. The third ACK with MP_CAPABLE would go out and the peer would create an established connection. Userspace would also get MPTCP_EVENT_CREATED after the connection was already reported closed.
After that, __mptcp_close_ssk() moves the now-ESTABLISHED subflow straight to TCP_CLOSE. The tcp_disconnect() called from __mptcp_subflow_disconnect() then starts with old_state == TCP_CLOSE, so tcp_need_reset() is false and no RST is sent. The __tcp_close() path for non-first subflows doesn't send one either. Wouldn't the peer be left half-open?
Plain TCP has no such window. tcp_disconnect() sets TCP_CLOSE and unhashes the socket while it holds the socket lock. A backlogged SYN-ACK then hits the TCP_CLOSE case in tcp_rcv_state_process(), and a later one finds an unhashed tuple and gets a reset from the stack.
The reset this patch removes probably didn't prevent the problem before either. tcp_acceptable_seq() returns tcp_wnd_end(), which is the ISN in SYN_SENT because snd_wnd is 0 and rx_opt.wscale_ok is not set yet. The peer's tcp_check_req() expects ISN+1, so it would drop that reset as out of window. The window therefore seems to date from ae155060247b, named in the Fixes: tag. Even so, this patch doesn't fully deliver the "as TCP does" behaviour described in the commit message.
Could this branch move the subflow to TCP_CLOSE, for example with tcp_set_state(ssk, TCP_CLOSE), before jumping to release_sock(ssk)?
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(). */
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 28/62] mptcp: no fastclose reset from SYN_SENT subflows
Quoted 16 lines · On 23/11/2026 07:32, [email protected] wrote:
net/mptcp/protocol.c static void mptcp_do_fastclose(struct sock *sk) · line 3303
Quoted 12 lines
net/mptcp/protocol.c +4
-0@@ -3297,6 +3297,10 @@ static void mptcp_do_fastclose(struct sock *sk) subflow->send_fastclose =1 ; +/* no reset in SYN_SENT, as TCP does */ +if (ssk->sk_state ==TCP_SYN_SENT ) + goto unlock; +[Severity: Medium]
The commit message says:
Quoted 5 lines
"Skip them again in this state, as TCP does: the subflow is still moved to
TCP_CLOSE, and a later SYN-ACK gets a reset from the stack."With this branch, a
SYN_SENTsubflow leavesmptcp_do_fastclose()with onlysend_fastcloseset. It is stillTCP_SYN_SENTand still hashed.
Indeed.
(...)
Quoted 2 lines
Could this branch move the subflow to
TCP_CLOSE, for example withtcp_set_state(ssk, TCP_CLOSE), before jumping torelease_sock(ssk)?
Yep, will fix in v3.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 29/62 mptcp: keep listening after MSG_FASTOPEN errors
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.
Skip this disconnect for a listener: it keeps listening, 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)
---
v2: new, for an issue found by a review agent
--- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +2 -1
@@ -2004,11 +2004,12 @@ 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 ) {/* 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 is not disconnected there, as with TCP. */ if (!mptcp_disconnect (sk,0 )) { sk->sk_disconnects++;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH mptcp-net v2 29/62] mptcp: keep listening after MSG_FASTOPEN errors
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: 1 · Medium: 0 · 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] This patch is incomplete.
--
mptcp: keep listening after MSG_FASTOPEN errors
This patch skips the mptcp_disconnect() retry in mptcp_sendmsg_fastopen() when the msk is a listener. A failed sendmsg() with MSG_FASTOPEN then no longer closes an MPTCP listener. The retry exists to redo a disconnect that failed inside __inet_stream_connect().
net/mptcp/protocol.c static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 2007
Quoted 10 lines
net/mptcp/protocol.c +1
-1@@ -2004,11 +2004,12 @@ 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 ) {
[Severity: High]
Does the TCP_LISTEN check fully cover the case described in the commit message, where there is nothing to retry?
__inet_stream_connect() calls disconnect() in only two places. One is the AF_UNSPEC branch, which tcp_sendmsg_fastopen() already rejects. The other is the sock_error label:
sock_error:
err = sock_error(sk) ? : -ECONNABORTED; sock->state = SS_UNCONNECTED; sk->sk_disconnects++; if (sk->sk_prot->disconnect(sk, flags)) sock->state = SS_DISCONNECTING;
Other errors return without trying a disconnect. One example:
case SS_CONNECTED: err = -EISCONN; goto out;
The same is true of -EINVAL, and of the -EOPNOTSUPP, -EALREADY and -ENOBUFS returns in tcp_sendmsg_fastopen(), which happen before __inet_stream_connect() is called. For a msk that is not a listener, the mptcp_disconnect() retry still runs for all of these errors.
This sequence looks reachable:
- an established MPTCP socket calls shutdown(SHUT_WR), and the msk goes to FIN_WAIT1, then FIN_WAIT2
- the peer sends data, then a DATA_FIN. mptcp_check_data_fin() moves the msk to TCP_CLOSE. sock->state stays SS_CONNECTED, and the data stays unread in sk_receive_queue
- the application calls send(fd, buf, len, MSG_FASTOPEN)
- __mptcp_nmpc_sk() accepts TCPF_CLOSE. tcp_sendmsg_fastopen()->__inet_stream_connect() returns -EISCONN from the SS_CONNECTED case without trying a disconnect
- back in mptcp_sendmsg_fastopen(), sk_state is TCP_CLOSE rather than TCP_LISTEN, so mptcp_disconnect(sk, 0) runs. It succeeds because fastopening is 0 by then
mptcp_disconnect()->mptcp_destroy_common() then does:
__skb_queue_purge(&sk->sk_receive_queue); skb_rbtree_purge(&msk->out_of_order_queue);
On top of that:
- the subflows are fast-closed
- the token and PM state are destroyed
- sk_shutdown and SOCK_DONE are cleared
- the socket is forced to SS_UNCONNECTED
Userspace sees only -EISCONN, but the unread data and the EOF are gone. Plain TCP returns -EISCONN via sk_stream_error() and leaves the socket and its data untouched.
The same unwanted disconnect seems to happen on a TCP_CLOSE msk when the TFO client sysctl is disabled and tcp_sendmsg_fastopen() returns -EOPNOTSUPP.
Would it make sense to retry only when a disconnect really failed? __inet_stream_connect() sets sock->state to SS_DISCONNECTING in exactly that case. Another option is for mptcp_disconnect() to record that it returned -EBUSY.
Either check would also cover the listener, which stays SS_UNCONNECTED. It could then replace the TCP_LISTEN check instead of being added next to it.
This code appears unchanged at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 29/62] mptcp: keep listening after MSG_FASTOPEN errors
Quoted 1 line · On 23/11/2026 07:32, [email protected] wrote:
Would it make sense to retry only when a disconnect really failed?
Indeed, I can filter out disconnected sockets in v3.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 30/62 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: keep listening after MSG_FASTOPEN errors": 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)
---
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
@@ -3977,6 +3977,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 31/62 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
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
[ Shorter comment, the details are in the commit message. Commit
message: how the issue was found, and its symptoms. ]
--- net/mptcp/subflow.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mptcp/subflow.c +5 -0
@@ -312,6 +312,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 32/62 net: add __sk_net_refcnt_upgrade() with a GFP mask
In reply to Matthieu Baerts (NGI0)sk_net_refcnt_upgrade() gives a kernel socket a reference on its network namespace, with a netns tracker allocated with GFP_KERNEL. The next commit needs to do that for a socket created in atomic context: the child of a kernel MPTCP listener, created when an MP_JOIN request is accepted.
Add __sk_net_refcnt_upgrade(), taking the GFP mask to use, and make sk_net_refcnt_upgrade() call it with GFP_KERNEL: no functional change for the existing callers.
The 'Fixes' tag here below is the same as the one from the next commit:
this patch is needed to fix the issue introduced by this commit ID.
--- include/net/sock.h | 1 + net/core/sock.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/net/sock.h +1 -0
@@ -1869,6 +1869,7 @@ static inline bool sock_allow_reclassification(const struct sock *csk)struct sock *sk_alloc (struct net *net,int family,gfp_t priority,struct proto *prot,int kern);void sk_free (struct sock *sk); +void __sk_net_refcnt_upgrade (struct sock *sk,gfp_t gfp);void sk_net_refcnt_upgrade (struct sock *sk);void sk_destruct (struct sock *sk);struct sock *sk_clone (const struct sock *sk,const gfp_t priority,bool lock);
net/core/sock.c +7 -2
@@ -2407,7 +2407,7 @@ static void __sk_destruct(struct rcu_head *head)sk_prot_free (sk->sk_prot_creator, sk); } -void sk_net_refcnt_upgrade (struct sock *sk) +void __sk_net_refcnt_upgrade (struct sock *sk,gfp_t gfp) {struct net *net =sock_net (sk);
@@ -2415,9 +2415,14 @@ void sk_net_refcnt_upgrade(struct sock *sk)__netns_tracker_free (net, &sk->ns_tracker, false);net_passive_dec (net); sk->sk_net_refcnt =1 ; -get_net_track (net, &sk->ns_tracker,GFP_KERNEL ); +get_net_track (net, &sk->ns_tracker, gfp);sock_inuse_add (net,1 ); } + +void sk_net_refcnt_upgrade (struct sock *sk) +{ +__sk_net_refcnt_upgrade (sk,GFP_KERNEL ); +}EXPORT_SYMBOL_GPL (sk_net_refcnt_upgrade);void sk_destruct (struct sock *sk)
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 33/62 mptcp: pm: don't let listeners pin their netns
In reply to Matthieu Baerts (NGI0)From: Josef Bacik <[email protected]>
For a "signal" endpoint with a port, the in-kernel path manager creates a listening MPTCP socket with sock_create_kern(). This socket is released when the endpoint is deleted or, failing that, by pm_nl_exit_net() when the network namespace is dismantled.
The MPTCP socket itself holds no reference on the namespace. But its first subflow is created by mptcp_subflow_create_socket(), which always calls sk_net_refcnt_upgrade(). So the namespace cannot be dismantled before the listener is released, and the listener is not released before the namespace is dismantled: unless somebody deletes the endpoint, both stay around for ever once the last process of the namespace is gone.
unshare -Urn sh -c 'ip link set lo up;
ip mptcp endpoint add 127.0.0.1 port 4321 signal'
leaks a namespace, with everything it contains, each time it is run. It remains charged to the user's max_net_namespaces limit.
Only take the reference if the MPTCP socket has one. A listening TCP socket has no timer of its own, and request sockets of a dead namespace are taken care of by inet_twsk_purge().
The sockets cloned from that listener for incoming MP_JOIN requests do need the reference, for their timers, but inherit sk_net_refcnt == 0. Take it when they are created, with __sk_net_refcnt_upgrade(), from the previous commit, as this is done in atomic context, and drop the connection request if the namespace is already going away.
The TCP listener of such an endpoint is now a plain kernel socket, like the MPTCP socket it belongs to: it is not counted in "sockets: used" in /proc/net/sockstat any more, and its destruction is not broadcast to the listeners of the SKNLGRP_INET*_TCP_DESTROY sock_diag groups.
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:
the command above, run 1000 times by an unprivileged user. Without this patch, all the network namespaces were leaked:
result: 1000 network namespaces made, 0 taken down, 1000 are left
[ Use __sk_net_refcnt_upgrade(), from the previous commit, instead of an
open-coded copy of sk_net_refcnt_upgrade(), with maybe_get_net() like rds_tcp_tune(). Shorter comments, and describe the condition: any kernel msk. Commit message: how the issue was found, and its symptoms. ]
--- net/mptcp/subflow.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
net/mptcp/subflow.c +24 -1
@@ -849,6 +849,22 @@ void __mptcp_subflow_fully_established(struct mptcp_sock *msk,WRITE_ONCE (msk->fully_established, true); } +/* Children of a kernel listener need a netns ref for their timers */ +static bool subflow_child_get_net (struct sock *child) +{ +struct net *net =sock_net (child); + +if (likely (child->sk_net_refcnt)) +return true; + +if (!maybe_get_net (net)) +return false; + +__sk_net_refcnt_upgrade (child,GFP_ATOMIC ); +put_net (net); +return true; +} + static struct sock *subflow_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, struct request_sock *req,
@@ -917,6 +933,11 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,tcp_rsk (req)->drop_req = false; +if (!subflow_child_get_net (child)) { +subflow_add_reset_reason (skb,MPTCP_RST_EUNSPEC ); + goto dispose_child; + } +/* we need to fallback on ctx allocation failure and on pre-reqs * checking above. In the latter scenario we additionally need * to reset the context to non MPTCP status.
@@ -1868,8 +1889,10 @@ int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,/* kernel sockets do not by default acquire net ref, but TCP timer * needs it. * Update ns_tracker to current stack trace and refcounted tracker. +* Not for a kernel msk, e.g. a PM listener: it would pin the netns. */ -sk_net_refcnt_upgrade (sf->sk); +if (sk->sk_net_refcnt) +sk_net_refcnt_upgrade (sf->sk); err =tcp_set_ulp (sf->sk,"mptcp" );if (err) goto err_free;
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 34/62 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)
[ 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
@@ -1502,8 +1502,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 );
@@ -1518,6 +1518,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 35/62 mptcp: initialize drop_req in subflow_init_req()
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
With CONFIG_MPTCP and SO_REUSEPORT migration, which net.ipv4.tcp_migrate_req=1 or a BPF program enables, TCP sockets can leak until reboot, and each keeps its network namespace alive.
tcp_check_req() keeps a child off the accept queue if drop_req is true in a request socket that an MPTCP listener created. drop_req has one writer, subflow_syn_recv_sock(), which tcp_check_req() calls before that test only for an MPTCP listener. But if SO_REUSEPORT migration moves the request socket to a plain TCP listener, the test reads what the allocation left in drop_req, and nothing drops the last reference of a child that stays off the accept queue.
The fix used here is to set drop_req to false in subflow_init_req(), which runs when the request socket of an MPTCP listener is set up.
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, run as an unprivileged user in a user namespace, with net.ipv4.tcp_migrate_req=1: an MPTCP listener and a TCP one sharing a port with SO_REUSEPORT, the MPTCP one being closed while handshakes complete. Without this patch, the children were leaked, with their network namespace, without any message from the kernel:
repro: step 3 to 6: 32 SYNs, 16 went to A. A closed, 16 third ACKs. accept() on B returned 0 [...]
repro: RESULT: 16 children never reached an accept queue
repro: one RST for each connection. TCP: inuse 0 orphan 0 tw 0 alloc 16 mem 0 === exit code 0. The process and its namespaces are gone
=== after: TCP sockets allocated, all namespaces: 16 [...]
With UBSAN, the original version of this patch also reported:
UBSAN: invalid-load in [...]/include/net/mptcp.h:144:47 load of value 14 is not a valid value for type '_Bool' tcp_check_req.cold+0xb6/0x189 tcp_v4_rcv+0x11f4/0x4230
[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]
--- net/mptcp/subflow.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/subflow.c +3 -0
@@ -151,6 +151,9 @@ static void subflow_init_req(struct request_sock *req, const struct sock *sk_lis subflow_req->allow_join_id0 =mptcp_allow_join_id0 (sock_net (sk_listener)); subflow_req->msk =NULL ;mptcp_token_init_request (req); + +/* read by tcp_check_req() even after migration to a TCP listener */ +tcp_rsk (req)->drop_req = false; }static bool subflow_use_different_sport (struct mptcp_sock *msk,const struct sock *sk)
Signature · 1 line
2.55.0
Matthieu Baerts (NGI0)
maintainerPATCH v2 36/62 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 inTCP_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)
---
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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 37/62 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.
---
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
@@ -4540,6 +4540,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);
@@ -4556,6 +4557,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 );
@@ -4570,7 +4572,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 38/62 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.
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.
---
v2: new, for an issue causing a flaky selftest
--- net/mptcp/protocol.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/mptcp/protocol.c +6 -0
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 38/62] 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: 1 · Medium: 0 · 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 holds only while the subflow MSS never drops below the pre-fallback MSS.
--
mptcp: send the infinite map in a single segment
This commit caps the skb that carries the MPTCP infinite mapping at one MSS in mptcp_sendmsg_frag(), using the MSS computed before the fallback. Before this change, the skb could be sized with the pre-fallback size goal. After the fallback, its segments still carried a DSS option and could exceed the MTU, which stalled the transfer.
net/mptcp/protocol.c static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, · line 1490
Quoted 13 lines
net/mptcp/protocol.c +5
-0@@ -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;
[Severity: High]
Does this keep the infinite mapping in a single segment only while the subflow MSS stays at or above the pre-fallback info->mss_now?
Right after this skb is queued, mptcp_update_infinite_map() clears the flag:
mptcp_subflow_ctx(ssk)->send_infinite_map = 0;
After that, MSS computations call mptcp_established_options() with skb == NULL, and it reserves no option space:
if (unlikely(__mptcp_check_fallback(msk) && !mptcp_check_infinite_map(skb))) return 0;
The queued skb still has mpext->infinite_map = 1, though. It is still sent with a DSS option, about 28 bytes with ack64.
The PMTU can drop while this skb is unsent or unacked. One example is an ICMP Frag-Needed for this very segment, which can be the first full-size segment when MP_FAIL arrives before any data. In that case, would the retransmission path split the skb with an MSS that has no room for the DSS?
tcp_v4_mtu_reduced()
tcp_sync_mss()
tcp_simple_retransmit()
...__tcp_retransmit_skb()
cur_mss = tcp_current_mss(sk); /* no DSS room after the fallback */
tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE, skb, len, cur_mss, GFP_ATOMIC)
mptcp_skb_ext_copy(buff, skb); /* infinite_map copied to each piece */
tso_fragment() copies the extension in the same way. Each piece is then cur_mss plus the DSS option, which is larger than the new PMTU.
With DF set, ip_fragment() drops the piece. The local ICMP carries the same MTU, so icsk_pmtu_cookie is not lowered.
Would every RTO retransmission be rebuilt the same way, so that the connection stalls until tcp_retries2 is reached?
A smaller overshoot also looks possible when TCP timestamps are not negotiated. The skb is sized for the DSS option without SACK. If SACK blocks appear later, the post-fallback MSS reserves room only for the SACK blocks. The DSS option plus SACK blocks could then put the segment 4 to 12 bytes over the MTU.
The later patch "mptcp: keep room for infinite map after fallback" reserves DSS space only while send_infinite_map is set. That is before this skb is created, so the gap seems to remain at the end of the series.
Would it be more robust to keep the DSS space reserved in the MSS calculation (skb == NULL) until the infinite-map skb has been acked? That would also make this cap unnecessary.
Quoted 3 lines
net/mptcp/protocol.c +0
-0skb =tcp_write_queue_tail (ssk);if (skb && copy > skb->len) {/* Limit the write to the size available in the
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 38/62] mptcp: send the infinite map in a single segment
Quoted 2 lines · On 23/11/2026 07:32, [email protected] wrote:
Does this keep the infinite mapping in a single segment only while the subflow MSS stays at or above the pre-fallback
info->mss_now?
Wow... that's theoretical and from what I got, it needs DSS checksums, an MP_FAIL, and a PMTU drop (or SACK blocks without TS) while the infinite mapping is in flight!!
Same comment on patch 39.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 39/62 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 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
---
v2: new, for an issue spotted by Sashiko
--- net/mptcp/options.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/options.c +4 -2
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 39/62] mptcp: keep room for infinite map after 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] The DSS reservation only lasts while subflow->send_infinite_map is set, and that flag is cleared before the…
--
mptcp: keep room for infinite map after fallback
After a fallback, mptcp_established_options() now keeps reserving room for the DSS option when the MSS is computed (skb == NULL), as long as subflow->send_infinite_map is set. Without this, the skb carrying the infinite mapping could be sized without DSS room. Its segments would then be bigger than the MTU and the connection would stall.
Quoted 6 lines
net/mptcp/options.c +0
-0@@ -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: Medium]
Is send_infinite_map the right flag to base this reservation on? The flag seems to be cleared before the infinite-map skb is ever sent, while mptcp_sendmsg_frag() is still building it:
net/mptcp/protocol.c:mptcp_update_infinite_map() {
...
mpext->infinite_map = 1;
mpext->data_len = 0;
if (!mptcp_try_fallback(ssk, MPTCP_MIB_INFINITEMAPTX)) {
...
}
mptcp_subflow_ctx(ssk)->send_infinite_map = 0;
}After that, tcp_write_xmit(), __tcp_retransmit_skb() and tcp_write_wakeup() all call tcp_current_mss(). That goes through tcp_established_options(sk, NULL, ...), and this check now returns 0 MPTCP option bytes.
However, __tcp_transmit_skb() on the same skb still sees mptcp_check_infinite_map(skb) == true. It then emits the 24 or 28 byte DSS.
The single-segment cap from "mptcp: send the infinite map in a single segment" (copy = mss_now) seems to hold only if nothing changes between building the skb and its last (re)transmission. Can either of these cases still produce segments bigger than the MTU?
(A) The PMTU drops while the infinite-map skb is not yet acked. Then tcp_current_mss()->tcp_sync_mss() returns an MSS with no DSS room, and __tcp_retransmit_skb() splits the skb at that cur_mss:
__tcp_retransmit_skb()
cur_mss = tcp_current_mss(sk);
...
tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE, skb, len, cur_mss, GFP_ATOMIC)
mptcp_skb_ext_copy(buff, skb);Both fragments keep the infinite_map ext and emit the DSS, so each one is the new MSS plus the DSS. If no split happens, the skb is still sized for the old MTU.
Either way, DF is set, so IP drops the packets. The local frag-needed reports the same MTU, so the MSS never shrinks. The subflow then keeps retransmitting oversized packets until it times out.
(B) Timestamps are off, and SACK or DSACK blocks appear between building the skb and sending or resending it.
At build time the 28 byte DSS is counted and there is no SACK, so skb->len = mss_cache - 28. At transmit time only the 12 byte SACK is counted, so mss_now = mss_cache - 12, which is larger than skb->len, and no split happens.
The real options are 28 + 12 = 40 bytes, so the segment is 12 bytes over the MTU. This repeats as long as the SACK state lasts, for example while the skb is waiting on cwnd or rwnd, or is being retransmitted.
Both cases look like the same stall that the commit message says is fixed:
"Keep room for the DSS option while the infinite mapping is still to be sent, when computing the MSS."
Should the reservation last as long as an infinite-map skb is still unacked, instead of ending once that skb has been built? The code at the end of the series appears to use the same logic, so a later patch does not seem to address this.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 40/62 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.
[ 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
@@ -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
@@ -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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 41/62 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
[ 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
@@ -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
@@ -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
@@ -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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 42/62 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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 43/62 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.
[ 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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 44/62 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.
---
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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 45/62 tcp: do not pass a BPF reqsk to an MPTCP listener
In reply to Matthieu Baerts (NGI0)From: Chris Mason <[email protected]>
A slab-out-of-bounds write and a panic can occur if a tc BPF program that validates SYN cookies assigns an ACK to a TCP listener, and the ACK then goes to an MPTCP listener of the same SO_REUSEPORT group.
bpf_sk_assign_tcp_reqsk() attaches a plain TCP request sock to the skb, and returns -EINVAL if the program passes in an MPTCP listener. But inet_steal_sock() and inet6_steal_sock() select a listener again from the SO_REUSEPORT group of the listener that was passed in, and the result can be an MPTCP listener. cookie_bpf_check() then passes the request sock to mptcp_subflow_init_cookie_req(), which writes to members of the larger struct mptcp_subflow_request_sock, so the writes can land in the next object of the slab.
The fix used here is to drop the segment in cookie_bpf_check() if the listener is an MPTCP listener.
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 tc BPF program validating SYN cookies -- the one from the BPF selftests -- and an SO_REUSEPORT group with a TCP listener and an MPTCP one, the latter being selected. With KASAN, the original version of this patch reported:
BUG: KASAN: slab-out-of-bounds in mptcp_subflow_init_cookie_req Write of size 1 at addr ... by task python3 mptcp_subflow_init_cookie_req cookie_bpf_check cookie_v4_check tcp_v4_do_rcv tcp_v4_rcv
Without debug options, and with request sockets of half-open connections next to the corrupted one, the kernel panicked a second later, when the timer of a request socket fired:
BUG: kernel NULL pointer dereference, address: 000000000000058f #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page Oops: Oops: 0000 [#1] SMP NOPTI CPU: 3 UID: 0 PID: 0 Comm: swapper/3 Not tainted 7.4.0-rc1+ #1 PREEMPT(lazy) RIP: 0010:tcp_syn_ack_timeout+0xd/0x30 Call Trace: <IRQ> reqsk_timer_handler+0x22e/0x500 call_timer_fn+0x2a/0x140 __run_timers+0x1f7/0x280 run_timer_softirq+0x49/0xf0 handle_softirqs+0xfa/0x300 __irq_exit_rcu+0xb5/0xf0 sysvec_apic_timer_interrupt+0x73/0x80 </IRQ> Kernel panic - not syncing: Fatal exception in interrupt
[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]
--- net/ipv4/syncookies.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/syncookies.c +2 -1
@@ -312,7 +312,8 @@ struct request_sock *cookie_bpf_check(struct sock *sk, struct sk_buff *skb) skb->sk =NULL ; skb->destructor =NULL ; -if (cookie_tcp_reqsk_init (sk, skb, req)) { +/* reuseport can pick an MPTCP listener: req is too small for it */ +if (sk_is_mptcp (sk) ||cookie_tcp_reqsk_init (sk, skb, req)) {reqsk_free (req); req =NULL ; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH mptcp-net v2 45/62] tcp: do not pass a BPF reqsk to an MPTCP listener
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 patch fixes the slab-out-of-bounds write: cookie_bpf_check() now frees the BPF reqsk and returns NULL whenever reuseport re-…
--
tcp: do not pass a BPF reqsk to an MPTCP listener
This commit fixes a slab-out-of-bounds write in mptcp_subflow_init_cookie_req(). The write happens when a plain TCP request sock assigned by BPF reaches an MPTCP listener, because inet_steal_sock() selects again from the SO_REUSEPORT group. With the fix, cookie_bpf_check() frees the reqsk and drops the segment when the listener is MPTCP.
Quoted 5 lines
net/ipv4/syncookies.c +0
-0
net/ipv4/syncookies.c struct request_sock *cookie_bpf_check(struct sock *sk, struct sk_buff *skb) · line 319
Quoted 9 lines
net/ipv4/syncookies.c +2
-1@@ -312,7 +312,8 @@ struct request_sock *cookie_bpf_check(struct sock *sk, struct sk_buff *skb) skb->sk =NULL ; skb->destructor =NULL ; -if (cookie_tcp_reqsk_init (sk, skb, req)) { +/* reuseport can pick an MPTCP listener: req is too small for it */ +if (sk_is_mptcp (sk) ||cookie_tcp_reqsk_init (sk, skb, req)) {reqsk_free (req); req =NULL ; }
[Severity: Low]
This closes the out-of-bounds write. Is the resulting drop persistent for the affected flows, though?
When cookie_bpf_check() returns NULL, cookie_v4_check() drops the segment without sending a RST:
net/ipv4/syncookies.c:cookie_v4_check() {
...
if (!req) {
SKB_DR_SET(reason, NO_SOCKET);
goto out_drop;
}
...
}With the default hash-based reuseport selection, the BPF program and inet_steal_sock() can pick different listeners. This mismatch looks fixed for a given 4-tuple.
The selftest program finds its listener like this:
bpf_skc_lookup_tcp()
__inet_lookup(skb == NULL)
__inet_lookup_listener()
For listeners bound to a wildcard address, the second lookup pass in __inet_lookup_listener() hashes with INADDR_ANY as daddr:
result = inet_lhash2_lookup(net, ilb2, skb, doff,
saddr, sport, htonl(INADDR_ANY), hnum, dif, sdif);
inet_steal_sock() then selects again using the real daddr:
reuse_sk = inet_lookup_reuseport(net, sk, skb, doff,
saddr, sport, daddr, ntohs(dport), ehashfn);
The two hashes differ. Wouldn't a fixed set of 4-tuples always get the TCP listener from the program and the MPTCP listener from the second selection? A reuseport BPF program that only acts when skb != NULL would split flows the same way.
For these flows the client has already received a SYN-ACK and thinks the connection is established. Each retransmitted ACK carries the same valid cookie. bpf_sk_assign_tcp_reqsk() returns 0, inet_steal_sock() picks the MPTCP listener again, and the segment is dropped again. The client waits until its retransmission timeout, and the BPF program never gets an error.
In inet_steal_sock(), the original sk is still the compatible TCP listener that the program chose. Could the code fall back to that listener when the newly selected socket is MPTCP, so these connections can complete?
If the drop is intended, could the commit message say that the fix turns the memory corruption into a connection failure for these 4-tuples?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 46/62 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.
[ Shorter comment. Commit message: the rest of the borrowed amount has
to be released + how the issue was found, and its symptoms. ]
--- net/mptcp/protocol.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/mptcp/protocol.c +6 -0
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 46/62] mptcp: reclaim forward memory after coalescing skbs
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 is a comment problem only.
--
mptcp: reclaim forward memory after coalescing skbs
The patch adds sk_mem_reclaim() calls in mptcp_try_coalesce() after the merged skb is freed, and in mptcp_data_queue_ofo() after the skb is queued. This returns the sk_forward_alloc that is left over from mptcp_borrow_fwdmem(), which would otherwise build up when small segments are coalesced or condensed.
net/mptcp/protocol.c static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to, · line 202
Quoted 11 lines
net/mptcp/protocol.c +3
-0@@ -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); +
[Severity: Low]
This isn't a bug, but mptcp_try_coalesce() now has two comments that describe different ownership models for the 'from' skb. Each one is wrong for some of the callers.
A few lines above the new code, the older comment says:
/* note the fwd memory can reach a negative value after accounting * for the delta, but the later skb free will restore a non * negative one */
That only holds when 'from' has the sock_rfree destructor.
In __mptcp_move_skb(), and in mptcp_data_queue_ofo() via mptcp_ooo_try_coalesce(), 'from' is borrowed through mptcp_borrow_fwdmem() and has no destructor. skb_try_coalesce() keeps delta <= from->truesize, so sk_forward_alloc does not go negative here. kfree_skb_partial() also gives nothing back. That missing release is the reason this patch adds the reclaim.
The new comment does not fit the third caller. __mptcp_ofo_queue() calls:
if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {with an out-of-order skb that mptcp_data_queue_ofo() already owns via skb_set_owner_r(). For that skb, kfree_skb_partial() runs sock_rfree()->sk_mem_uncharge(), which already reclaims. Nothing borrowed is left, and the new sk_mem_reclaim() has no effect.
Could the older comment be updated, and the new one reworded to cover both the borrowed and the owned cases? As written, a reader who trusts the older comment might drop the new reclaim as redundant. That would bring back the sk_forward_alloc buildup on the borrowed paths.
Quoted 3 lines
net/mptcp/protocol.c +0
-0return true; }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts (NGI0)
maintainerPATCH v2 47/62 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 pageThe 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.
[ Shorter comment. Commit message: how the issue was found, and its
symptoms. ]
--- net/mptcp/protocol.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +20 -1
@@ -4636,10 +4636,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);
@@ -4657,6 +4673,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);
@@ -4672,7 +4691,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 48/62 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 [...]
[ 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
@@ -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,
@@ -2454,12 +2448,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;
@@ -4663,8 +4651,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);
@@ -4696,26 +4683,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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 49/62 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
---
v2: update a comment (Clashiko)
--- net/mptcp/protocol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +4 -3
@@ -4650,8 +4650,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);
@@ -4674,7 +4674,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 50/62 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 + 1001The 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)
[ 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.
--- net/mptcp/protocol.h | 9 ++++++++- net/mptcp/subflow.c | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-)
net/mptcp/protocol.h +8 -1
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 50/62] mptcp: continue the last mapping after a fallback
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] When only the receiver falls back, the new dummy mapping (dsn_base + map_subflow_seq - 1 in subflow_check_data_avail(),…
- [Low] The MP_FAIL branch of subflow_check_data_avail() (net/mptcp/subflow.c) ignores the new map_old precondition.
--
mptcp: continue the last mapping after a fallback
The fallback dummy mapping in subflow_check_data_avail() now continues from the peer's last DSS mapping (dsn_base) instead of iasn. Before this, a zero window probe or a reinjection shifted all later data out of order. The patch also tracks the highest end of the peer's mappings (dsn_end), and makes mptcp_try_fallback() fail while the last mapping ends below it.
Quoted 4 lines
net/mptcp/subflow.c +0
-0
[ ... ]
Quoted 4 lines
net/mptcp/subflow.c +0
-0@@ -1438,6 +1440,17 @@ static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk)return true; }
net/mptcp/subflow.c static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk) · line 1452
Quoted 10 lines
net/mptcp/subflow.c +10
-0+/* 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; +}
[Severity: Medium]
Can this deliver bytes twice to the application when only the receiver falls back, even if the sender runs a current kernel?
A probe or reinjection whose map ends exactly at dsn_end moves dsn_base but leaves map_old at 0, because before(end, dsn_end) is false.
Take two zero window probes. The receiver has DATA_ACKed up to DSN E, so dsn_end = E, and its MPTCP window is zero:
probe 1 SSN P, DSN E-1, 1 byte (content of byte E), with DSS
-> dsn_base = E - P, end = E, map_old = 0
receiver reads and sends a window update with DSS probe 2 SSN P+1, DSN E-1, sent before the window update arrives,
DSS stripped by a middlebox
Probe 2 passes the sender's reset check. Probe 1 was acked with DSS, so opt_ack_seq is current.
On the receiver, probe 2 gets MAPPING_NODSS. mptcp_try_fallback() then succeeds, because map_old and old_data_pending are both clear. The dummy mapping at the end of subflow_check_data_avail() gives:
map_seq = dsn_base + map_subflow_seq - 1 = (E - P) + (P + 1) - 1 = E
That equals ack_seq, so the probe's byte is delivered at E.
Next, the sender sends byte E onward as new data at snd_nxt. The reset check in mptcp_sendmsg_frag() only covers old data:
if (unlikely(before64(data_seq, msk->snd_nxt) &&
!test_bit(MPTCP_JOINED, &msk->flags) &&
after(tcp_sk(ssk)->snd_una, subflow->opt_ack_seq))) {
...
mptcp_subflow_reset(ssk);The new data does not trigger it, and the receiver, which has fallen back, maps it at E+1 onward. Byte E is delivered twice and every later byte is shifted by one.
The sender only resets later, when its MPTCP rtx timer reinjects old data. By then the shifted data has already reached recvmsg(). Before this patch, probe 2 was mapped at E+1 and went to the out-of-order queue, so the connection stalled instead.
Two reinjections seem to allow the same thing. The first one, seen with DSS and ending exactly at dsn_end (for example a spurious __mptcp_retrans() after a stale DATA_ACK), moves dsn_base. The second one has its DSS stripped and gets dummy DSNs starting at dsn_end, so its old bytes are delivered as new.
The commit message says:
"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"."
Does that still hold when the sender's next transmission after the stripped resend is new data and not old data?
Later in the series, "mptcp: reset when the DSS disappears after a DATA_ACK" makes NODSS fatal only when subflow->dss_confirmed is set. A receiver that never sent data of its own, such as a download client, still looks exposed.
Quoted 3 lines
net/mptcp/subflow.c +1
-0+static bool subflow_check_data_avail (struct sock *ssk) {
[ ... ]
net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1522
Quoted 8 lines
net/mptcp/subflow.c +1
-0@@ -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; }
[Severity: Low]
Should map_old be checked here, before this branch commits to a graceful MP_FAIL?
For MAPPING_BAD_CSUM, mptcp_subflow_fail() only checks msk->allow_infinite_fallback and msk->first. It then clears allow_subflows, sends MP_FAIL without RST and arms fail_tout.
Only after that does subflow_update_dsn_base() run on the bad checksum map. If that map is a reinjection of old data ending before dsn_end, map_old becomes 1 after the fallback has already been promised.
The peer answers from mptcp_pm_mp_fail_received() with an infinite mapping. On the receiver, that leads to:
subflow_check_data_avail()
get_mapping_status() /* data_len == 0: MAPPING_INVALID here,
MAPPING_INFINITE later in the series */
goto fallback
__mptcp_check_fallback(msk) /* still false */
mptcp_try_fallback()
if (subflow->map_old && !__mptcp_check_fallback(msk))
return false; goto reset /* MPTCP_RST_EMPTCP */
The subflow is then reset with MPTCP_RST_EMPTCP one round trip later, after the peer has already fallen back.
Could this branch test map_old right after updating it, and take the existing goto reset path with MPTCP_RST_EMIDDLEBOX, as the !mptcp_subflow_fail() case does?
Hitting this needs DSS checksums. It also needs a reinjection of old data on the only subflow that stops before dsn_end while the peer's allow_infinite_fallback is still set, for example __mptcp_retransmit_pending_data() after a failed MP_JOIN. Finally, the payload of one of the old maps must be corrupted on the path.
At the end of the series, "mptcp: reset when the DSS disappears after a DATA_ACK" still leaves this MP_FAIL branch unchanged.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121-mptcp-cmason-fixes-v2-0-00327fd1de1f%40kernel.org
Matthieu Baerts
maintainerRe: [PATCH mptcp-net v2 50/62] mptcp: continue the last mapping after a fallback
Quoted 29 lines · On 23/11/2026 07:32, [email protected] wrote:
Quoted 4 lines
net/mptcp/subflow.c +0
-0[ ... ]
Quoted 4 lines
net/mptcp/subflow.c +0
-0@@ -1438,6 +1440,17 @@ static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk)return true; }net/mptcp/subflow.c static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk) · line 1452
Quoted 10 lines
net/mptcp/subflow.c +10
-0+/* 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; +}[Severity: Medium]
Can this deliver bytes twice to the application when only the receiver falls back, even if the sender runs a current kernel?A probe or reinjection whose map ends exactly at
dsn_endmovesdsn_basebut leavesmap_oldat 0, becausebefore(end, dsn_end)is false.
Quoted 8 lines
Take two zero window probes. The receiver has
DATA_ACKedup to DSN E, sodsn_end= E, and its MPTCP window is zero:probe 1 SSN P, DSN E-1, 1 byte (content of byte E), with DSS
-> dsn_base = E - P, end = E, map_old = 0receiver reads and sends a window update with DSS probe 2 SSN P+1, DSN E-1, sent before the window update arrives,
DSS stripped by a middlebox
Mmh, it needs a middlebox dropping the DSS of one probe, but not of the other one... I don't think we need to support that: if middlebox wants to mess up with TCP packets, they can already do that from various ways. Upper protocols will detect that.
(...)
Quoted 4 lines
Quoted 4 lines
net/mptcp/subflow.c +0
-0@@ -1501,6 +1516,7 @@ static bool subflow_check_data_avail(struct sock *ssk) subflow->reset_reason =MPTCP_RST_EMIDDLEBOX ; goto reset; }
Quoted 8 lines
net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1522
Quoted 4 lines
net/mptcp/subflow.c +1
-0+subflow_update_dsn_base (subflow);WRITE_ONCE (subflow->data_avail, true);return true; }[Severity: Low]
Shouldmap_oldbe checked here, before this branch commits to a gracefulMP_FAIL?
No: it needs DSS checksums, a reinjection and a corruption...
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 51/62 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)
---
v2: new, for an issue spotted by Sashiko
--- net/mptcp/options.c | 5 +++++ net/mptcp/subflow.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-)
net/mptcp/options.c +5 -0
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH mptcp-net v2 51/62] 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 f7213d49d43afa61976fc0d20b767c461864c635
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: keep the first byte after a simult connect
This commit sets subflow->ssn_offset when sending a SYN-ACK in TCP_SYN_RECV during a simultaneous connect and only updates it from packets with TCPHDR_SYN in subflow_finish_connect().
Quoted 6 lines
net/mptcp/options.c +0
-0@@ -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]
Should setting subflow->ssn_offset here be restricted to the subflow->request_mptcp simultaneous connect branch?
If an active MP_JOIN subflow (subflow->request_join == 1, subflow->remote_key_valid == 1, subflow->mp_join == 0) receives a crossed SYN in TCP_SYN_SENT, tcp_rcv_synsent_state_process() moves it to TCP_SYN_RECV and calls tcp_send_synack() -> mptcp_syn_options(), which now initializes subflow->ssn_offset to the peer's ISN.
When the third ACK arrives with seq == subflow->ssn_offset + 1, tcp_rcv_state_process() transitions the subflow to TCP_ESTABLISHED before subflow_finish_connect() runs and calls tcp_data_queue() -> mptcp_incoming_options() -> check_fully_established():
net/mptcp/options.c:check_fully_established() {
if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) {
...
}
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;
}
if (!(mp_opt->suboptions & OPTIONS_MPTCP_MPC)) {
if (subflow->mp_join)
goto reset;
subflow->mp_capable = 0;
if (!mptcp_try_fallback(ssk, MPTCP_MIB_MPCAPABLEDATAFALLBACK)) {
...
}Because TCP_SKB_CB(skb)->seq == subflow->ssn_offset + 1 now matches while subflow->mp_join is 0 and subflow->remote_key_valid is 1, a plain ACK calls mptcp_try_fallback() on the parent connection instead of resetting the subflow, while an ACK carrying a DSS ACK with data jumps to set_fully_established without MP_JOIN authentication and triggers the WARN_ON_ONCE() in subflow_data_ready().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=51
Matthieu Baerts (NGI0)
maintainerPATCH v2 52/62 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.
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)
---
v2: new, for an issue found by a review agent, after a Sashiko review
--- net/mptcp/subflow.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/mptcp/subflow.c +10 -0
@@ -1988,6 +1988,16 @@ 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 ; +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
Matthieu Baerts (NGI0)
maintainerPATCH v2 53/62 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.
---
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
@@ -2299,6 +2299,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 54/62 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 anMP_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
---
v2: new, for an issue causing a flaky selftest
--- net/mptcp/protocol.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/mptcp/protocol.c +17 -0
@@ -2415,10 +2415,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 ) {
@@ -2426,6 +2437,9 @@ static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *deltlist_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 ;
@@ -2437,6 +2451,9 @@ static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *deltif (!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
Matthieu Baerts (NGI0)
maintainerPATCH v2 55/62 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.
---
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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 56/62 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.
---
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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 57/62 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 __mptcp_wr_shutdown() sets these two fields without ordering them: 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.
Use a release/acquire pair, 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.
---
v2: new, for an issue spotted by Clashiko
--- net/mptcp/protocol.c | 3 ++- net/mptcp/protocol.h | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +2 -1
@@ -3666,7 +3666,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_try_fallback() */ +smp_store_release (&msk->snd_data_fin_enable,1 );mptcp_check_send_data_fin (sk); }
net/mptcp/protocol.h +4 -2
@@ -1364,8 +1364,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 58/62 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.
---
v2: new, for an issue found by a review agent
--- net/mptcp/protocol.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/protocol.c +3 -0
@@ -1961,6 +1961,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
Matthieu Baerts (NGI0)
maintainerPATCH v2 59/62 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.
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
Note: when squashing, the commit message could mention that mptcp_sched_get_send() now sets the rtx timer interval before calling a BPF scheduler, as the default one does.
--- net/mptcp/sched.c | 3 +++ 1 file changed, 3 insertions(+)
net/mptcp/sched.c +3 -0
@@ -189,6 +189,9 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)if (msk->sched == &mptcp_sched_default || !msk->sched)return mptcp_sched_default_get_send (msk); + +/* as the default scheduler: the rtx timer needs an interval */ +mptcp_set_timeout ((struct sock *)msk);return msk->sched->get_send (msk); }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH mptcp-net v2 59/62] 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() if already scheduled --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mptcp: mptcp_sched_get_send() skips mptcp_set_timeout() if already scheduled
--
commit be05849933557cf4aa59c7bd40312183567d8767
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() before invoking a custom packet scheduler so that msk->timer_ival is initialized.
net/mptcp/sched.c int mptcp_sched_get_send(struct mptcp_sock *msk) · line 196
Quoted 13 lines
net/mptcp/sched.c +3
-0@@ -189,6 +189,9 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)if (msk->sched == &mptcp_sched_default || !msk->sched)return mptcp_sched_default_get_send (msk); + +/* as the default scheduler: the rtx timer needs an interval */ +mptcp_set_timeout ((struct sock *)msk);return msk->sched->get_send (msk); }
[Severity: Medium]
Can mptcp_sched_get_send() still leave msk->timer_ival at 0 when a subflow already has subflow->scheduled set?
Right above this hunk, mptcp_sched_get_send() returns 0 early if any subflow has subflow->scheduled set:
net/mptcp/sched.c:mptcp_sched_get_send() {
...
mptcp_for_each_subflow(msk, subflow) {
if (READ_ONCE(subflow->scheduled))
return 0;
}
...
}When a BPF scheduler marks multiple subflows as scheduled (such as bpf_red), the active subflow can drain mptcp_send_head(sk) and delegate the remaining scheduled subflow. Because mptcp_send_head(sk) is now NULL, __mptcp_subflow_push_pending() does not enter its send loop on the delegated subflow and leaves subflow->scheduled set to true.
Once all in-flight data is acknowledged, mptcp_stop_rtx_timer() resets msk->timer_ival to 0. On the next send, mptcp_sched_get_send() takes the early return above without calling mptcp_set_timeout(). If __subflow_push_pending() then stops after the first fragment because msk->snd_burst <= 0 (or fails under memory pressure), it exits before its own mptcp_set_timeout() call, and mptcp_reset_rtx_timer() arms the retransmit timer with a 0 interval, firing every jiffy.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=59
Matthieu Baerts (NGI0)
maintainerPATCH v2 60/62 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.
---
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
@@ -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
Matthieu Baerts (NGI0)
maintainerPATCH v2 61/62 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
--- net/mptcp/protocol.c | 88 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 21 deletions(-)
net/mptcp/protocol.c +67 -21
@@ -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;
@@ -2810,7 +2860,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
@@ -2818,6 +2868,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); }
@@ -3085,20 +3139,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 */
@@ -3416,8 +3460,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 ) {
@@ -4768,8 +4811,11 @@ 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); -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
[email protected]
AI reviewRe: [PATCH mptcp-next mptcp-net v2 61/62] 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: tcp_disconnect() clears SOCK_DONE before mptcp_check_rcv_close()
- [Medium] mptcp: dummy fallback DATA_FIN changes state before mptcp_close_last_err()
- [Medium] mptcp: missing mptcp_check_data_fin_ack() before mptcp_close_last_err()
--
commit 0c5fc2bb3f82340912e87636cc6d5fef891b87cb
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: report errors as TCP does when closing
This commit updates MPTCP socket closure on close timeouts and last-subflow closure to set SHUTDOWN_MASK and populate sk_err based on the subflow error or MPTCP socket state, matching tcp_done_with_error().
Quoted 4 lines
net/mptcp/protocol.c +0
-0
[ ... ]
Quoted 10 lines
net/mptcp/protocol.c +2
-1@@ -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 );
net/mptcp/protocol.c static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk, · line 2971
Quoted 10 lines
net/mptcp/protocol.c +4
-3-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]
Can a fallback socket closed by a clean FIN report EPIPE or ECONNRESET from recv() instead of EOF here?
When ssk is msk->first and dispose_it is false, earlier in __mptcp_close_ssk() the call to __mptcp_subflow_disconnect() -> tcp_disconnect() clears SOCK_DONE on msk->first. When mptcp_check_rcv_close() then drains the backlog and calls mptcp_check_data_fin(), sock_flag(msk->first, SOCK_DONE) is already false:
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);
...
}Because SOCK_DONE is not copied to sk, and mptcp_close_last_err() then sets sk->sk_err to EPIPE or ECONNRESET (when sk transitions to TCP_CLOSE_WAIT or TCP_CLOSING), mptcp_recvmsg() sees !sock_flag(sk, SOCK_DONE) and returns the error instead of 0.
[Severity: Medium]
Does calling mptcp_check_rcv_close() without also checking mptcp_check_data_fin_ack() cause a cleanly closed connection to report ECONNRESET?
If sk is in TCP_LAST_ACK, TCP_CLOSING, or TCP_FIN_WAIT1 and the peer's DATA_ACK acknowledging our DATA_FIN has already updated msk->snd_una in softirq before __mptcp_close_ssk() runs, mptcp_check_rcv_close() only checks rcv_data_fin and rcv_fastclose. Without mptcp_check_data_fin_ack() advancing sk->sk_state to TCP_CLOSE (or to TCP_FIN_WAIT2 before mptcp_check_data_fin() moves it to TCP_CLOSE), sk->sk_state != TCP_CLOSE remains true and mptcp_close_last_err() sets sk->sk_err to ECONNRESET even though the DATA_FIN handshake completed cleanly.
Also, because this branch is skipped when sk->sk_state == TCP_ESTABLISHED, an accepted socket in TCP_ESTABLISHED that receives final data, DATA_FIN (or MP_FASTCLOSE), and subflow close in its backlog while locked by mptcp_worker() will skip mptcp_check_rcv_close() and start the close timeout timer instead of processing the backlog and closing immediately.
Quoted 24 lines
net/mptcp/protocol.c +2
-12@@ -3085,20 +3139,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 */
net/mptcp/protocol.c static void mptcp_worker(struct work_struct *work) · line 3464
Quoted 7 lines
net/mptcp/protocol.c +1
-2@@ -3416,8 +3460,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]
Can a thread in mptcp_poll() or getsockopt(SO_ERROR) be woken on close timeout before mptcp_close_err() publishes ETIMEDOUT and SHUTDOWN_MASK?
kworker CPU1mptcp_worker()
mptcp_do_fastclose(sk)
mptcp_set_state(sk, TCP_CLOSE)
__mptcp_close_ssk(sk, ...)
if (sk->sk_state == TCP_CLOSE)
mptcp_close_wake_up(sk)
mptcp_poll()
state == TCP_CLOSE
sk_shutdown == 0, sk_err == 0
<-- misses EPOLLERR/EPOLLIN/EPOLLOUT mptcp_close_err(sk, ETIMEDOUT)
mptcp_close_err() writes sk_err and SHUTDOWN_MASK before setting TCP_CLOSE and waking waiters so lockless pollers see a consistent state. However, on close timeout, mptcp_do_fastclose() already sets TCP_CLOSE, and __mptcp_close_ssk() then hits the new sk->sk_state == TCP_CLOSE branch and calls mptcp_close_wake_up() while sk_err and sk_shutdown are still 0. In mptcp_check_fastclose() above, mptcp_set_state(sk, TCP_CLOSE) is likewise called before WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK).
net/mptcp/protocol.c static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, · line 4821
Quoted 13 lines
net/mptcp/protocol.c +4
-1@@ -4768,8 +4811,11 @@ 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); -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));
[Severity: Medium]
On a fallback socket closed by a TCP reset or timeout without a FIN, does mptcp_check_rcv_close() corrupt the state before mptcp_close_last_err() maps the error?
When a fallback subflow reaches TCP_CLOSE, subflow_sched_work_if_closed() emulates a dummy rcv_data_fin = 1 even if no FIN was received:
net/mptcp/subflow.c:subflow_sched_work_if_closed() {
...
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))
mptcp_schedule_work(sk);
...
}When mptcp_check_data_fin() processes that dummy rcv_data_fin (here in mptcp_stream_accept(), in __mptcp_close_ssk(), or earlier in mptcp_worker()), it leaves SOCK_DONE unset on sk because msk->first lacks SOCK_DONE, yet it still advances sk->sk_state from TCP_ESTABLISHED to TCP_CLOSE_WAIT, or from TCP_FIN_WAIT2 to TCP_CLOSE. As a result, a TCP RST in TCP_ESTABLISHED sees TCP_CLOSE_WAIT in mptcp_close_last_err() and reports EPIPE instead of ECONNRESET, and a reset or timeout in TCP_FIN_WAIT2 sees sk->sk_state == TCP_CLOSE and skips mptcp_close_last_err() completely.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=61
Matthieu Baerts (NGI0)
maintainerRFC PATCH v2 62/62 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 does not cover the received data, e.g. 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.
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
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.)
--- net/mptcp/options.c | 11 +++++++---- net/mptcp/protocol.h | 3 ++- net/mptcp/subflow.c | 29 +++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 9 deletions(-)
net/mptcp/options.c +7 -4
@@ -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
@@ -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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC mptcp-next mptcp-net v2 62/62] mptcp: reset when the DSS disappears after a DATA_ACK
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mptcp: fallback after dss_confirmed in mptcp_dss_corruption() on partial map - [Low] mptcp…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] mptcp: fallback after dss_confirmed in mptcp_dss_corruption() on partial map
- [Low] mptcp: missing MAPPING_INFINITE in show_mapping_status() trace macro
--
commit 066a0ac232910122a63844ec66369cf60e694e69
Author: Matthieu Baerts (NGI0) <[email protected]>
mptcp: reset when the DSS disappears after a DATA_ACK
This commit tracks whether a DATA_ACK has acknowledged sent data on a subflow (dss_confirmed) and resets the subflow instead of falling back to TCP when a subsequent segment arrives without a DSS option or with an invalid mapping.
Quoted 15 lines
net/mptcp/subflow.c +2
-1@@ -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)
net/mptcp/subflow.c static enum mapping_status get_mapping_status(struct sock *ssk, · line 1247
Quoted 6 lines
net/mptcp/subflow.c +1
-1@@ -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 ; }
[Severity: Low]
Should show_mapping_status() in include/trace/events/mptcp.h also be updated for MAPPING_INFINITE (along with MAPPING_BAD_CSUM and MAPPING_NODSS) so trace_subflow_check_data_avail() does not print raw numeric values?
Quoted 37 lines
net/mptcp/subflow.c +19
-1if (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 )
net/mptcp/subflow.c static bool subflow_check_data_avail(struct sock *ssk) · line 1547
Quoted 7 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 )) {
[Severity: Medium]
Can an incoming skb that starts within the current mapping but extends beyond subflow->map_data_len (for instance, after middlebox coalescing or resegmentation across a mapping boundary) still trigger a fallback to TCP after subflow->dss_confirmed is set?
validate_mapping() in get_mapping_status() only checks that the starting SSN of the skb lies within [subflow->map_subflow_seq, subflow->map_subflow_seq + subflow->map_data_len), so get_mapping_status() returns MAPPING_OK and bypasses subflow_nodss_is_fatal() here. When __mptcp_move_skbs_from_subflow() then sees map_remaining < len, it calls mptcp_dss_corruption(), which invokes mptcp_try_fallback() without checking whether subflow->dss_confirmed is set:
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);
}
}As a result, the receiver still performs a one-sided fallback to TCP after a DATA_ACK has confirmed bidirectional MPTCP options instead of resetting the subflow.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=62
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: 2 failed test(s): packetdrill_fastopen packetdrill_regressions ⚠️
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- 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-baseline regression:sched-mem-pressure regression:sched-rmem(3) regression:sched-weak-secondary(3) validation:sched-loss ⚠️ (105 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/44893077071
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/ae8564eb0766
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1218014
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-normalFor 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)
Matthieu Baerts
maintainerHello,
Quoted 1 line · On 21/11/2026 10:40, Matthieu Baerts (NGI0) wrote:
Here are various fixes, many from Chris Mason and Josef Bacik:
The series is huge, I suggest already applying some that have passed Clashiko and my reviews. So I can send them to netdev soon after, not to have to deal with so many pending patches for multiple revisions.
New patches for t/upstream-net and t/upstream:
- 52d9a98589c9: tcp: drain the queues of a listen() that fails
- 8a4e263203f4: mptcp: drain the queues of a listen() that fails
- 9d0ecb1b1f33: mptcp: clear inet_opt in the child of an IPv6 listener
- 761c32ace7c8: mptcp: pm: work on a copy of the received RM_ADDR list
- 475077050ec0: mptcp: pm: don't drop an RM_ADDR behind a pending one
- ead7833cdd65: mptcp: pm: don't drop an RM_ADDR because of an ADD_ADDR
- 7d1b430b2cb2: mptcp: pm: keep an RM_ADDR when computing the MSS
- 85fece8445cd: mptcp: arm the rtx timer if a push leaves data behind
- 4b4353255dff: mptcp: force the charge for the first skb of a subflow
- 6c52ddc4696e: mptcp: leave an orphan's DATA_FIN to the worker
- 9a03bc9a9a99: mptcp: don't leak an orphan when the PM closes its last subflow
- beaa7aa14762: net: add __sk_net_refcnt_upgrade() with a GFP mask
- f0b87bad9a3f: mptcp: pm: don't let listeners pin their netns
- c8be86f52be2: mptcp: initialize drop_req in subflow_init_req()
- 3a3ef2da848e: tcp: do not pass a BPF reqsk to an MPTCP listener
- Results: 55ff7876edc2..4f33144c3abc (export-net)
- Results: b9620afcd7c2..35684d7aa7f8 (export)
Tests are now in progress:
- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/b042b24f739ea310b47ec70a923ba27aa4a46cea/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/97149e277cb068294d3d49966decfd7f9a6f0b8e/checks
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.