Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7
@ 2026-12-02 21:29 Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 1/9] mptcp: pm: kernel: c-flag: keep local_addr_used in sync Matthieu Baerts (NGI0)
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable, Yiming Qian,
	Chris Mason

Here are some unrelated fixes:

- Patch 1: avoid a warning when removing MPTCP endpoints in a specific
  case. A fix for a fix introduced in v6.18 and backported to v5.15.

- Patches 2-5: 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, as TCP does. Fixes for v5.11.

- Patch 6: wake up the senders blocked when the connection is closed
  without subflows. Fix for another fix introduced in v6.6 and targeting
  v5.11.

- Patches 7-9: reclaim the forward memory after coalescing skbs, and
  do not overcharge the memcg at accept(). Fixes for v6.19.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Chris Mason (3):
      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()

Matthieu Baerts (NGI0) (6):
      mptcp: pm: kernel: c-flag: keep local_addr_used in sync
      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: wake up blocked senders when no sf left

 net/mptcp/pm_kernel.c |   8 ++-
 net/mptcp/protocol.c  | 176 +++++++++++++++++++++++++++++++++++++++-----------
 net/mptcp/protocol.h  |   2 +-
 net/mptcp/subflow.c   |   7 +-
 4 files changed, 148 insertions(+), 45 deletions(-)
---
base-commit: c1c39137dcc3134010566ff29a81c93124efa539
change-id: 20261202-net-mptcp-misc-fixes-7-4-rc7-dddd590247f3

Best regards,
--  
Matthieu Baerts (NGI0) <matttbe@kernel.org>


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

* [PATCH net 1/9] mptcp: pm: kernel: c-flag: keep local_addr_used in sync
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 2/9] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable, Yiming Qian

The ID was marked as used before incrementing local_addr_used counter
when the families were not matching.

Marking endpoints as used while they are not can have an impact on the
local_addr_used counter when endpoints not linked to the initial subflow
are removed -- CAP_NET_ADMIN is required -- and active connections have
such badly marked endpoints. In this case, the local counter will be
decremented while it shouldn't. If the counter was already at 0, this
warning will be emitted:

  WARNING: net/mptcp/pm_kernel.c:1080 at __mark_subflow_endp_available+0x46/0x50, CPU#0: a.out/149
  RIP: 0010:__mark_subflow_endp_available (net/mptcp/pm_kernel.c:1080 (discriminator 2) net/mptcp/pm_kernel.c:1076 (discriminator 2))
  Call Trace:
   mptcp_pm_nl_del_addr_doit (net/mptcp/pm_kernel.c:1112 net/mptcp/pm_kernel.c:1227)
   genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114)

The fix is easy: increment local_addr_used similar to what is done in
mptcp_pm_create_subflow_or_signal_addr() for the non C-flag case.

Fixes: 4b1ff850e0c1 ("mptcp: pm: in-kernel: usable client side with C-flag")
Cc: stable@vger.kernel.org
Reported-by: Yiming Qian <yimingqian591@gmail.com>
Closes: https://lore.kernel.org/20261006114409.117190-1-yimingqian591@gmail.com
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/pm_kernel.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c
index f7396628490e..d465524902f0 100644
--- a/net/mptcp/pm_kernel.c
+++ b/net/mptcp/pm_kernel.c
@@ -584,13 +584,15 @@ fill_local_addresses_vec_c_flag(struct mptcp_sock *msk,
 
 		__clear_bit(local->addr.id, msk->pm.id_avail_bitmap);
 
-		if (!mptcp_pm_addr_families_match(sk, &local->addr, remote))
-			continue;
-
 		if (local->addr.id == msk->mpc_endpoint_id)
 			continue;
 
+		/* Increment before checking families, similar to non C-flag */
 		msk->pm.local_addr_used++;
+
+		if (!mptcp_pm_addr_families_match(sk, &local->addr, remote))
+			continue;
+
 		msk->pm.extra_subflows++;
 		i++;
 

-- 
2.55.0


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

* [PATCH net 2/9] mptcp: keep an orphan while it can send its data
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 1/9] mptcp: pm: kernel: c-flag: keep local_addr_used in sync Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-03 21:51   ` netdev-bot+sashiko
  2026-12-02 21:29 ` [PATCH net 3/9] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable

The close timeout of an orphaned MPTCP socket started at close(), and
its expiry reset the connection, while some data could still be waiting
for the peer to open its window: a peer reading slowly or pausing got a
reset 60 seconds after close(), and lost the end of the data, while TCP
delivers it.

This timeout is there for the DATA_FIN exchange, see commit d866ae9aaa43
("mptcp: add a new sysctl for make after break timeout"), and for an
orphan that can no longer send anything. So restart it when the DATA_FIN
is sent, and when it expires before, as long as a subflow can still send
the data, which is then pushed again: an established subflow, on which
the peer acked something recently, at least the window probes. Until
then, as for a TCP socket that is not orphaned, nothing limits how long
the peer can keep its window closed, while it acks the window probes.
The timeout still starts at close(): the subflows are not TCP orphans,
so its expiry is the only check that the orphan can still send.

This was reported on GitHub, with a reproducer: a server writes 2 MB,
then calls close(), while the client pauses before reading the rest.
After a pause of 90 seconds, the client got ECONNRESET, while TCP
delivered everything, as MPTCP now does. If the client vanishes instead,
the orphan is now reset as TCP does.

Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Cc: stable@vger.kernel.org
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/647
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index d6a07fa4b4e4..82a0cbe38192 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2814,6 +2814,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;
@@ -3151,6 +3173,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;
 
@@ -3392,6 +3419,10 @@ static void mptcp_check_send_data_fin(struct sock *sk)
 
 	WRITE_ONCE(msk->snd_nxt, msk->write_seq);
 
+	/* an orphan's close timeout is for the DATA_FIN exchange */
+	if (sock_flag(sk, SOCK_DEAD))
+		mptcp_start_tout_timer(sk);
+
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
 

-- 
2.55.0


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

* [PATCH net 3/9] mptcp: limit an orphan probing a zero window
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 1/9] mptcp: pm: kernel: c-flag: keep local_addr_used in sync Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 2/9] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-03 21:51   ` netdev-bot+sashiko
  2026-12-02 21:29 ` [PATCH net 4/9] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable

Since the previous commit, an orphan with data to send is kept while
the peer acks something, at least the window probes: a peer keeping its
window closed, e.g. not reading, could then keep the orphan forever.

TCP limits this for its orphans: tcp_probe_timer() aborts them instead
of probing again after the max interval. The subflows of an MPTCP orphan
are not orphaned: they probe again then, and back off once more, up to
tcp_retries2. So check if TCP would have aborted them, when the close
timeout expires. Same with data in flight, when the peer has shrunk its
window to zero: tcp_retransmit_timer() only aborts orphans then.

Two corner cases needing non-default settings are not covered, which is
fine: an idle subflow refreshed by keepalives still keeps the orphan
when the stale detection is disabled, and tcp_orphan_retries is ignored.

This was found by an AI code review agent, while reviewing the previous
commit. With its reproducer and a long pause, the orphan was kept until
the end of the pause. It is now reset as TCP does, respecting
tcp_retries2.

