From: Peijie Shao <shaopeijie@cestc.cn>
To: David Laight <david.laight.linux@gmail.com>,
Keith Busch <kbusch@kernel.org>,
Chaitanya Kulkarni <chaitanyak@nvidia.com>
Cc: hch@lst.de, sagi@grimberg.me, kch@nvidia.com,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
zhang.guanghui@cestc.cn, gechangzhong@cestc.cn
Subject: Re: [PATCH] nvmet: Replace sock_create with sock_create_kern
Date: Fri, 28 Mar 2025 16:51:23 +0800 [thread overview]
Message-ID: <1f55b71d-8e28-4eac-b14e-d32a7e704578@cestc.cn> (raw)
In-Reply-To: <20250324210421.526c1729@pumpkin>
On 3/25/2025 5:04 AM, David Laight wrote:
> On Mon, 24 Mar 2025 11:17:08 +0800
> shaopeijie@cestc.cn wrote:
>
>> From: Peijie Shao <shaopeijie@cestc.cn>
>>
>> Replacing sock_create() with sock_create_kern()
>> changes the socket object's label to kernel_t,
>> thereby bypassing unnecessary SELinux permission
>> checks. It also helps to avoid copy and paste bugs.
>
> Does sock_create_kern() hold a reference on the namespace?
> It hadn't used to and sock_create() will take one.
>
> David
>
>>
>> Signed-off-by: Peijie Shao <shaopeijie@cestc.cn>
>> ---
>> drivers/nvme/target/tcp.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
>> index 4f9cac8a5abe..216afacc8179 100644
>> --- a/drivers/nvme/target/tcp.c
>> +++ b/drivers/nvme/target/tcp.c
>> @@ -2049,7 +2049,8 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)
>> if (port->nport->inline_data_size < 0)
>> port->nport->inline_data_size = NVMET_TCP_DEF_INLINE_DATA_SIZE;
>>
>> - ret = sock_create(port->addr.ss_family, SOCK_STREAM,
>> + ret = sock_create_kern(current->nsproxy->net_ns,
>> + port->addr.ss_family, SOCK_STREAM,
>> IPPROTO_TCP, &port->sock);
>> if (ret) {
>> pr_err("failed to create a socket\n");
>
>
>
Thanks for reviewing. Indeed, there is a netns UAF issue. The call path
sock_create() -> __sock_create() -> inet_create() -> sk_alloc() takes a
reference of the given netns, however sock_create_kern() doesn't perform
this step.
Sorroy the patch for the host side '[PATCH] nvme-tcp: fix selinux denied
when calling sock_sendmsg' has the same problem.
I will send a v2 patch to fix both host and target side soon, thanks.
next prev parent reply other threads:[~2025-03-28 8:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 3:17 shaopeijie
2025-03-24 21:04 ` David Laight
2025-03-28 8:51 ` Peijie Shao [this message]
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
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=1f55b71d-8e28-4eac-b14e-d32a7e704578@cestc.cn \
--to=shaopeijie@cestc.cn \
--cc=chaitanyak@nvidia.com \
--cc=david.laight.linux@gmail.com \
--cc=gechangzhong@cestc.cn \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®