Netdev List
 help / color / mirror / Atom feed
* [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5
@ 2026-11-23 13:24 Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 01/10] tcp: drain the queues of a listen() that fails Matthieu Baerts (NGI0)
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable, Neal Cardwell, Kuniyuki Iwashima,
	Hyunwoo Kim, Josef Bacik, Martin KaFai Lau, Daniel Borkmann,
	Alexei Starovoitov, Martin KaFai Lau, bpf

Here are some unrelated fixes:

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

- Patch 4: fix UaF in corner cases from delegated actions. A fix for
  v5.12.

- Patches 5-6: 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 7-8: do not let PM listeners pin their netns, leaked
  otherwise. A fix for v5.12.

- Patch 9: initialize drop_req, not to leak sockets with SO_REUSEPORT
  migration. A fix for v5.14.

- Patch 10: do not pass a BPF request sock to an MPTCP listener, to
  avoid a slab-out-of-bounds write. A fix for v6.9.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Chris Mason (6):
      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: leave an orphan's DATA_FIN to the worker
      mptcp: initialize drop_req in subflow_init_req()
      tcp: do not pass a BPF reqsk to an MPTCP listener

Hyunwoo Kim (1):
      mptcp: fix use-after-free of the subflow context on the delegated list

Josef Bacik (1):
      mptcp: pm: don't let listeners pin their netns

Matthieu Baerts (NGI0) (2):
      mptcp: don't leak an orphan when the PM closes its last subflow
      net: add __sk_net_refcnt_upgrade() with a GFP mask

 include/net/sock.h              |  1 +
 net/core/sock.c                 |  9 +++++++--
 net/ipv4/inet_connection_sock.c | 12 ++++++++----
 net/ipv4/syncookies.c           |  3 ++-
 net/mptcp/protocol.c            | 42 +++++++++++++++++++++++++++++++++--------
 net/mptcp/protocol.h            | 18 ++++++++++++++++--
 net/mptcp/subflow.c             | 32 ++++++++++++++++++++++++++++---
 7 files changed, 97 insertions(+), 20 deletions(-)
---
base-commit: 3896ae4adf5ffc11ffd0f7f42c3923e8dc195e75
change-id: 20261123-net-mptcp-misc-fixes-7-4-rc5-965d6b4fb777

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


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

* [PATCH net 01/10] tcp: drain the queues of a listen() that fails
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 02/10] mptcp: " Matthieu Baerts (NGI0)
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable, Neal Cardwell, Kuniyuki Iwashima

From: Chris Mason <mason@kernel.org>

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

Fixes: 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ 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. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>
---
 net/ipv4/inet_connection_sock.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 9a3b05edb62b..2e27b3e592a8 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1382,8 +1382,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);
@@ -1401,9 +1401,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;
 }
 

-- 
2.55.0


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

* [PATCH net 02/10] mptcp: drain the queues of a listen() that fails
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 01/10] tcp: drain the queues of a listen() that fails Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6 listener Matthieu Baerts (NGI0)
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable

From: Chris Mason <mason@kernel.org>

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

Fixes: 76e2a55d1625 ("mptcp: better msk-level shutdown.")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment. Add a Fixes tag. Commit message: how the issue was
  found, and its symptoms. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b375da1f17fe..fd88104f0631 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4340,6 +4340,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));
 

-- 
2.55.0


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

* [PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6 listener
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 01/10] tcp: drain the queues of a listen() that fails Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 02/10] mptcp: " Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated list Matthieu Baerts (NGI0)
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable

From: Chris Mason <mason@kernel.org>

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

Fixes: cf7da0d66cc1 ("mptcp: Create SUBFLOW socket for incoming connections")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ Commit message: how the issue was found, and its symptoms ]
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 fd88104f0631..50c294d925b0 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3677,6 +3677,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) {

-- 
2.55.0


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

* [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated list
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (2 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6 listener Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 05/10] mptcp: leave an orphan's DATA_FIN to the worker Matthieu Baerts (NGI0)
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Hyunwoo Kim, stable

From: Hyunwoo Kim <imv4bel@gmail.com>

mptcp_subflow_delegate() links the subflow context into a per-CPU napi
list and takes a reference on the subflow socket. The context is a
separate allocation, reached through icsk_ulp_data, and the list holds
no reference to it.

inet_csk_destroy_sock() runs sk_prot->destroy() regardless of the
outstanding references. That path ends in tcp_cleanup_ulp(), which calls
subflow_ulp_release(). subflow_ulp_release() frees the context with
kfree_rcu() but does not remove it from the list. Once the grace period
elapses and the context is actually freed, the next mptcp_napi_poll()
dequeues that entry and mptcp_subflow_delegated_next() writes to the
freed context with list_del_init(). That is the use-after-free.

The decoded KASAN trace is:

 ==================================================================
 BUG: KASAN: slab-use-after-free in __list_del_entry_valid_or_report (lib/list_debug.c:49)
 Read of size 8 at addr ffff88800cc13cc8 by task poc/88

 CPU: 3 UID: 65534 PID: 88 Comm: poc Not tainted 7.2.0-rc7 #1 PREEMPT(lazy)
 Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
 Call Trace:
  <IRQ>
  dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
  print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
  ? __pfx__raw_spin_lock_irqsave (include/asm-generic/qrwlock.h:122 (discriminator 4))
  ? __list_del_entry_valid_or_report (lib/list_debug.c:49)
  kasan_report (mm/kasan/report.c:595)
  ? __list_del_entry_valid_or_report (lib/list_debug.c:49)
  __list_del_entry_valid_or_report (lib/list_debug.c:49)
  mptcp_napi_poll (include/linux/list.h:132 include/linux/list.h:246 include/linux/list.h:318 net/mptcp/protocol.h:787 net/mptcp/protocol.c:4620)
  ? call_timer_fn (kernel/time/timer.c:1748)
  __napi_poll (net/core/dev.c:7735)
  ? __pfx_delayed_work_timer_fn (include/linux/list.h:404 (discriminator 2))
  net_rx_action (net/core/dev.c:7798 net/core/dev.c:7955)
  ? __pfx_net_rx_action (include/net/gro.h:525)
  ? _raw_spin_lock_irq (include/linux/instrumented.h:55 include/linux/atomic/atomic-instrumented.h:1301 include/asm-generic/qspinlock.h:111 include/linux/spinlock.h:187 include/linux/spinlock_api_smp.h:143 kernel/locking/spinlock.c:174)
  ? __pfx__raw_spin_lock_irq (kernel/locking/spinlock.c:183)
  ? try_to_wake_up (include/linux/spinlock.h:571 kernel/sched/core.c:4292)
  handle_softirqs (kernel/softirq.c:622)
  ? __pfx_handle_softirqs (include/linux/wait_bit.h:77)
  ? __hrtimer_rearm_deferred (kernel/time/hrtimer.c:707 kernel/time/hrtimer.c:2141 kernel/time/hrtimer.c:2161)
  do_softirq (kernel/softirq.c:523 (discriminator 20) kernel/softirq.c:510 (discriminator 20))
  </IRQ>
  <TASK>
  __local_bh_enable_ip (kernel/softirq.c:450)
  inet_stream_connect (net/ipv4/af_inet.c:756)
  __sys_connect (net/socket.c:2154)
  ? __pfx___sys_connect (net/socket.c:2136)
  ? __sys_setsockopt (include/linux/file.h:63 include/linux/file.h:83 net/socket.c:2385)
  __x64_sys_connect (net/socket.c:2160 net/socket.c:2157 net/socket.c:2157)
  ? fpregs_assert_state_consistent (include/linux/instrumented.h:82 include/asm-generic/bitops/instrumented-non-atomic.h:141 include/linux/thread_info.h:133 arch/x86/kernel/fpu/core.c:912)
  do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94)
  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
 RIP: 0033:0x4216eb
 Code: 48 89 e5 48 83 ec 10 89 55 f8 48 89 75 f0 89 7d fc e8 b9 ec 02 00 8b 55 f8 48 8b 75 f0 41 89 c0 8b 7d fc b8 2a 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 2d 44 89 c7 89 45 fc e8 12 ed 02 00 8b 45 fc
All code
========
   0:	48 89 e5             	mov    %rsp,%rbp
   3:	48 83 ec 10          	sub    $0x10,%rsp
   7:	89 55 f8             	mov    %edx,-0x8(%rbp)
   a:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
   e:	89 7d fc             	mov    %edi,-0x4(%rbp)
  11:	e8 b9 ec 02 00       	call   0x2eccf
  16:	8b 55 f8             	mov    -0x8(%rbp),%edx
  19:	48 8b 75 f0          	mov    -0x10(%rbp),%rsi
  1d:	41 89 c0             	mov    %eax,%r8d
  20:	8b 7d fc             	mov    -0x4(%rbp),%edi
  23:	b8 2a 00 00 00       	mov    $0x2a,%eax
  28:	0f 05                	syscall
  2a:*	48 3d 00 f0 ff ff    	cmp    $0xfffffffffffff000,%rax		<-- trapping instruction
  30:	77 2d                	ja     0x5f
  32:	44 89 c7             	mov    %r8d,%edi
  35:	89 45 fc             	mov    %eax,-0x4(%rbp)
  38:	e8 12 ed 02 00       	call   0x2ed4f
  3d:	8b 45 fc             	mov    -0x4(%rbp),%eax

Code starting with the faulting instruction
===========================================
   0:	48 3d 00 f0 ff ff    	cmp    $0xfffffffffffff000,%rax
   6:	77 2d                	ja     0x35
   8:	44 89 c7             	mov    %r8d,%edi
   b:	89 45 fc             	mov    %eax,-0x4(%rbp)
   e:	e8 12 ed 02 00       	call   0x2ed25
  13:	8b 45 fc             	mov    -0x4(%rbp),%eax
 RSP: 002b:00007fbe0147b1d0 EFLAGS: 00000293 ORIG_RAX: 000000000000002a
 RAX: ffffffffffffffda RBX: 000000000000000a RCX: 00000000004216eb
 RDX: 0000000000000010 RSI: 00007fbe0147b200 RDI: 000000000000000a
 RBP: 00007fbe0147b1e0 R08: 0000000000000000 R09: 0000000000000000
 R10: 00007fbe0147b1f8 R11: 0000000000000293 R12: 00007fbe0147b1f8
 R13: 00007fbe0157b678 R14: 00007fbe0147b1f4 R15: 00007fffd4bc16c0
  </TASK>

 Allocated by task 90:
  kasan_save_stack (mm/kasan/common.c:57)
  kasan_save_track (mm/kasan/common.c:78)
  __kasan_kmalloc (mm/kasan/common.c:398 mm/kasan/common.c:415)
  __kmalloc_cache_noprof (include/linux/kasan.h:263 mm/slub.c:5489)
  subflow_create_ctx (include/linux/slab.h:988 include/linux/slab.h:1309 net/mptcp/subflow.c:1845)
  subflow_ulp_init (net/mptcp/subflow.c:1977)
  tcp_set_ulp (net/ipv4/tcp_ulp.c:146 net/ipv4/tcp_ulp.c:167)
  mptcp_subflow_create_socket (net/mptcp/subflow.c:1806)
  __mptcp_nmpc_sk.part.0 (net/mptcp/protocol.c:111 net/mptcp/protocol.c:143)
  mptcp_connect (net/mptcp/protocol.c:139 net/mptcp/protocol.c:4009)
  __inet_stream_connect (net/ipv4/af_inet.c:684)
  inet_stream_connect (net/ipv4/af_inet.c:755)
  __sys_connect (net/socket.c:2154)
  __x64_sys_connect (net/socket.c:2160 net/socket.c:2157 net/socket.c:2157)
  do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94)
  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)

 Freed by task 22:
  kasan_save_stack (mm/kasan/common.c:57)
  kasan_save_track (mm/kasan/common.c:78)
  kasan_save_free_info (mm/kasan/generic.c:584)
  __kasan_slab_free (mm/kasan/common.c:253 mm/kasan/common.c:285)
  kvfree_rcu_cb (include/linux/kasan.h:235 mm/slub.c:2677 mm/slub.c:6377 mm/slub.c:6662)
  rcu_core (kernel/rcu/tree.c:2645 kernel/rcu/tree.c:2897)
  handle_softirqs (kernel/softirq.c:622)
  run_ksoftirqd (kernel/softirq.c:1076 kernel/softirq.c:1068)
  smpboot_thread_fn (kernel/smpboot.c:160)
  kthread (kernel/kthread.c:436)
  ret_from_fork (arch/x86/kernel/process.c:158)
  ret_from_fork_asm (arch/x86/entry/entry_64.S:245)

 Last potentially related work creation:
  kasan_save_stack (mm/kasan/common.c:57)
  kasan_record_aux_stack (mm/kasan/generic.c:556)
  __call_rcu_common.constprop.0 (kernel/rcu/tree.c:3159)
  tcp_cleanup_ulp (net/ipv4/tcp_ulp.c:124)
  tcp_v4_destroy_sock (net/ipv4/tcp_ipv4.c:2437)
  inet_csk_destroy_sock (net/ipv4/inet_connection_sock.c:1282)
  __tcp_close (net/ipv4/tcp.c:3299)
  __mptcp_close_ssk (net/mptcp/protocol.c:2648)
  mptcp_destroy_common (net/mptcp/protocol.c:3442 (discriminator 1))
  mptcp_destroy (net/mptcp/protocol.c:3651)
  __mptcp_destroy_sock (net/mptcp/protocol.c:3284)
  __mptcp_close (net/mptcp/protocol.c:3386)
  mptcp_close (net/mptcp/protocol.c:3401)
  inet_release (net/ipv4/af_inet.c:442)
  __sock_release (net/socket.c:710)
  sock_close (net/socket.c:1501 (discriminator 1))
  __fput (fs/file_table.c:512)
  fput_close_sync (fs/file_table.c:617)
  __x64_sys_close (fs/open.c:1511 fs/open.c:1496 fs/open.c:1496)
  do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94)
  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)

 Second to last potentially related work creation:
  kasan_save_stack (mm/kasan/common.c:57)
  kasan_record_aux_stack (mm/kasan/generic.c:556)
  kvfree_call_rcu (mm/slab_common.c:1288)
  tcp_cleanup_ulp (net/ipv4/tcp_ulp.c:124)
  tcp_v4_destroy_sock (net/ipv4/tcp_ipv4.c:2437)
  inet_csk_destroy_sock (net/ipv4/inet_connection_sock.c:1282)
  __tcp_close (net/ipv4/tcp.c:3299)
  __mptcp_close_ssk (net/mptcp/protocol.c:2648)
  mptcp_destroy_common (net/mptcp/protocol.c:3442 (discriminator 1))
  mptcp_destroy (net/mptcp/protocol.c:3651)
  __mptcp_destroy_sock (net/mptcp/protocol.c:3284)
  __mptcp_close (net/mptcp/protocol.c:3386)
  mptcp_close (net/mptcp/protocol.c:3401)
  inet_release (net/ipv4/af_inet.c:442)
  __sock_release (net/socket.c:710)
  sock_close (net/socket.c:1501 (discriminator 1))
  __fput (fs/file_table.c:512)
  fput_close_sync (fs/file_table.c:617)
  __x64_sys_close (fs/open.c:1511 fs/open.c:1496 fs/open.c:1496)
  do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94)
  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)

 The buggy address belongs to the object at ffff88800cc13c00
  which belongs to the cache kmalloc-512 of size 512
 The buggy address is located 200 bytes inside of
  freed 512-byte region [ffff88800cc13c00, ffff88800cc13e00)

 The buggy address belongs to the physical page:
 page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xcc10
 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
 flags: 0x100000000000040(head|node=0|zone=1)
 page_type: f5(slab)
 raw: 0100000000000040 ffff888007042c80 dead000000000100 dead000000000122
 raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
 head: 0100000000000040 ffff888007042c80 dead000000000100 dead000000000122
 head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
 head: 0100000000000002 ffffffffffffff01 00000000ffffffff 00000000ffffffff
 head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
 page dumped because: kasan: bad access detected

 Memory state around the buggy address:
  ffff88800cc13b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
  ffff88800cc13c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 >ffff88800cc13c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                               ^
  ffff88800cc13d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff88800cc13d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ==================================================================

