2017-09-27 12:49:23

by Richard Genoud

[permalink] [raw]
Subject: [PATCH] mtd: nand: atmel: fix buffer overflow in atmel_pmecc_user

When calculating the size needed by struct atmel_pmecc_user *user,
the dmu and delta buffer sizes were forgotten.
This lead to a memory corruption (especially with a large ecc_strength).

Link: http://lkml.kernel.org/r/[email protected]
Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
Cc: Nicolas Ferre <[email protected]>
Cc: [email protected]
Reported-by: Richard Genoud <[email protected]>
Pointed-at-by: Boris Brezillon <[email protected]>
Signed-off-by: Richard Genoud <[email protected]>
---
drivers/mtd/nand/atmel/pmecc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
index 146af8218314..8268636675ef 100644
--- a/drivers/mtd/nand/atmel/pmecc.c
+++ b/drivers/mtd/nand/atmel/pmecc.c
@@ -363,7 +363,7 @@ atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
size += (req->ecc.strength + 1) * sizeof(u16);
/* Reserve space for mu, dmu and delta. */
size = ALIGN(size, sizeof(s32));
- size += (req->ecc.strength + 1) * sizeof(s32);
+ size += (req->ecc.strength + 1) * sizeof(s32) * 3;

user = kzalloc(size, GFP_KERNEL);
if (!user)


2017-09-27 15:31:11

by Nicolas Ferre

[permalink] [raw]
Subject: Re: [PATCH] mtd: nand: atmel: fix buffer overflow in atmel_pmecc_user

On 27/09/2017 at 14:49, Richard Genoud wrote:
> When calculating the size needed by struct atmel_pmecc_user *user,
> the dmu and delta buffer sizes were forgotten.
> This lead to a memory corruption (especially with a large ecc_strength).
>
> Link: http://lkml.kernel.org/r/[email protected]
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Cc: Nicolas Ferre <[email protected]>

Yes:
Reviewed-by: Nicolas Ferre <[email protected]>
Thanks Richard and Boris for this quick fix!

Regards,
Nicolas

> Cc: [email protected]
> Reported-by: Richard Genoud <[email protected]>
> Pointed-at-by: Boris Brezillon <[email protected]>
> Signed-off-by: Richard Genoud <[email protected]>
> ---
> drivers/mtd/nand/atmel/pmecc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
> index 146af8218314..8268636675ef 100644
> --- a/drivers/mtd/nand/atmel/pmecc.c
> +++ b/drivers/mtd/nand/atmel/pmecc.c
> @@ -363,7 +363,7 @@ atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
> size += (req->ecc.strength + 1) * sizeof(u16);
> /* Reserve space for mu, dmu and delta. */
> size = ALIGN(size, sizeof(s32));
> - size += (req->ecc.strength + 1) * sizeof(s32);
> + size += (req->ecc.strength + 1) * sizeof(s32) * 3;
>
> user = kzalloc(size, GFP_KERNEL);
> if (!user)
>


--
Nicolas Ferre

2017-09-28 09:46:26

by Boris Brezillon

[permalink] [raw]
Subject: Re: [PATCH] mtd: nand: atmel: fix buffer overflow in atmel_pmecc_user

On Wed, 27 Sep 2017 14:49:17 +0200
Richard Genoud <[email protected]> wrote:

> When calculating the size needed by struct atmel_pmecc_user *user,
> the dmu and delta buffer sizes were forgotten.
> This lead to a memory corruption (especially with a large ecc_strength).
>
> Link: http://lkml.kernel.org/r/[email protected]
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Cc: Nicolas Ferre <[email protected]>
> Cc: [email protected]
> Reported-by: Richard Genoud <[email protected]>
> Pointed-at-by: Boris Brezillon <[email protected]>
> Signed-off-by: Richard Genoud <[email protected]>

Applied.

Thanks,

Boris

> ---
> drivers/mtd/nand/atmel/pmecc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
> index 146af8218314..8268636675ef 100644
> --- a/drivers/mtd/nand/atmel/pmecc.c
> +++ b/drivers/mtd/nand/atmel/pmecc.c
> @@ -363,7 +363,7 @@ atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
> size += (req->ecc.strength + 1) * sizeof(u16);
> /* Reserve space for mu, dmu and delta. */
> size = ALIGN(size, sizeof(s32));
> - size += (req->ecc.strength + 1) * sizeof(s32);
> + size += (req->ecc.strength + 1) * sizeof(s32) * 3;
>
> user = kzalloc(size, GFP_KERNEL);
> if (!user)
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/