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]
Date:   Tue, 30 Mar 2021 09:05:15 -0700
From:   Dave Jiang <dave.jiang@...el.com>
To:     Lv Yunlong <lyl2019@...l.ustc.edu.cn>, vkoul@...nel.org
Cc:     dmaengine@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] dma: Fix a double free in dma_async_device_register


On 3/30/2021 2:01 AM, Lv Yunlong wrote:
> In the first list_for_each_entry() macro of dma_async_device_register,
> it gets the chan from list and calls __dma_async_device_channel_register
> (..,chan). We can see that chan->local is allocated by alloc_percpu() and
> it is freed chan->local by free_percpu(chan->local) when
> __dma_async_device_channel_register() failed.
>
> But after __dma_async_device_channel_register() failed, the caller will
> goto err_out and freed the chan->local in the second time by free_percpu().
>
> The cause of this problem is forget to set chan->local to NULL when
> chan->local was freed in __dma_async_device_channel_register(). My
> patch sets chan->local to NULL when the callee failed to avoid double free.

Thanks for the fix. I think it would make sense to set it to NULL in 
__dma_async_device_channel_register() cleanup path after it calls 
free_percpu(chan->local) right? That would address any other instances 
of this issue happening else where.


>
> Fixes: d2fb0a0438384 ("dmaengine: break out channel registration")
> Signed-off-by: Lv Yunlong <lyl2019@...l.ustc.edu.cn>
> ---
>   drivers/dma/dmaengine.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index fe6a460c4373..fef64b198c95 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1249,8 +1249,10 @@ int dma_async_device_register(struct dma_device *device)
>   	/* represent channels in sysfs. Probably want devs too */
>   	list_for_each_entry(chan, &device->channels, device_node) {
>   		rc = __dma_async_device_channel_register(device, chan);
> -		if (rc < 0)
> +		if (rc < 0) {
> +			chan->local = NULL;
>   			goto err_out;
> +		}
>   	}
>   
>   	mutex_lock(&dma_list_mutex);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