mtd: nand: check ecc->total sanity in nand_scan_tail

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Thu Jul 13 10:59:16 PDT 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=79e0348c4e24fd1affdcf055e0269755580e0fcc
Commit:     79e0348c4e24fd1affdcf055e0269755580e0fcc
Parent:     2165c4a1f71a04c7ea6493f18740a3afd4e47e4f
Author:     Masahiro Yamada <yamada.masahiro at socionext.com>
AuthorDate: Thu May 25 13:50:20 2017 +0900
Committer:  Boris Brezillon <boris.brezillon at free-electrons.com>
CommitDate: Thu Jun 1 10:09:35 2017 +0200

    mtd: nand: check ecc->total sanity in nand_scan_tail
    
    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 at socionext.com>
    Signed-off-by: Boris Brezillon <boris.brezillon at free-electrons.com>
---
 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 58a97e3..2404bb0 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -4789,6 +4789,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



More information about the linux-mtd-cvs mailing list