[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1f55b71d-8e28-4eac-b14e-d32a7e704578@cestc.cn>
Date: Fri, 28 Mar 2025 16:51:23 +0800
From: Peijie Shao <shaopeijie@...tc.cn>
To: David Laight <david.laight.linux@...il.com>,
Keith Busch <kbusch@...nel.org>, Chaitanya Kulkarni <chaitanyak@...dia.com>
Cc: hch@....de, sagi@...mberg.me, kch@...dia.com,
linux-nvme@...ts.infradead.org, linux-kernel@...r.kernel.org,
zhang.guanghui@...tc.cn, gechangzhong@...tc.cn
Subject: Re: [PATCH] nvmet: Replace sock_create with sock_create_kern
On 3/25/2025 5:04 AM, David Laight wrote:
> On Mon, 24 Mar 2025 11:17:08 +0800
> shaopeijie@...tc.cn wrote:
>
>> From: Peijie Shao <shaopeijie@...tc.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@...tc.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.
Powered by blists - more mailing lists