lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <47669fb6-3700-e327-11af-93a92b0984a0@huaweicloud.com>
Date:   Thu, 28 Sep 2023 14:03:28 +0800
From:   Yu Kuai <yukuai1@...weicloud.com>
To:     Ming Lei <ming.lei@...hat.com>, linan666@...weicloud.com
Cc:     josef@...icpanda.com, axboe@...nel.dk, linux-block@...r.kernel.org,
        nbd@...er.debian.org, linux-kernel@...r.kernel.org,
        linan122@...wei.com, yi.zhang@...wei.com, houtao1@...wei.com,
        yangerkun@...wei.com, "yukuai (C)" <yukuai3@...wei.com>
Subject: Re: [PATCH] nbd: pass nbd_sock to nbd_read_reply() instead of index

Hi,

在 2023/09/28 12:05, Ming Lei 写道:
> On Mon, Sep 11, 2023 at 10:33:08AM +0800, linan666@...weicloud.com wrote:
>> From: Li Nan <linan122@...wei.com>
>>
>> If a socket is processing ioctl 'NBD_SET_SOCK', config->socks might be
>> krealloc in nbd_add_socket(), and a garbage request is received now, a UAF
>> may occurs.
>>
>>    T1
>>    nbd_ioctl
>>     __nbd_ioctl
>>      nbd_add_socket
>>       blk_mq_freeze_queue
>> 				T2
>>    				recv_work
>>    				 nbd_read_reply
>>    				  sock_xmit
>>       krealloc config->socks
>> 				   def config->socks
>>
>> Pass nbd_sock to nbd_read_reply(). And introduce a new function
>> sock_xmit_recv(), which differs from sock_xmit only in the way it get
>> socket.
>>
> 
> I am wondering why not grab queue usage counter before calling nbd_read_reply()
> for avoiding such issue, something like the following change:
> 
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index df1cd0f718b8..09215b605b12 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -837,9 +837,6 @@ static void recv_work(struct work_struct *work)
>   	while (1) {
>   		struct nbd_reply reply;
>   
> -		if (nbd_read_reply(nbd, args->index, &reply))
> -			break;
> -
>   		/*
>   		 * Grab .q_usage_counter so request pool won't go away, then no
>   		 * request use-after-free is possible during nbd_handle_reply().
> @@ -852,6 +849,9 @@ static void recv_work(struct work_struct *work)
>   			break;
>   		}
>   

This break how nbd works, if there is no reply yet, recv_work() will
wait for reply in:

nbd_read_reply
  sock_xmit
   sock_recvmsg

After this change, recv_work() will just return if there is no io.

Thanks,
Kuai

> +		if (nbd_read_reply(nbd, args->index, &reply))
> +			break;
> +
>   		cmd = nbd_handle_reply(nbd, args->index, &reply);
>   		if (IS_ERR(cmd)) {
>   			percpu_ref_put(&q->q_usage_counter);
> 
> Thanks,
> Ming
> 
> .
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