Note for the backports: this patch is needed with the previous one, and
before v6.15, tcp_rto_max() can be replaced by TCP_RTO_MAX.

Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Cc: stable@vger.kernel.org
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 82a0cbe38192..96b3baef341f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2814,6 +2814,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)
 {
@@ -2829,7 +2855,8 @@ static bool mptcp_orphan_keep(struct sock *sk)
 		/* a live peer acks at least the probes, every TCP_RTO_MAX */
 		if (__mptcp_subflow_active(subflow) &&
 		    tcp_jiffies32 - READ_ONCE(tcp_sk(ssk)->rcv_tstamp) <
-		    2 * TCP_RTO_MAX)
+		    2 * TCP_RTO_MAX &&
+		    !mptcp_subflow_probe_timed_out(ssk))
 			return true;
 	}
 

-- 
2.55.0


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

* [PATCH net 4/9] mptcp: count orphans as TCP does
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
                   ` (2 preceding siblings ...)
  2026-12-02 21:29 ` [PATCH net 3/9] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-03 21:51   ` netdev-bot+sashiko
  2026-12-02 21:29 ` [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable

The MPTCP sockets orphaned by close() were not counted in
tcp_orphan_count, contrary to TCP: tcp_max_orphans did not limit them,
and they were not visible in /proc/net/sockstat.

This is all the more needed since commit "mptcp: keep an orphan while it
can send its data": an orphan can then be kept longer than its close
timeout, e.g., as Sashiko noticed, by a peer acking the data at the TCP
level only, without moving the DATA_ACK.

Count them, and as TCP does, reset an orphan when there are too many
orphans, or when TCP uses too much memory: at close(), and when its
close timeout expires while it is kept to send its data. This is similar
to what tcp_out_of_resources() does from the TCP timers, without the
stricter limit for the stalled orphans. These resets are counted in
TCPAbortOnMemory, not in a new MPTCP counter: the MPTCP orphans now
share the TCP orphan count and limits.

This has been found by a review agent, and validated with a script
closing 8 connections whose peer doesn't read, with tcp_max_orphans set
to 4: the MPTCP orphans were all kept, without being counted, while
other orphans were reset. Now, only 5 or 6 are kept, vs 4 or 5 with TCP,
which also checks the limit from the timers of its orphans.

Fixes: e16163b6e2b7 ("mptcp: refactor shutdown and close")
Cc: stable@vger.kernel.org
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 24 ++++++++++++++++++++++--
 net/mptcp/protocol.h |  1 +
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 96b3baef341f..fc8aad7e2fde 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2840,6 +2840,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)
 {
@@ -2857,7 +2867,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;
@@ -3490,6 +3500,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);
 }
 
@@ -3579,8 +3592,15 @@ bool __mptcp_close(struct sock *sk, long timeout)
 	/* all the subflows are closed, only timeout can change the msk
 	 * state, let's not keep resources busy for no reasons
 	 */
-	if (subflows_alive == 0)
+	if (subflows_alive == 0) {
 		mptcp_set_state(sk, TCP_CLOSE);
+	} else if (sk->sk_state != TCP_CLOSE) {
+		/* as TCP orphans: counted, and limited */
+		tcp_orphan_count_inc();
+		set_bit(MPTCP_ORPHAN_COUNTED, &msk->flags);
+		if (mptcp_orphan_oom(sk))
+			mptcp_do_fastclose(sk);
+	}
 
 	sock_hold(sk);
 	pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 7644651f01a8..05bf9c3f11b4 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -117,6 +117,7 @@
 #define MPTCP_FALLBACK_DONE	2
 #define MPTCP_WORK_CLOSE_SUBFLOW 3
 #define MPTCP_RTX_ENABLED	4
+#define MPTCP_ORPHAN_COUNTED	5
 
 /* MPTCP socket release cb flags */
 #define MPTCP_PUSH_PENDING	1

-- 
2.55.0


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

* [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, as TCP does
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
                   ` (3 preceding siblings ...)
  2026-12-02 21:29 ` [PATCH net 4/9] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-03 21:51   ` netdev-bot+sashiko
  2026-12-02 21:29 ` [PATCH net 6/9] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable

Once an MPTCP socket has received a DATA_FIN, recv() returns the
remaining data, then EOF. But if the connection was then reset, e.g. by
an MP_FASTCLOSE, recv() returned an error after the data, e.g. EPIPE,
instead of EOF as TCP does. A proxy resetting the other connection on
read errors then dropped the data it still had to forward.

As TCP does with a FIN, set SOCK_DONE when processing the DATA_FIN, and
check it before the socket error in recvmsg(). With an MP_FASTCLOSE, the
data still in the backlog is moved first, not to miss the DATA_FIN.
After a fallback, a DATA_FIN is also emulated after a reset: only set
SOCK_DONE after a FIN, not to hide a reset behind an EOF. This FIN is
cleared when the first subflow is disconnected: emulate this DATA_FIN
before scheduling the disconnection, and process it before
disconnecting.

As with TCP, splice() then returns EOF too, and the error after an
MP_FASTCLOSE depends on the state reached with the DATA_FIN, e.g. EPIPE
in CLOSE_WAIT.

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 modification in mptcp_check_fastclose() is not needed.

Fixes: 15cc10453398 ("mptcp: deliver ssk errors to msk")
Cc: stable@vger.kernel.org
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647
Reviewed-by: Mat Martineau <martineau@kernel.org>
Acked-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 31 +++++++++++++++++++++++++++++--
 net/mptcp/subflow.c  |  7 ++++---
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index fc8aad7e2fde..1f045348764a 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -707,6 +707,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) {
@@ -934,6 +938,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);
@@ -2437,6 +2444,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;
@@ -2756,6 +2766,8 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 		     struct mptcp_subflow_context *subflow)
 {
+	struct mptcp_sock *msk = mptcp_sk(sk);
+
 	/* The first subflow can already be closed or disconnected */
 	if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
 		return;
@@ -2763,12 +2775,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 	subflow->close_event_done = true;
 
 	if (sk->sk_state == TCP_ESTABLISHED)
-		mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
+		mptcp_event(MPTCP_EVENT_SUB_CLOSED, msk, ssk, GFP_KERNEL);
 
 	/* subflow aborted before reaching the fully_established status
 	 * attempt the creation of the next subflow
 	 */
-	mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
+	mptcp_pm_subflow_check_next(msk, subflow);
+
+	/* On fallback, the FIN of the first subflow is cleared when it is
+	 * disconnected: process the DATA_FIN emulated from it before.
+	 */
+	if (ssk == msk->first && __mptcp_check_fallback(msk) &&
+	    READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
+		mptcp_move_skbs(sk);
+		mptcp_check_data_fin(sk);
+	}
 
 	__mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
 }
@@ -2881,6 +2902,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) {
@@ -3740,6 +3766,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;
 }
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 054ee992904e..3c2aff563575 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1379,9 +1379,6 @@ static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ss
 	if (!skb_queue_empty(&ssk->sk_receive_queue))
 		return;
 
-	if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
-		mptcp_schedule_work(sk);
-
 	/* when the fallback subflow closes the rx side, trigger a 'dummy'
 	 * ingress data fin, so that the msk state will follow along
 	 */
@@ -1390,6 +1387,10 @@ static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ss
 	    mptcp_update_rcv_data_fin(msk, subflow->map_seq +
 				      subflow->map_data_len, true))
 		mptcp_schedule_work(sk);
