All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gustavo Pimentel <Gustavo.Pimentel@synopsys.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	"dmaengine@vger.kernel.org" <dmaengine@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: RE: [PATCH] dmaengine: dw-edma: Fix use after free in dw_edma_alloc_chunk()
Date: Wed, 16 Dec 2020 17:13:55 +0000	[thread overview]
Message-ID: <DM5PR12MB1835E4CC6D248D2FF0C48182DAC50@DM5PR12MB1835.namprd12.prod.outlook.com> (raw)
In-Reply-To: <X9dTBFrUPEvvW7qc@mwanda>

On Mon, Dec 14, 2020 at 11:56:52, Dan Carpenter 
<dan.carpenter@oracle.com> wrote:

> If the dw_edma_alloc_burst() function fails then we free "chunk" but
> it's still on the "desc->chunk->list" list so it will lead to a use
> after free.  Also the "->chunks_alloc" count is incremented when it
> shouldn't be.
> 
> In current kernels small allocations are guaranteed to succeed and
> dw_edma_alloc_burst() can't fail so this will not actually affect
> runtime.
> 
> Fixes: e63d79d1ffcd ("dmaengine: Add Synopsys eDMA IP core driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Based on static analysis.  Not tested.
> 
>  drivers/dma/dw-edma/dw-edma-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c
> index b971505b8715..08d71dafa001 100644
> --- a/drivers/dma/dw-edma/dw-edma-core.c
> +++ b/drivers/dma/dw-edma/dw-edma-core.c
> @@ -86,12 +86,12 @@ static struct dw_edma_chunk *dw_edma_alloc_chunk(struct dw_edma_desc *desc)
>  
>  	if (desc->chunk) {
>  		/* Create and add new element into the linked list */
> -		desc->chunks_alloc++;
> -		list_add_tail(&chunk->list, &desc->chunk->list);
>  		if (!dw_edma_alloc_burst(chunk)) {
>  			kfree(chunk);
>  			return NULL;
>  		}
> +		desc->chunks_alloc++;
> +		list_add_tail(&chunk->list, &desc->chunk->list);
>  	} else {
>  		/* List head */
>  		chunk->burst = NULL;
> -- 
> 2.29.2

Thanks for the fix! Nicely catch!

Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>



  reply	other threads:[~2020-12-16 17:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 11:56 [PATCH] dmaengine: dw-edma: Fix use after free in dw_edma_alloc_chunk() Dan Carpenter
2020-12-14 11:56 ` Dan Carpenter
2020-12-16 17:13 ` Gustavo Pimentel [this message]
2020-12-21 16:22 ` Vinod Koul
2020-12-21 16:34   ` Vinod Koul

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=DM5PR12MB1835E4CC6D248D2FF0C48182DAC50@DM5PR12MB1835.namprd12.prod.outlook.com \
    --to=gustavo.pimentel@synopsys.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.