]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
mtd: nand: check ecc->total sanity in nand_scan_tail
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Thu, 25 May 2017 04:50:20 +0000 (13:50 +0900)
committerBoris Brezillon <boris.brezillon@free-electrons.com>
Thu, 1 Jun 2017 08:09:35 +0000 (10:09 +0200)
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>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
drivers/mtd/nand/nand_base.c

index 58a97e30b3f4ebc48658535499ecb69e4098f9b2..2404bb046b69aa1dee9bd3e1aa259109723b5ab9 100644 (file)
@@ -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