+
+	/* after the 'dummy' data fin: mptcp_close_ssk() checks it */
+	if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
+		mptcp_schedule_work(sk);
 }
 
 static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk)

-- 
2.55.0


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

* [PATCH net 6/9] mptcp: wake up blocked senders when no sf left
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
                   ` (4 preceding siblings ...)
  2026-12-02 21:29 ` [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-03 21:51   ` netdev-bot+sashiko
  2026-12-02 21:29 ` [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), stable

When an MPTCP socket moves to TCP_CLOSE because its last subflow is
closed, after the close timeout or not, sk_shutdown was not updated, and
no error was set in most cases. A thread blocked in send() was then
never woken up for good.

Set SEND_SHUTDOWN in these cases: no more data can be sent. The blocked
send() then returns EPIPE, as a send() called after the close timeout
already does. Reporting another error first, e.g. ETIMEDOUT as TCP does
after a timeout, would change the behaviour seen by the applications:
this is left for net-next.

This was reported on GitHub, with a reproducer: the only subflow dies by
RTO, and send() was never woken up, while it returned ETIMEDOUT after a
few seconds with TCP. With this patch, send() returns EPIPE after the
subflow timeout (like TCP) and the close timeout (by default at 60
seconds). This is also validated with new Packetdrill tests, with the
close timeout, and with a reset received in CLOSE_WAIT. Without this
patch, send() stayed blocked in both cases:

  close_timeout_blocked_send.pkt:24: runtime error: exiting while a blocking system call is in progress
  close_wait_reset_blocked_send.pkt:25: runtime error: exiting while a blocking system call is in progress

Fixes: 27e5ccc2d5a5 ("mptcp: fix dangling connection hang-up")
Cc: stable@vger.kernel.org
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/648
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 1f045348764a..e89ed0b1e421 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2756,6 +2756,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);
@@ -3247,6 +3249,7 @@ static void mptcp_worker(struct work_struct *work)
 		mptcp_do_fastclose(sk);
 		mptcp_for_each_subflow_safe(msk, subflow, tmp)
 			__mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
+		WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN);
 		mptcp_close_wake_up(sk);
 	}
 

-- 
2.55.0


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

* [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
                   ` (5 preceding siblings ...)
  2026-12-02 21:29 ` [PATCH net 6/9] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-03 21:51   ` netdev-bot+sashiko
  2026-12-02 21:29 ` [PATCH net 8/9] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 9/9] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
  8 siblings, 1 reply; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), Chris Mason, stable

From: Chris Mason <mason@kernel.org>

If MPTCP sockets receive many small segments whose data stays queued,
TCP can stall on the whole host, and an MPTCP server can be OOM killed
in its memory cgroup, although almost no memory is in use.

When the MPTCP socket (msk) takes over an skb from a subflow,
mptcp_borrow_fwdmem() adds skb->truesize to the sk_forward_alloc of the
msk, and the subflow reserves new memory for the next skb. Both
sk_forward_alloc and sk_rmem_alloc count against tcp_mem and the memory
cgroup, but only sk_rmem_alloc has a limit, sk_rcvbuf, so what queueing
the skb does not move to sk_rmem_alloc has to be released. But
mptcp_try_coalesce() moves only the increase in truesize of the skb that
receives the data, and skb_condense() in mptcp_data_queue_ofo() can
lower skb->truesize, so the rest piles up in sk_forward_alloc.

The fix used here is to return every whole page of sk_forward_alloc with
sk_mem_reclaim(), in mptcp_try_coalesce() once the merged skb is freed,
and in mptcp_data_queue_ofo() once the skb is queued.

This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
a remote peer sends 33000 segments of one byte after a hole in the data
sequence, which are merged in the out-of-order queue. Without this
patch, the memory forward-allocated by the MPTCP socket -- msk_f -- grew
with each merged segment, above 29 MB, versus 3200 bytes with it:

  SNAP label=stage1-1-connections tcp_mem_pages=7168 [...] msk_f=29445248 [...]
  [...] OFOQueue=33000 OFOMerge=32862 [...]

With more connections, the original version of this patch reported that
the TCP memory went above tcp_mem[2], stalling the other TCP
connections, or that the memory cgroup went above its limit.

Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment. Commit message: the rest of the borrowed amount has
  to be released + how the issue was found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index e89ed0b1e421..8649e739ae50 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -196,6 +196,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;
 }
 
@@ -421,6 +424,9 @@ static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
 end:
 	skb_condense(skb);
 	skb_set_owner_r(skb, sk);
+
+	/* skb_condense() can shrink the truesize borrowed from the subflow */
+	sk_mem_reclaim(sk);
 }
 
 static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,

-- 
2.55.0


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

