2016-04-04 20:58:44

by Han Xu

[permalink] [raw]
Subject: [PATCH] mtd: gpmi: fix raw_buffer pointer double free issue

fix the raw_buffer pointer double free issue found by coverify.

CID 18344 (#2 of 2): Double free (USE_AFTER_FREE)
3. double_free: Calling gpmi_alloc_dma_buffer frees pointer
this->raw_buffer which has already been freed

Signed-off-by: Han Xu <[email protected]>
---

changes in v2:
- add coverity check log
---
drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 8122c69..dcb60b0 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -797,6 +797,7 @@ static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)

this->cmd_buffer = NULL;
this->data_buffer_dma = NULL;
+ this->raw_buffer = NULL;
this->page_buffer_virt = NULL;
this->page_buffer_size = 0;
}
--
1.9.1


2016-04-04 21:31:24

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH] mtd: gpmi: fix raw_buffer pointer double free issue

Am 04.04.2016 um 22:41 schrieb Han Xu:
> fix the raw_buffer pointer double free issue found by coverify.
>
> CID 18344 (#2 of 2): Double free (USE_AFTER_FREE)
> 3. double_free: Calling gpmi_alloc_dma_buffer frees pointer
> this->raw_buffer which has already been freed
>
> Signed-off-by: Han Xu <[email protected]>
> ---
>
> changes in v2:
> - add coverity check log
> ---
> drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> index 8122c69..dcb60b0 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> @@ -797,6 +797,7 @@ static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
>
> this->cmd_buffer = NULL;
> this->data_buffer_dma = NULL;
> + this->raw_buffer = NULL;
> this->page_buffer_virt = NULL;
> this->page_buffer_size = 0;

Reviewed-by: Richard Weinberger <[email protected]>

Aside of that, the driver should IMHO be fixed to not call
gpmi_free_dma_buffer() multiple times on the same buffer...

Thanks,
//richard

2016-04-05 15:43:49

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH] mtd: gpmi: fix raw_buffer pointer double free issue

On Mon, 4 Apr 2016 15:41:29 -0500
Han Xu <[email protected]> wrote:

> fix the raw_buffer pointer double free issue found by coverify.
>
> CID 18344 (#2 of 2): Double free (USE_AFTER_FREE)
> 3. double_free: Calling gpmi_alloc_dma_buffer frees pointer
> this->raw_buffer which has already been freed
>
> Signed-off-by: Han Xu <[email protected]>

Applied.

Thanks,

Boris

> ---
>
> changes in v2:
> - add coverity check log
> ---
> drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> index 8122c69..dcb60b0 100644
> --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
> @@ -797,6 +797,7 @@ static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
>
> this->cmd_buffer = NULL;
> this->data_buffer_dma = NULL;
> + this->raw_buffer = NULL;
> this->page_buffer_virt = NULL;
> this->page_buffer_size = 0;
> }



--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com