The freeing path cannot dequeue the entry itself: the list is per-CPU
and only the CPU that queued the subflow may touch it, as
tcp_release_cb_override() already notes.

Delay the free instead. Add MPTCP_DELEGATE_DEAD.
mptcp_subflow_free_ctx() sets it and frees the context only if the
subflow is not scheduled, while mptcp_napi_poll() frees it if the dead
bit is set when it clears the scheduled bit. Either
mptcp_subflow_free_ctx() gets there first, sees the scheduled bit and
leaves the free to mptcp_napi_poll(), or mptcp_napi_poll() gets there
first, does not see the dead bit and mptcp_subflow_free_ctx() does the
free.

Also skip mptcp_subflow_process_delegated() once the dead bit is set.
subflow_ulp_release() has already dropped the msk reference by then, so
the pending actions must not run.

Finally, move delegated_status out of struct_group(reset).
mptcp_subflow_ctx_reset() clears that group on disconnect, and clearing
the scheduled bit while the entry is still queued would let
mptcp_subflow_free_ctx() free a context the napi list still points to.
delegated_node is already outside the group.

Fixes: b19bc2945b40 ("mptcp: implement delegated actions")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 13 ++++++++++---
 net/mptcp/protocol.h | 18 ++++++++++++++++--
 net/mptcp/subflow.c  |  4 ++--
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 50c294d925b0..23d35f43b566 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2708,7 +2708,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 	 */
 	if (!inet_csk(ssk)->icsk_ulp_ops) {
 		WARN_ON_ONCE(!sock_flag(ssk, SOCK_DEAD));
-		kfree_rcu(subflow, rcu);
+		mptcp_subflow_free_ctx(subflow);
 	} else {
 		/* otherwise tcp will dispose of the ssk and subflow ctx */
 		__tcp_close(ssk, 0);
@@ -4803,10 +4803,13 @@ static int mptcp_napi_poll(struct napi_struct *napi, int budget)
 	delegated = container_of(napi, struct mptcp_delegated_action, napi);
 	while ((subflow = mptcp_subflow_delegated_next(delegated)) != NULL) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		long status;
 
 		bh_lock_sock_nested(ssk);
 		if (!sock_owned_by_user(ssk)) {
-			mptcp_subflow_process_delegated(ssk, xchg(&subflow->delegated_status, 0));
+			status = xchg(&subflow->delegated_status, 0);
+			if (!(status & BIT(MPTCP_DELEGATE_DEAD)))
+				mptcp_subflow_process_delegated(ssk, status);
 		} else {
 			/* tcp_release_cb_override already processed
 			 * the action or will do at next release_sock().
@@ -4814,11 +4817,15 @@ static int mptcp_napi_poll(struct napi_struct *napi, int budget)
 			 * CPU that scheduled it.
 			 */
 			smp_wmb();
-			clear_bit(MPTCP_DELEGATE_SCHEDULED, &subflow->delegated_status);
+			status = set_mask_bits(&subflow->delegated_status,
+					       BIT(MPTCP_DELEGATE_SCHEDULED), 0);
 		}
 		bh_unlock_sock(ssk);
 		sock_put(ssk);
 
+		if (status & BIT(MPTCP_DELEGATE_DEAD))
+			kfree_rcu(subflow, rcu);
+
 		if (++work_done == budget)
 			return budget;
 	}
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 7d226ee38315..7644651f01a8 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -553,8 +553,10 @@ DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
 #define MPTCP_DELEGATE_SEND		1
 #define MPTCP_DELEGATE_ACK		2
 #define MPTCP_DELEGATE_SNDBUF		3