* [PATCH net 8/9] mptcp: don't charge a shared page twice at accept()
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
                   ` (6 preceding siblings ...)
  2026-12-02 21:29 ` [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  2026-12-02 21:29 ` [PATCH net 9/9] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)
  8 siblings, 0 replies; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), Chris Mason, stable

From: Chris Mason <mason@kernel.org>

accept() of an MPTCP connection that has already received data can leak
one page of memory cgroup charge, and the leaked charges can get the
server OOM killed.

At accept(), __inet_accept() charges the MPTCP socket (msk) for the
memory that it holds, rounded up to whole pages, and
mptcp_graft_subflows() does the same for each subflow. A page is
uncharged only once, when the socket that holds it releases it, so
rounding up each socket on its own is only correct while each page
belongs to one socket. But for each skb that the msk takes over from a
subflow, it borrows skb->truesize bytes from the pages that the subflow
reserved, so the two can share a page:

    reserved by the subflow      4096 bytes  1 page
      now held by the msk         896 bytes  charged for 1 page
      still held by the subflow  3200 bytes  charged for 1 page

The fix used here is to keep a running sum of what the msk and its
subflows hold, and to let the new mptcp_charge_subflow() charge each
subflow only for the pages that it adds to the rounded-up sum.

This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch:
an MPTCP server in a memory cgroup, the first byte of the client
arriving before accept(). Without this patch, 4096 bytes stayed charged
to the memory cgroup for each connection, after its end:

  SNAP label=after-1000 rounds=1000 sockets_left_in_srv=0 [...] c_sock=4096000 [...]
  SNAP label=after-5000 rounds=5000 sockets_left_in_srv=0 [...] c_sock=20480000 [...]

With a memory limit, the original version of this patch reported that
the server was killed by the OOM killer after about 14,400 connections.

Fixes: 9db5b3cec4ec ("mptcp: borrow forward memory from subflow")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment. Commit message: how the issue was found, and its
  symptoms. ]
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 8649e739ae50..ed8606fb1a90 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4481,10 +4481,26 @@ static int mptcp_listen(struct socket *sock, int backlog)
 	return err;
 }
 
+/* Similar to __sk_charge(), but the msk and its subflows share pages */
+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);
@@ -4502,6 +4518,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);
 
@@ -4517,7 +4536,7 @@ static void mptcp_graft_subflows(struct sock *sk)
 			goto unlock;
 
 		__mptcp_inherit_cgrp_data(sk, ssk);
-		__mptcp_inherit_memcg(sk, ssk, GFP_KERNEL);
+		mem = mptcp_charge_subflow(sk, ssk, mem);
 
 unlock:
 		release_sock(ssk);

-- 
2.55.0


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

* [PATCH net 9/9] mptcp: don't charge the backlog twice at accept()
  2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
                   ` (7 preceding siblings ...)
  2026-12-02 21:29 ` [PATCH net 8/9] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
@ 2026-12-02 21:29 ` Matthieu Baerts (NGI0)
  8 siblings, 0 replies; 16+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-12-02 21:29 UTC (permalink / raw)
  To: Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Davide Caratti
  Cc: netdev, mptcp, Matthieu Baerts (NGI0), Chris Mason, stable

From: Chris Mason <mason@kernel.org>

accept() can permanently overcharge the memory cgroup of an MPTCP
server, so the server can be OOM killed, if the new connection received
data while its MPTCP socket was locked.

The sockets of an MPTCP connection have no memory cgroup before
accept(), which then charges the sk_forward_alloc and the sk_rmem_alloc
of the MPTCP socket (msk) and of each subflow. mptcp_graft_subflows()
also charges msk->backlog_unaccounted: the truesize of the skbs that
__mptcp_add_backlog() queued while the socket lock of the msk was held
and their subflow had no memory cgroup. But the first charge already
covers each of these skbs that has not been freed, in the sk_rmem_alloc
of its subflow or of the msk, so no later uncharge matches the extra
charge.

The fix used here is to remove msk->backlog_unaccounted, its charge in
mptcp_graft_subflows() and the warning that tests it in
mptcp_can_spool_backlog(). An RFC patch [1] removes the same lines, as
part of another approach.

This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch,
on a kernel with the previous patch: 100,000 connections to an MPTCP
server in a memory cgroup. Without this patch, about 63 MB stayed
charged to this memory cgroup once all the connections were closed, and
to its parent after its removal:

  SNAP label=after-100000 rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 [...] c_sock=63295488 [...]
  [...]
  SNAP label=c-removed rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 c=removed [...] p_sock=63295488 [...]

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

  SNAP label=after-50 rounds=50 sockets_left_in_srv=0 tcp_mem_pages=256 [...] c_sock=12881920 [...]

Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20260924080219.1036588-4-caixinchen1@huawei.com/ [1]
Signed-off-by: Chris Mason <mason@kernel.org>
[ No comment change: the commit message explains why the backlog is
  covered. Commit message: refer to the RFC [1] removing the same lines
  + how the issue was found, and its symptoms. ]
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 35 +----------------------------------
 net/mptcp/protocol.h |  1 -
 2 files changed, 1 insertion(+), 35 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ed8606fb1a90..cef861ea026e 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -795,12 +795,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,
@@ -2334,12 +2328,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;
 
@@ -4508,8 +4496,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);
@@ -4541,26 +4528,6 @@ static void mptcp_graft_subflows(struct sock *sk)
 unlock:
 		release_sock(ssk);
 	}
-
-	if (mem_cgroup_sk_enabled(sk)) {
-		gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
-		int amt;
-
-		/* Account the backlog memory; prior accept() is aware of
-		 * fwd and rmem only.
-		 */
-		mptcp_data_lock(sk);
-		amt = sk_mem_pages(sk->sk_forward_alloc +
-				   msk->backlog_unaccounted +
-				   atomic_read(&sk->sk_rmem_alloc)) -
-		      sk_mem_pages(sk->sk_forward_alloc +
-				   atomic_read(&sk->sk_rmem_alloc));
-		msk->backlog_unaccounted = 0;
-		mptcp_data_unlock(sk);
-
-		if (amt)
-			mem_cgroup_sk_charge(sk, amt, gfp);
-	}
 }
 
 static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 05bf9c3f11b4..73bd9a3008f6 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -392,7 +392,6 @@ struct mptcp_sock {
 
 	struct list_head backlog_list;	/* protected by the data lock */
 	u32		backlog_len;
-	u32		backlog_unaccounted;
 };
 
 #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)

-- 
2.55.0


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

* Re: [PATCH net 2/9] mptcp: keep an orphan while it can send its data
  2026-12-02 21:29 ` [PATCH net 2/9] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
@ 2026-12-03 21:51   ` netdev-bot+sashiko
  0 siblings, 0 replies; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 21:51 UTC (permalink / raw)
  To: matttbe
  Cc: martineau, geliang, davem, edumazet, kuba, pabeni, willemb, horms,
	dcaratti, netdev, mptcp, mason, stable

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

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

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 does not cover MPTCP connections that fell back to TCP
  (plain TCP peer), so they still get the reset this commit claims to…
- [Medium] Unbounded orphan lifetime controlled by the remote peer
  (baseline decision: resolved later in the series).
- [Low] The new timer restart in mptcp_check_send_data_fin() can
  overwrite a deliberately backdated close timeout.
- [Low] mptcp_orphan_keep() evaluates `tcp_jiffies32 -
  READ_ONCE(tcp_sk(ssk)->rcv_tstamp) < 2 * TCP_RTO_MAX` under the msk…

--

mptcp: keep an orphan while it can send its data

This commit keeps an orphaned MPTCP socket alive past its close timeout
while data is still pending and an active subflow recently received an
ACK. In that case mptcp_worker() re-arms the timeout and pushes the
pending data again, and the close timeout is also restarted when the
DATA_FIN is sent for an orphan.

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/647

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index d6a07fa4b4e4c..82a0cbe38192e 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2814,6 +2814,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;

[Severity: High]
Does this cover connections that fell back to plain TCP? The
snd_nxt == write_seq check only counts data still queued at the MPTCP
level. It does not count data that is already in the subflow's TCP
write queue but has not been sent.

On fallback, mptcp_check_allowed_size() doesn't apply the peer window:

net/mptcp/protocol.c:mptcp_check_allowed_size() {
    ...
	if (__mptcp_check_fallback(msk))
		return avail_size;
    ...
}

So the whole tail can move into msk->first as soon as it fits in the
subflow sndbuf, even while the peer window is closed.

__mptcp_push_pending() then calls mptcp_check_send_data_fin(). That
sets snd_nxt = write_seq, restarts the close timeout (the new code
further below) and calls mptcp_subflow_shutdown(). On fallback, that
queues the TCP FIN behind the undelivered data and simulates the
DATA_FIN ack:

net/mptcp/protocol.c:mptcp_subflow_shutdown() {
    ...
		if (__mptcp_check_fallback(mptcp_sk(sk))) {
			pr_debug("Fallback\n");
			ssk->sk_shutdown |= how;
			tcp_shutdown(ssk, how);
			...
			WRITE_ONCE(mptcp_sk(sk)->snd_una, mptcp_sk(sk)->snd_nxt);
    ...
}

>From then on, mptcp_orphan_keep() can never return true. When the
restarted TCP_TIMEWAIT_LEN expires:

mptcp_worker()
  mptcp_do_fastclose()      /* sets fastclosing, returns early on fallback */
  __mptcp_close_ssk(sk, ssk, subflow, 0)
    __mptcp_subflow_disconnect(ssk, subflow, fastclosing)
      tcp_disconnect(ssk, 0)  /* RST, write queue purged */

Take an MPTCP server with a plain TCP client. The server writes data
that fits in the subflow sndbuf, then calls close(), and the client
pauses for more than 60 seconds. Would the client still get ECONNRESET
and lose the tail?

That is the symptom the commit message describes as fixed ("TCP
delivered everything, as MPTCP now does"). The same logic is still
there at the end of the series.

Should the keep check also account for data queued in the subflows on
fallback, or should fallback orphans be left to TCP's orphan handling?

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

[Severity: Low]
Can this unsigned subtraction underflow? tcp_ack() writes
tp->rcv_tstamp in softirq, under the subflow lock:

	tp->rcv_tstamp = tcp_jiffies32;

This check runs under the msk socket lock only, and the order of the
two loads here is unspecified. Consider this sequence:

- the worker loads tcp_jiffies32 (T)
- jiffies ticks
- another CPU processes an ACK and stores rcv_tstamp = T + 1
- the worker loads rcv_tstamp

The difference is then 0xffffffff, so a subflow that has just received
an ACK is treated as not live. If it is the only active subflow, the
orphan is fastclosed.

Would taking a single tcp_jiffies32 snapshot and using a signed
comparison avoid this? mptcp_close_tout_expired() just above already
uses time_after32().

> +	}
> +
> +	return false;
> +}
> +

[ ... ]

> @@ -3151,6 +3173,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);
> +	}

[Severity: Medium]
With only this patch applied, what limits how long an orphan can be
kept? Each time the close timeout expires, it is re-armed here as long
as these hold:

- snd_nxt != write_seq
- an active subflow got any ACK within 2 * TCP_RTO_MAX

There is no cap, no orphan count check and no memory pressure check.
A peer that advertises a zero window and acks the probes could keep
the msk and its send buffers pinned forever. The commit message notes
that "nothing limits how long the peer can keep its window closed".

The TCP orphan limits in tcp_probe_timer() (tcp_orphan_retries() and
tcp_out_of_resources()) don't apply, because the subflows are not
SOCK_DEAD. __mptcp_close() also doesn't count MPTCP orphans in
tcp_orphan_count.

This seems to be fixed later in the series:

- "mptcp: limit an orphan probing a zero window" adds
  mptcp_subflow_probe_timed_out()
- "mptcp: count orphans as TCP does" adds tcp_orphan_count_inc() and
  mptcp_orphan_oom()

Since this patch has Cc: stable, could it be backported without those
follow-ups?

