Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1650173 > unrolled thread

[PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail

Started byMasahiro Yamada <yamada.masahiro@socionext.com>
First post2017-05-25 07:00 +0200
Last post2017-05-29 20:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-05-25 07:00 +0200
    Re: [PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail Boris Brezillon <boris.brezillon@free-electrons.com> - 2017-05-29 20:50 +0200

#1650173 — [PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2017-05-25 07:00 +0200
Subject[PATCH] mtd: nand: check ecc->total sanity in nand_scan_tail
Message-ID<tKT2p-3wg-1@gated-at.bofh.it>
Drivers are supposed to set correct ecc->{size,strength,bytes} before
calling nand_scan_tail(), but it does not complain about ecc->total
bigger than oobsize.

In this case, chip->scan_bbt() crashes due to memory corruption, but
it is hard to debug.  It would be kind to fail it earlier with a clear
message.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

I was actually hit by this case.

I wasted half a day until I figured out my coding mistake in my
Denali driver.  It will be helpful to check this in NAND core.


 drivers/mtd/nand/nand_base.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index f4d686192717..14d6a5aa3ee8 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4970,6 +4970,11 @@ int nand_scan_tail(struct mtd_info *mtd)
 		goto err_free;
 	}
 	ecc->total = ecc->steps * ecc->bytes;
+	if (ecc->total > mtd->oobsize) {
+		WARN(1, "Total number of ECC bytes exceeded oobsize\n");
+		ret = -EINVAL;
+		goto err_free;
+	}
 
 	/*
 	 * The number of bytes available for a client to place data into
-- 
2.7.4

[toc] | [next] | [standalone]


#1652685

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2017-05-29 20:50 +0200
Message-ID<tMxTP-3Uk-3@gated-at.bofh.it>
In reply to#1650173
On Thu, 25 May 2017 13:50:20 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> Drivers are supposed to set correct ecc->{size,strength,bytes} before
> calling nand_scan_tail(), but it does not complain about ecc->total
> bigger than oobsize.
> 
> In this case, chip->scan_bbt() crashes due to memory corruption, but
> it is hard to debug.  It would be kind to fail it earlier with a clear
> message.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


Applied to nand/next.

Thanks,

Boris

> ---
> 
> I was actually hit by this case.
> 
> I wasted half a day until I figured out my coding mistake in my
> Denali driver.  It will be helpful to check this in NAND core.
> 
> 
>  drivers/mtd/nand/nand_base.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index f4d686192717..14d6a5aa3ee8 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -4970,6 +4970,11 @@ int nand_scan_tail(struct mtd_info *mtd)
>  		goto err_free;
>  	}
>  	ecc->total = ecc->steps * ecc->bytes;
> +	if (ecc->total > mtd->oobsize) {
> +		WARN(1, "Total number of ECC bytes exceeded oobsize\n");
> +		ret = -EINVAL;
> +		goto err_free;
> +	}
>  
>  	/*
>  	 * The number of bytes available for a client to place data into

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web