+#define MPTCP_DELEGATE_DEAD		4
 
-#define MPTCP_DELEGATE_ACTIONS_MASK	(~BIT(MPTCP_DELEGATE_SCHEDULED))
+#define MPTCP_DELEGATE_ACTIONS_MASK	(~(BIT(MPTCP_DELEGATE_SCHEDULED) | \
+					   BIT(MPTCP_DELEGATE_DEAD)))
 /* MPTCP subflow context */
 struct mptcp_subflow_context {
 	struct	list_head node;/* conn_list of subflows */
@@ -628,11 +630,11 @@ struct mptcp_subflow_context {
 
 	u32	subflow_id;
 
-	long	delegated_status;
 	unsigned long	fail_tout;
 
 	);
 
+	long	delegated_status;
 	struct	list_head delegated_node;   /* link into delegated_action, protected by local BH */
 
 	u32	setsockopt_seq;
@@ -671,6 +673,8 @@ mptcp_subflow_ctx_reset(struct mptcp_subflow_context *subflow)
 	memset(&subflow->reset, 0, sizeof(subflow->reset));
 	subflow->request_mptcp = 1;
 	WRITE_ONCE(subflow->local_id, -1);
+	set_mask_bits(&subflow->delegated_status,
+		      MPTCP_DELEGATE_ACTIONS_MASK, 0);
 }
 
 /* Convert reset reasons in MPTCP to enum sk_rst_reason type */