>  	if (mptcp_close_tout_expired(sk)) {
>  		struct mptcp_subflow_context *subflow, *tmp;
>  

[ ... ]

> @@ -3392,6 +3419,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 a close timeout that was backdated on
purpose? When the last subflow of an orphan is closed while msk->first
is already in TCP_CLOSE, __mptcp_close_ssk() does:

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

There are two ways this can run before mptcp_check_send_data_fin():

- inside mptcp_worker() itself, earlier in the same run, via
  mptcp_pm_worker()->mptcp_pm_rm_addr_recv()->
  mptcp_pm_rm_addr_or_subflow()->mptcp_close_ssk()
- from netlink PM paths such as mptcp_pm_nl_subflow_destroy_doit(),
  before the worker runs

A DATA_FIN may still be pending at that point. For example,
__mptcp_subflow_push_pending() pushed the last data and only scheduled
the worker, and all the data was DATA_ACKed. In that case, the new
mptcp_start_tout_timer() call resets probe_timestamp to now. Then
mptcp_close_tout_expired() is false and the state is not TCP_CLOSE, so
__mptcp_destroy_sock() is skipped.

Would the orphan then stay around for another TCP_TIMEWAIT_LEN with no
usable subflow, instead of being destroyed in this worker run as it
was before? This code is unchanged at the end of the series.

> +
>  	mptcp_for_each_subflow(msk, subflow) {
>  		struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

* Re: [PATCH net 3/9] mptcp: limit an orphan probing a zero window
  2026-12-02 21:29 ` [PATCH net 3/9] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
@ 2026-12-03 21:51   ` netdev-bot+sashiko
  0 siblings, 0 replies; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 21:51 UTC (permalink / raw)
  To: matttbe
  Cc: martineau, geliang, davem, edumazet, kuba, pabeni, willemb, horms,
	dcaratti, netdev, mptcp, mason, stable

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

Critical: 0 · High: 1 · Medium: 2 · 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] mptcp_orphan_keep() keeps the orphan as long as any active
  subflow has a fresh rcv_tstamp and mptcp_subflow_probe_timed_out()…
- [Medium] In mptcp_subflow_probe_timed_out() (net/mptcp/protocol.c), the
  data-in-flight branch decides only on `!tp->snd_wnd && icsk->icsk_rto…
- [Medium] The orphan keep logic (mptcp_orphan_keep() plus
  mptcp_subflow_probe_timed_out() in net/mptcp/protocol.c) only looks at…

--

mptcp: limit an orphan probing a zero window

This patch adds mptcp_subflow_probe_timed_out(). It checks whether TCP
would have aborted a subflow if that subflow were an orphan probing a
zero window. mptcp_orphan_keep() now uses it, so a peer that keeps its
window closed can no longer hold an MPTCP orphan forever.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 82a0cbe38192e..96b3baef341f3 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2814,6 +2814,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)
> +{

[ ... ]

> +	slow = lock_sock_fast_nested(ssk);
> +	limit = tcp_rto_max(ssk);
> +	if (tp->packets_out) {
> +		ret = !tp->snd_wnd && icsk->icsk_rto >= limit;

[Severity: Medium]
Can icsk_rto ever reach tcp_rto_max() here when
net.ipv4.tcp_thin_linear_timeouts=1?

Take a subflow with fewer than 4 packets in flight whose peer has shrunk
its window to zero. The subflow is not SOCK_DEAD, so
tcp_retransmit_timer() takes the zero-window branch. It jumps to
out_reset_timer without calling tcp_update_rto_stats():

net/ipv4/tcp_timer.c:tcp_retransmit_timer() {
    ...
	if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) &&
	    !((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))) {
		...
		tcp_enter_loss(sk);
		tcp_retransmit_skb(sk, skb, 1);
		__sk_dst_reset(sk);
		goto out_reset_timer;
	}
    ...
out_reset_timer:
	...
	if (sk->sk_state == TCP_ESTABLISHED &&
	    (tp->thin_lto || READ_ONCE(net->ipv4.sysctl_tcp_thin_linear_timeouts)) &&
	    tcp_stream_is_thin(tp) &&
	    icsk->icsk_retransmits <= TCP_THIN_LINEAR_RETRIES) {
		icsk->icsk_backoff = 0;
		icsk->icsk_rto = clamp(__tcp_set_rto(tp),
				       tcp_rto_min(sk),
				       tcp_rto_max(sk));
    ...
}

Because icsk_retransmits stays at 0, the thin-stream branch runs every
time the timer fires. It recomputes icsk_rto from srtt/rttvar, so this
check never returns true.

The peer's dup ACKs keep rcv_tstamp fresh, so
tcp_rtx_probe0_timed_out() does not abort the subflow either. As a
result, mptcp_worker() keeps re-arming the close timeout through
mptcp_start_tout_timer().

A plain TCP orphan in the same state is SOCK_DEAD, so it skips that
branch, goes through tcp_write_timeout(), and is aborted.

The commit message says this case is covered ("Same with data in
flight, when the peer has shrunk its window to zero"). This setting is
not one of the corner cases it lists.

Only the per-netns sysctl can trigger this, because
TCP_THIN_LINEAR_TIMEOUTS cannot be set on an MPTCP socket. The only
bound is the global tcp_check_oom() limit added later in the series by
"mptcp: count orphans as TCP does".

> +	} 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;

[Severity: High]
For an idle subflow with packets_out == 0 and no send head, this always
returns false. With default settings, could a remote peer use a second,
idle backup subflow to keep the orphan forever?

The sequence would be:

1. The peer opens a second subflow B with MP_JOIN and sets the backup
   bit, which subflow_check_req() copies into subflow->backup. The peer
   could also mark B as backup later with MP_PRIO.

2. The peer keeps its window at zero, so the zero-window probe sits on
   subflow A. With this patch, A is eventually reported as timed out.

3. The peer sends a pure in-window ACK on B more often than every 240s,
   so tcp_ack() keeps B's rcv_tstamp fresh.

B never gets any data:

- mptcp_subflow_get_send() does not pick a backup subflow while A is
  active.
- There is no rtx head, since snd_una == snd_nxt.
- mptcp_subflow_get_retrans() only returns a backup when
  min_stale_count > 1.

Stale detection does not help either. mptcp_pm_chk_stale() skips B:

net/mptcp/pm.c:mptcp_pm_chk_stale() {
    ...
		/* No data outstanding at TCP level? not stale */
		if (tcp_rtx_and_write_queues_empty(ssk))
			continue;
    ...
}

A is never marked stale because its rcv_tstamp keeps changing.

mptcp_orphan_keep() then returns true through B every time the close
timeout expires, and mptcp_worker() re-arms the timer.

The commit message says:

    an idle subflow refreshed by keepalives still keeps the orphan
    when the stale detection is disabled

Is that accurate, given that this case needs no non-default setting?

A non-backup idle subflow does not stay idle, because
__mptcp_push_pending() would queue a probe on it. The backup bit is what
keeps B idle.

This is still present at the end of the series. Only the
tcp_check_oom() limit from "mptcp: count orphans as TCP does" bounds it.

Would it make sense to count only subflows that hold data, or to track
MPTCP-level progress instead?

> +	}
> +	unlock_sock_fast(ssk, slow);
> +
> +	return ret;
> +}

[ ... ]

> @@ -2829,7 +2855,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]
Should this also check MPTCP-level progress? The keep decision only
looks at TCP-level subflow state: rcv_tstamp, packets_out, snd_wnd,
icsk_rto, icsk_backoff and the send head. Nothing checks whether
msk->snd_una has advanced.

A peer could advertise a non-zero TCP window, TCP-ACK every segment,
and never advance DATA_ACK.

ack_update_msk() only moves wnd_end forward, so the msk stops sending
new data once snd_nxt reaches wnd_end. mptcp_sendmsg_frag() then sends
no zero-window probe because snd_una != snd_nxt. At the same time,
snd_nxt != write_seq still holds.

__mptcp_retrans() has no retry limit and always ends with:

reset_timer:
	mptcp_check_and_set_pending(sk);

	if (!mptcp_rtx_timer_pending(sk))
		mptcp_reset_rtx_timer(sk);

The dfrag therefore keeps being retransmitted on a subflow with empty
TCP queues. The peer TCP-ACKs it, so rcv_tstamp stays fresh.

Both branches of mptcp_subflow_probe_timed_out() then return false:

- With packets_out set, snd_wnd is non-zero.
- Without packets_out, there is no send head.

Wouldn't mptcp_orphan_keep() then return true every time the close
timeout expires? That would pin the orphan forever, with a single
subflow and default settings.

This needs a misbehaving peer that withholds DATA_ACK while still
sending TCP ACKs. A Linux peer that stops reading advances DATA_ACK and
closes its window instead.

The keep logic came from the previous commit, "mptcp: keep an orphan
while it can send its data". The only limit is the global
tcp_check_oom() bound added later in the series.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

* Re: [PATCH net 4/9] mptcp: count orphans as TCP does
  2026-12-02 21:29 ` [PATCH net 4/9] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
@ 2026-12-03 21:51   ` netdev-bot+sashiko
  0 siblings, 0 replies; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 21:51 UTC (permalink / raw)
  To: matttbe
  Cc: martineau, geliang, davem, edumazet, kuba, pabeni, willemb, horms,
	dcaratti, netdev, mptcp, mason, stable

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] For fallback MPTCP connections, the new OOM abort at close()
  does not reset the connection.
- [Low] The MIB counter and the RST reason disagree for the new MPTCP OOM
  abort.

--

mptcp: count orphans as TCP does

This commit adds MPTCP sockets orphaned by close() to tcp_orphan_count.
That way tcp_max_orphans and the TCP memory limits apply to them. If
tcp_check_oom() reports too many orphans or too much memory, the orphan
is reset at close() or when its close timeout expires, and the abort is
counted in TCPAbortOnMemory.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 96b3baef341f3..fc8aad7e2fde9 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2840,6 +2840,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;
> +}

[Severity: Low]
Should the reset sent for this abort use SK_RST_REASON_TCP_ABORT_ON_MEMORY?

Both new abort paths end up in mptcp_do_fastclose(). One is a direct call
from __mptcp_close(). The other is from mptcp_worker() once
mptcp_orphan_keep() returns false. mptcp_do_fastclose() hard-codes the
close reason:

net/mptcp/protocol.c:mptcp_do_fastclose() {
    ...
		tcp_send_active_reset(ssk, SK_RST_REASON_TCP_ABORT_ON_CLOSE);
    ...
}

include/net/rstreason.h pairs SK_RST_REASON_TCP_ABORT_ON_MEMORY with
LINUX_MIB_TCPABORTONMEMORY, and __tcp_close() uses the two together:

	if (tcp_check_oom(sk, 0)) {
		tcp_set_state(sk, TCP_CLOSE);
		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 non-fallback MPTCP OOM abort is counted in
TCPAbortOnMemory, but the tcp_send_reset tracepoint reports
ABORT_ON_CLOSE for it.

The hard-coded reason was already there, but this patch is the first to
use it for memory aborts.

[ ... ]

> @@ -3579,8 +3592,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: Medium]
Does this branch reset the connection when the msk has fallen back to
TCP?

On fallback sockets, mptcp_do_fastclose() sets TCP_CLOSE and returns
before it sends any RST:

	/* Explicitly send the fastclose reset as need */
	if (__mptcp_check_fallback(msk))
		return;

So subflow->send_fastclose stays 0. Since the msk is now TCP_CLOSE, the
destroy path runs right away:

__mptcp_close()
  __mptcp_destroy_sock()
    mptcp_destroy()                  /* sets free_first */
      mptcp_destroy_common()
        __mptcp_clear_xmit(sk)       /* drops unsent msk-level data */
        __mptcp_close_ssk(sk, ssk, subflow, 0)
          __tcp_close(ssk, 0)        /* dispose_it is true */

If close() ran with data still pending at the msk level,
mptcp_check_send_data_fin() returned early. The subflow is therefore
still ESTABLISHED, and __tcp_close() sends a normal FIN on it. A RST
follows only if TCP's own tcp_check_oom(ssk, 0) in __tcp_close() also
fires.

In the orphan-limit case, both checks read the same cached orphan count.
TCP then resets as well, and TCPAbortOnMemory is incremented a second
time for the same connection.

In the memory case, tcp_out_of_memory() checks the subflow's
sk_wmem_queued against SOCK_MIN_SNDBUF. That value can be small while the
msk's queue is large, for example when msk-to-subflow pushes fail under
tcp_mem[2] pressure. Can the peer then get a clean FIN after
__mptcp_clear_xmit() has silently dropped the rest of the stream?

The close timeout path in mptcp_worker() handles the same fallback socket
differently. There, free_first is still 0, so __mptcp_close_ssk() goes
through __mptcp_subflow_disconnect() and tcp_disconnect(), which sends a
RST.

The commit message says:

    reset an orphan when there are too many orphans, or when TCP uses
    too much memory: at close(), and when its close timeout expires

Should the fallback case get an explicit reset here, with
TCPAbortOnMemory counted only once? Later patches in this series don't
seem to change mptcp_do_fastclose(), mptcp_orphan_oom() or this branch of
__mptcp_close().

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

* Re: [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, as TCP does
  2026-12-02 21:29 ` [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
@ 2026-12-03 21:51   ` netdev-bot+sashiko
  0 siblings, 0 replies; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 21:51 UTC (permalink / raw)
  To: matttbe
  Cc: martineau, geliang, davem, edumazet, kuba, pabeni, willemb, horms,
	dcaratti, netdev, mptcp, mason, stable

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] This patch's fix (EOF after a DATA_FIN even when a reset
  follows) does not cover the passive side when accept() gets the msk…
- [Low] mptcp_close_ssk() (net/mptcp/protocol.c:2787-2788) reads
  msk->rcv_data_fin with READ_ONCE() before it takes the first subflow's…

--

mptcp: return EOF after a DATA_FIN, as TCP does

Once a DATA_FIN has been processed, this patch sets SOCK_DONE on the msk.
mptcp_recvmsg() now checks that flag before the socket error, so recv()
returns EOF after the data even if a reset or MP_FASTCLOSE follows. After
a fallback, the emulated DATA_FIN is now set before the subflow close is
scheduled, and mptcp_close_ssk() processes it before the first subflow is
disconnected.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/647

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index fc8aad7e2fde9..1f045348764ad 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c

[ ... ]

> @@ -2763,12 +2775,21 @@ void mptcp_close_ssk(struct sock *sk, struct sock *ssk,

[ ... ]

> +	mptcp_pm_subflow_check_next(msk, subflow);
> +
> +	/* On fallback, the FIN of the first subflow is cleared when it is
> +	 * disconnected: process the DATA_FIN emulated from it before.
> +	 */
> +	if (ssk == msk->first && __mptcp_check_fallback(msk) &&
> +	    READ_ONCE(msk->rcv_data_fin) && !sock_flag(sk, SOCK_DEAD)) {
> +		mptcp_move_skbs(sk);
> +		mptcp_check_data_fin(sk);
> +	}

[Severity: Medium]
Is the passive side covered when accept() takes the msk lock before
mptcp_worker() has handled the emulated DATA_FIN?

When the first subflow is already closed and is the only subflow,
mptcp_stream_accept() moves newsk to TCP_CLOSE before it calls
mptcp_close_ssk():

net/mptcp/protocol.c:mptcp_stream_accept() {
    ...
		if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
			if (unlikely(list_is_singular(&msk->conn_list)))
				mptcp_set_state(newsk, TCP_CLOSE);
			mptcp_close_ssk(newsk, msk->first,
					mptcp_subflow_ctx(msk->first));
		}
    ...
}

The new block above then matches. This is the first subflow, the msk has
fallen back, subflow_sched_work_if_closed() has set rcv_data_fin, and the
msk is not SOCK_DEAD.

But mptcp_check_data_fin() does nothing here. mptcp_pending_data_fin()
only accepts TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2, so the
msk gets neither RCV_SHUTDOWN nor SOCK_DONE.

Next, __mptcp_close_ssk()->__mptcp_subflow_disconnect()->tcp_disconnect()
clears SOCK_DONE on the subflow. It keeps sk_err, which tcp_reset() set
to EPIPE in CLOSE_WAIT.

The accept() caller owns the msk, so the error report is deferred as
MPTCP_ERROR_REPORT. Then at release_sock():

mptcp_release_cb()
  __mptcp_error_report()
    __mptcp_subflow_error_report()

This skips the new SOCK_DONE propagation, because the subflow flag is
already cleared, and sets sk_err = EPIPE on the msk.

mptcp_worker() then bails out on TCPF_CLOSE, so nothing corrects this
later. Doesn't mptcp_recvmsg() then return the data followed by -EPIPE
instead of EOF? The commit message says this case is fixed.

The non-fallback case looks similar. Data, a DATA_FIN and an MP_FASTCLOSE
can all arrive before accept(), with the worker not yet run. In that case
mptcp_check_fastclose() and mptcp_check_data_fin() are never called, and
recv() returns -ENOTCONN after the data instead of EOF.

Could the pending DATA_FIN be processed before mptcp_set_state(newsk,
TCP_CLOSE) in mptcp_stream_accept()?

>  
>  	__mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
>  }

[Severity: Low]
Can the lockless READ_ONCE(msk->rcv_data_fin) check in mptcp_close_ssk()
race with the subflow side?

The check runs before lock_sock_nested() in __mptcp_close_ssk() takes the
first subflow's lock. The emulated DATA_FIN is written from the subflow's
softirq / state_change context:

subflow_sched_work_if_closed()
  mptcp_update_rcv_data_fin()

and the msk lock does not exclude that path.

mptcp_pm_nl_subflow_destroy_doit() in net/mptcp/pm_userspace.c holds only
the msk lock and has no fallback check. It can select msk->first and
does:

	mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN);
	mptcp_close_ssk(sk, ssk, mptcp_subflow_ctx(ssk));

Consider this interleaving:

1. mptcp_close_ssk() reads rcv_data_fin == 0 and is then preempted.

2. The subflow receives a FIN (tcp_fin() sets SOCK_DONE), then a RST.
   sk_err is set and the error report is deferred as MPTCP_ERROR_REPORT.
   tcp_done() moves the subflow to TCP_CLOSE, and
   subflow_sched_work_if_closed() sets the dummy rcv_data_fin.

3. __mptcp_close_ssk() locks the subflow, sees TCP_CLOSE and calls
   tcp_disconnect(), which clears SOCK_DONE.

4. At release_sock(msk), __mptcp_subflow_error_report() finds no
   SOCK_DONE on the subflow. It moves the msk to TCP_CLOSE and sets
   sk_err.

mptcp_check_data_fin() never runs on this path, so recv() would return
the error instead of EOF.

Moving the MPTCP_WORK_CLOSE_SUBFLOW bit after the dummy DATA_FIN in
subflow_sched_work_if_closed() only orders the worker runs that the bit
triggers, so it does not help this caller.

This is a rare corner case. It needs a userspace PM (CAP_NET_ADMIN)
tearing down the only subflow of a fallback connection, plus precisely
timed peer packets.

Would it make sense to re-check rcv_data_fin under the subflow lock
before disconnecting, or to stop relying on SOCK_DONE surviving on the
subflow?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

* Re: [PATCH net 6/9] mptcp: wake up blocked senders when no sf left
  2026-12-02 21:29 ` [PATCH net 6/9] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
@ 2026-12-03 21:51   ` netdev-bot+sashiko
  0 siblings, 0 replies; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 21:51 UTC (permalink / raw)
  To: matttbe
  Cc: martineau, geliang, davem, edumazet, kuba, pabeni, willemb, horms,
	dcaratti, netdev, mptcp, mason, stable

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] A blocked send() can still hang forever after the last subflow
  is gone, so the bug in this patch's title ("wake up blocked senders…

--

mptcp: wake up blocked senders when no sf left

This commit sets SEND_SHUTDOWN on the msk when it moves to TCP_CLOSE
because its last subflow is gone. This is done at the bottom of
__mptcp_close_ssk() and in the close-timeout branch of mptcp_worker(). A
send() blocked waiting for memory then returns EPIPE instead of hanging.

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/648

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 1f045348764ad..e89ed0b1e4218 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -2756,6 +2756,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);

[Severity: High]
Can a blocked send() still hang forever if the only remaining subflow is
msk->first and the path manager closes it gracefully?

Both new SEND_SHUTDOWN writes depend on the "all subflows closed" check at
the bottom of __mptcp_close_ssk(). That check requires msk->first to
already be in TCP_CLOSE:

    if (list_is_singular(&msk->conn_list) && msk->first &&
        inet_sk_state_load(msk->first) == TCP_CLOSE) {

A peer that sends RM_ADDR for remote id 0 reaches this path. So does a
userspace PM subflow destroy through mptcp_pm_nl_subflow_destroy_doit():

mptcp_pm_rm_addr_or_subflow()
  mptcp_subflow_shutdown(sk, ssk, how)
  mptcp_close_ssk()
    subflow->close_event_done = true;
    __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH)
      __mptcp_subflow_disconnect()
        tcp_shutdown(ssk, SEND_SHUTDOWN);

mptcp_pm_rm_addr_or_subflow() only skips subflows in FIN_WAIT1,
FIN_WAIT2, CLOSING or CLOSE. It has no check for the last subflow.

free_first is only set at destroy time, so dispose_it is false for
msk->first. __mptcp_subflow_disconnect() therefore only sends a FIN, and
the ssk ends up in FIN_WAIT1, not TCP_CLOSE.

The check above is then false, so none of its three branches runs. The
msk does not move to TCP_CLOSE, SEND_SHUTDOWN is not set, and
mptcp_start_tout_timer() is not called.

Later the ssk reaches TCP_CLOSE. subflow_sched_work_if_closed() sets
MPTCP_WORK_CLOSE_SUBFLOW, and __mptcp_close_subflow() calls
mptcp_close_ssk() again. That call returns early:

    if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
        return;

So the "all subflows closed" check is never run again for this subflow.

The msk then stays in TCP_ESTABLISHED with no usable subflow:

  - probe_timestamp is never set, so mptcp_close_tout_expired() stays
    false and the new SEND_SHUTDOWN in mptcp_worker() is never reached.
  - __mptcp_subflow_error_report() only passes errors on in SYN_SENT or
    after fallback, so sk_err is never set.

A sender waiting in sk_stream_wait_memory() would never see sk_err,
SEND_SHUTDOWN or freed write memory.

Should this path re-check "all subflows closed" when a FIN-shut first
subflow later reaches TCP_CLOSE, even with close_event_done set? Or
should it arm the close timeout here?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

* Re: [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs
  2026-12-02 21:29 ` [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
@ 2026-12-03 21:51   ` netdev-bot+sashiko
  0 siblings, 0 replies; 16+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 21:51 UTC (permalink / raw)
  To: matttbe
  Cc: martineau, geliang, davem, edumazet, kuba, pabeni, willemb, horms,
	dcaratti, netdev, mptcp, mason, stable

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, mptcp_try_coalesce() in net/mptcp/protocol.c
  has two comments next to each other that disagree about the 'from'…

--

mptcp: reclaim forward memory after coalescing skbs

When an MPTCP socket takes an skb from a subflow, mptcp_borrow_fwdmem()
credits skb->truesize to the msk forward allocation. Only part of that
credit moves to sk_rmem_alloc when the skb is coalesced or condensed, so
the rest builds up in sk_forward_alloc. This patch adds sk_mem_reclaim()
calls in mptcp_try_coalesce() and mptcp_data_queue_ofo() to release that
leftover memory.

> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index e89ed0b1e4218..8649e739ae500 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -196,6 +196,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 after this change the two comments in
mptcp_try_coalesce() disagree about the 'from' skb. Each one is wrong for
one kind of caller.

The existing comment just above 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
	 */

For the borrowed callers, __mptcp_move_skb() and mptcp_data_queue_ofo()
via mptcp_ooo_try_coalesce(), mptcp_subflow_lend_fwdmem() has cleared
from->destructor. mptcp_borrow_fwdmem() has also already added
from->truesize to sk_forward_alloc.

Since delta can't exceed from->truesize, sk_mem_charge(sk, delta) can't
push the forward allocation negative. kfree_skb_partial() also runs no
destructor, so the later free restores nothing. That is the reason this
patch needs the explicit sk_mem_reclaim().

The new comment assumes 'from' is always borrowed. That doesn't hold for
__mptcp_ofo_queue():

	if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {

On that path 'from' is an out-of-order queue skb. skb_set_owner_r() already
gave it sock_rfree at the end: label of mptcp_data_queue_ofo(), so
kfree_skb_partial() ends up calling sock_rfree()->sk_mem_uncharge(). That
already returns from->truesize and reclaims. There the old comment is the
accurate one, and the new reclaim is redundant but harmless.

mptcp_drop() states this borrowed vs owned split explicitly:

	if (!skb->destructor)
		sk_mem_reclaim(sk);

Could the comments in mptcp_try_coalesce() be updated to cover both cases?
For example, drop the stale "later skb free will restore" text and say the
reclaim is needed for borrowed skbs that have no destructor.

>  	return true;
>  }
>  

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17%40kernel.org

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

end of thread, other threads:[~2026-12-03 21:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 21:29 [PATCH net 0/9] mptcp: misc fixes for v7.4-rc7 Matthieu Baerts (NGI0)
2026-12-02 21:29 ` [PATCH net 1/9] mptcp: pm: kernel: c-flag: keep local_addr_used in sync Matthieu Baerts (NGI0)
2026-12-02 21:29 ` [PATCH net 2/9] mptcp: keep an orphan while it can send its data Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 3/9] mptcp: limit an orphan probing a zero window Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 4/9] mptcp: count orphans as TCP does Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 5/9] mptcp: return EOF after a DATA_FIN, " Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 6/9] mptcp: wake up blocked senders when no sf left Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 7/9] mptcp: reclaim forward memory after coalescing skbs Matthieu Baerts (NGI0)
2026-12-03 21:51   ` netdev-bot+sashiko
2026-12-02 21:29 ` [PATCH net 8/9] mptcp: don't charge a shared page twice at accept() Matthieu Baerts (NGI0)
2026-12-02 21:29 ` [PATCH net 9/9] mptcp: don't charge the backlog " Matthieu Baerts (NGI0)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox