From: Christoph Hellwig <hch@lst.de>
To: shaopeijie@cestc.cn
Cc: kbusch@kernel.org, sagi@grimberg.me, axboe@kernel.dk, hch@lst.de,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
gechangzhong@cestc.cn, zhang.guanghui@cestc.cn
Subject: Re: [PATCH v2] nvme-tcp: Fix netns UAF introduced by commit 1be52169c348
Date: Fri, 4 Apr 2025 08:17:31 +0200 [thread overview]
Message-ID: <20250404061731.GA31237@lst.de> (raw)
In-Reply-To: <20250403144748.3399661-1-shaopeijie@cestc.cn>
I'll do another minor fixup for the comment formatting, but otherwise
this looks good. I'll queue it up.
On Thu, Apr 03, 2025 at 10:47:48PM +0800, shaopeijie@cestc.cn wrote:
> From: Peijie Shao <shaopeijie@cestc.cn>
>
> The patch is for nvme-tcp host side.
>
> commit 1be52169c348
> ("nvme-tcp: fix selinux denied when calling sock_sendmsg")
> uses sock_create_kern instead of sock_create to solve SELinux
> problem, however sock_create_kern does not take a reference of
> the given netns, which results in a use-after-free when the
> non-init_net netns is destroyed before sock_release.
>
> For example: a container not share with host's network namespace
> doing a 'nvme connect', and is stopped without 'nvme disconnect'.
>
> The patch changes parameter current->nsproxy->net_ns to init_net,
> makes the socket always belongs to the host. It also naturally
> avoids changing sock's netns from previous creator's netns to
> init_net when sock is re-created by nvme recovery path
> (workqueue is in init_net namespace).
>
> Signed-off-by: Peijie Shao <shaopeijie@cestc.cn>
> ---
>
> Changes in v2:
> 1. Fix style problems reviewed by Christoph Hellwig, thanks!
> 2. Add 'nvme-tcp:' prefix for the patch.
>
> Version v1:
> Hi all,
> This is the v1 patch. Before this version, I tried to
> get_net(current->nsproxy->net_ns) in nvme_tcp_alloc_queue() to
> fix the issue, but failed to find a suitable placeto do
> put_net(). Because the socket is released by fput() internally.
> I think code like below:
> nvme_tcp_free_queue() {
> fput()
> put_net()
> }
> can not ensure the socket was released before put_net, since
> someone is still holding the file.
>
> So I would like to use the 'init_net' net namespace.
>
> ---
> drivers/nvme/host/tcp.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index 26c459f0198d..9b1d0ad18b77 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -1789,8 +1789,14 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
> queue->cmnd_capsule_len = sizeof(struct nvme_command) +
> NVME_TCP_ADMIN_CCSZ;
>
> - ret = sock_create_kern(current->nsproxy->net_ns,
> - ctrl->addr.ss_family, SOCK_STREAM,
> + /*
> + * sock_create_kern() does not take a reference to
> + * current->nsproxy->net_ns, use init_net instead.
> + * This also avoid changing sock's netns from previous
> + * creator's netns to init_net when sock is re-created
> + * by nvme recovery path.
> + */
> + ret = sock_create_kern(&init_net, ctrl->addr.ss_family, SOCK_STREAM,
> IPPROTO_TCP, &queue->sock);
> if (ret) {
> dev_err(nctrl->device,
> --
> 2.43.0
>
>
---end quoted text---
next prev parent reply other threads:[~2025-04-04 6:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 3:17 [PATCH] nvmet: Replace sock_create with sock_create_kern shaopeijie
2025-03-24 21:04 ` David Laight
2025-03-28 8:51 ` Peijie Shao
2025-04-01 6:19 ` [PATCH] Fix netns UAF introduced by commit 1be52169c348 shaopeijie
2025-04-03 4:30 ` Christoph Hellwig
2025-04-03 4:30 ` Christoph Hellwig
2025-04-03 13:59 ` Peijie Shao
2025-04-03 14:47 ` [PATCH v2] nvme-tcp: " shaopeijie
2025-04-04 6:17 ` Christoph Hellwig [this message]
2025-04-07 14:31 ` Christoph Hellwig
2025-04-07 17:18 ` Kuniyuki Iwashima
2025-04-08 5:04 ` Christoph Hellwig
2025-04-08 5:55 ` Kuniyuki Iwashima
2025-04-08 5:58 ` Christoph Hellwig
2025-04-08 6:08 ` Kuniyuki Iwashima
2025-03-24 23:24 ` [PATCH] nvmet: Replace sock_create with sock_create_kern Chaitanya Kulkarni
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=20250404061731.GA31237@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=gechangzhong@cestc.cn \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=shaopeijie@cestc.cn \
--cc=zhang.guanghui@cestc.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.