@@ -808,6 +812,16 @@ mptcp_subflow_delegated_next(struct mptcp_delegated_action *delegated)
 	return ret;
 }
 
+static inline void mptcp_subflow_free_ctx(struct mptcp_subflow_context *subflow)
+{
+	long old = set_mask_bits(&subflow->delegated_status, 0,
+				 BIT(MPTCP_DELEGATE_DEAD));
+
+	/* a scheduled subflow is owned by mptcp_napi_poll(), which will free it */
+	if (!(old & BIT(MPTCP_DELEGATE_SCHEDULED)))
+		kfree_rcu(subflow, rcu);
+}
+
 void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp);
 void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk);
 
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 6f07544bfe40..20d506235074 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -832,7 +832,7 @@ void mptcp_subflow_drop_ctx(struct sock *ssk)
 			sock_put(ctx->conn);
 	}
 
-	kfree_rcu(ctx, rcu);
+	mptcp_subflow_free_ctx(ctx);
 }
 
 void __mptcp_subflow_fully_established(struct mptcp_sock *msk,
@@ -2098,7 +2098,7 @@ static void subflow_ulp_release(struct sock *ssk)
 
 	mptcp_subflow_ops_undo_override(ssk);
 	if (release)
-		kfree_rcu(ctx, rcu);
+		mptcp_subflow_free_ctx(ctx);
 }
 
 static void subflow_ulp_clone(const struct request_sock *req,

-- 
2.55.0


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

* [PATCH net 05/10] mptcp: leave an orphan's DATA_FIN to the worker
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (3 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated list Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 06/10] mptcp: don't leak an orphan when the PM closes its last subflow Matthieu Baerts (NGI0)
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable

From: Chris Mason <mason@kernel.org>

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

Fixes: bc68b0efa1bf ("mptcp: move the whole rx path under msk socket lock protection")
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. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 23d35f43b566..17451240c105 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2312,9 +2312,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)

-- 
2.55.0


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

* [PATCH net 06/10] mptcp: don't leak an orphan when the PM closes its last subflow
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (4 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 05/10] mptcp: leave an orphan's DATA_FIN to the worker Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 07/10] net: add __sk_net_refcnt_upgrade() with a GFP mask Matthieu Baerts (NGI0)
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0), stable

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

Fixes: 27e5ccc2d5a5 ("mptcp: fix dangling connection hang-up")
Cc: stable@vger.kernel.org
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 17451240c105..5339fd6a8d81 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2744,8 +2744,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 {

-- 
2.55.0


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

* [PATCH net 07/10] net: add __sk_net_refcnt_upgrade() with a GFP mask
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (5 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 06/10] mptcp: don't leak an orphan when the PM closes its last subflow Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns Matthieu Baerts (NGI0)
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0), stable,
	Neal Cardwell, Kuniyuki Iwashima

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.

Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port")
Cc: stable@vger.kernel.org
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>
---
 include/net/sock.h | 1 +
 net/core/sock.c    | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 3144efad8c36..de23cdc89477 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1843,6 +1843,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);
diff --git a/net/core/sock.c b/net/core/sock.c
index 5675053625e6..5ed63d2d8976 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2422,7 +2422,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);
 
@@ -2430,9 +2430,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)

-- 
2.55.0


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

* [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (6 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 07/10] net: add __sk_net_refcnt_upgrade() with a GFP mask Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 19:00   ` Matthieu Baerts
  2026-11-23 13:24 ` [PATCH net 09/10] mptcp: initialize drop_req in subflow_init_req() Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener Matthieu Baerts (NGI0)
  9 siblings, 1 reply; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Josef Bacik, stable

From: Josef Bacik <josef@toxicpanda.com>

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

Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port")
Cc: stable@vger.kernel.org
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
[ 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. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/subflow.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 20d506235074..3e674c21bdb2 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -844,6 +844,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,
@@ -912,6 +928,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.
@@ -1860,8 +1881,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;

-- 
2.55.0


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

* [PATCH net 09/10] mptcp: initialize drop_req in subflow_init_req()
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (7 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  2026-11-23 13:24 ` [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener Matthieu Baerts (NGI0)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable

From: Chris Mason <mason@kernel.org>

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

Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
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. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/subflow.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 3e674c21bdb2..054ee992904e 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -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)

-- 
2.55.0


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

* [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener
  2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
                   ` (8 preceding siblings ...)
  2026-11-23 13:24 ` [PATCH net 09/10] mptcp: initialize drop_req in subflow_init_req() Matthieu Baerts (NGI0)
@ 2026-11-23 13:24 ` Matthieu Baerts (NGI0)
  9 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts (NGI0) @ 2026-11-23 13:24 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Mat Martineau, Geliang Tang,
	Christoph Paasch, Florian Westphal
  Cc: netdev, mptcp, Davide Caratti, Matthieu Baerts (NGI0),
	Chris Mason, stable, Neal Cardwell, Kuniyuki Iwashima,
	Martin KaFai Lau, Daniel Borkmann, Alexei Starovoitov,
	Martin KaFai Lau, bpf

From: Chris Mason <mason@kernel.org>

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. The connection then fails, instead of
corrupting the memory.

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

Fixes: e472f88891ab ("bpf: tcp: Support arbitrary SYN Cookie.")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ Shorter comment. Commit message: how the issue was found, its
  symptoms, and that the connection then fails. ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Martin KaFai Lau <martin.lau@kernel.org>
Cc: bpf@vger.kernel.org
---
 net/ipv4/syncookies.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 89169c82431c..f39600ee3f17 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -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;
 	}

-- 
2.55.0


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

* Re: [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns
  2026-11-23 13:24 ` [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns Matthieu Baerts (NGI0)
@ 2026-11-23 19:00   ` Matthieu Baerts
  0 siblings, 0 replies; 12+ messages in thread
From: Matthieu Baerts @ 2026-11-23 19:00 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman, Mat Martineau, Geliang Tang, Christoph Paasch,
	Florian Westphal, mptcp, Davide Caratti, Josef Bacik, stable,
	Eric Dumazet

Hello,

On 23/11/2026 14:24, Matthieu Baerts (NGI0) wrote:
> From: Josef Bacik <josef@toxicpanda.com>
> 
> 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
> 
> Fixes: 1729cf186d8a ("mptcp: create the listening socket for new port")
> Cc: stable@vger.kernel.org
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> [ 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. ]
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
>  net/mptcp/subflow.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
> index 20d506235074..3e674c21bdb2 100644
> --- a/net/mptcp/subflow.c
> +++ b/net/mptcp/subflow.c
> @@ -844,6 +844,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);

I just noticed put_net() is somehow deprecated (according to
netdev/deprecated_api test on PW). In net_namespace.h, above the
declaration of "put_net()", it says "Try using put_net_track() instead",
but I don't think it makes sense here: I would need to allocate a new
tracker here. Indeed, I cannot use child->ns_tracker (it belongs to the
reference __sk_net_refcnt_upgrade()) or NULL (no_tracker was never
incremented) from what I see.

If a new tracker is needed, it would be allocated before
__sk_net_refcnt_upgrade() and released just after. The fix here follows
what is done in rds_tcp_tune(), with the same sequence from 5c70eb5c593d
("net: better track kernel sockets lifetime").

So I think there is nothing to change here.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


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

end of thread, other threads:[~2026-11-23 19:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 13:24 [PATCH net 00/10] mptcp: misc fixes for v7.4-rc5 Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 01/10] tcp: drain the queues of a listen() that fails Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 02/10] mptcp: " Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6 listener Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 04/10] mptcp: fix use-after-free of the subflow context on the delegated list Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 05/10] mptcp: leave an orphan's DATA_FIN to the worker Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 06/10] mptcp: don't leak an orphan when the PM closes its last subflow Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 07/10] net: add __sk_net_refcnt_upgrade() with a GFP mask Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns Matthieu Baerts (NGI0)
2026-11-23 19:00   ` Matthieu Baerts
2026-11-23 13:24 ` [PATCH net 09/10] mptcp: initialize drop_req in subflow_init_req() Matthieu Baerts (NGI0)
2026-11-23 13:24 ` [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener 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