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@socionext.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
This commit is contained in:
Masahiro Yamada 2017-05-25 13:50:20 +09:00 committed by Boris Brezillon
parent 2165c4a1f7
commit 79e0348c4e
1 changed files with 5 additions and 0 deletions

View File

@ -4789,6 +4789,11 @@ int nand_scan_tail(struct mtd_info *mtd)
goto err_free; goto err_free;
} }
ecc->total = ecc->steps * ecc->bytes; 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 * The number of bytes available for a client to place data into