dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Lv Yunlong <lyl2019@mail.ustc.edu.cn>, vkoul@kernel.org
Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma: Fix a double free in dma_async_device_register
Date: Tue, 30 Mar 2021 09:05:15 -0700	[thread overview]
Message-ID: <f4ce9e2a-6bb9-d3ae-3583-2d29e09aa3a3@intel.com> (raw)
In-Reply-To: <20210330090149.13476-1-lyl2019@mail.ustc.edu.cn>


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@mail.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);

  reply	other threads:[~2021-03-30 16:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30  9:01 [PATCH] dma: Fix a double free in dma_async_device_register Lv Yunlong
2021-03-30 16:05 ` Dave Jiang [this message]
2021-03-31  1:46   ` lyl2019
  -- strict thread matches above, loose matches on Subject: below --
2021-03-22 13:08 Lv Yunlong

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=f4ce9e2a-6bb9-d3ae-3583-2d29e09aa3a3@intel.com \
    --to=dave.jiang@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyl2019@mail.ustc.edu.cn \
    --cc=vkoul@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).