From: Matthieu Baerts <matttbe@kernel.org>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Mat Martineau <martineau@kernel.org>,
Geliang Tang <geliang@kernel.org>,
Christoph Paasch <cpaasch@openai.com>,
Florian Westphal <fw@strlen.de>,
mptcp@lists.linux.dev, Davide Caratti <dcaratti@redhat.com>,
Josef Bacik <josef@toxicpanda.com>,
stable@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>
Subject: Re: [PATCH net 08/10] mptcp: pm: don't let listeners pin their netns
Date: Mon, 23 Nov 2026 20:00:48 +0100 [thread overview]
Message-ID: <fbddbdbd-4052-4753-89ee-cc75198b9842@kernel.org> (raw)
In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-8-278042217e8d@kernel.org>
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.
next prev parent reply other threads:[~2026-11-23 19:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fbddbdbd-4052-4753-89ee-cc75198b9842@kernel.org \
--to=matttbe@kernel.org \
--cc=cpaasch@openai.com \
--cc=davem@davemloft.net \
--cc=dcaratti@redhat.com \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=geliang@kernel.org \
--cc=horms@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=martineau@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox