Skip to content

Commit b8f3911

Browse files
author
Boris Brezillon
committed
mtd: spi-nor: Check consistency of the memory size extracted from the SFDP
One field of the flash parameter table contains information about the flash device size. Most of the time the data extracted from this field is valid, but sometimes the BFPT section of the SFDP table is corrupted or invalid and this field is set to 0xffffffff, thus resulting in an integer overflow when setting params->size. Since NOR devices are anayway always smaller than 2^64 bytes, we can easily stop the BFPT parsing if the size reported in this table is invalid. Fixes: f384b35 ("mtd: spi-nor: parse Serial Flash Discoverable Parameters (SFDP) tables") Reported-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Boris Brezillon <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Acked-by: Cyrille Pitchen <[email protected]>
1 parent 2bd6bf0 commit b8f3911

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/mtd/spi-nor/spi-nor.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,15 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
21272127
params->size = bfpt.dwords[BFPT_DWORD(2)];
21282128
if (params->size & BIT(31)) {
21292129
params->size &= ~BIT(31);
2130+
2131+
/*
2132+
* Prevent overflows on params->size. Anyway, a NOR of 2^64
2133+
* bits is unlikely to exist so this error probably means
2134+
* the BFPT we are reading is corrupted/wrong.
2135+
*/
2136+
if (params->size > 63)
2137+
return -EINVAL;
2138+
21302139
params->size = 1ULL << params->size;
21312140
} else {
21322141
params->size++;

0 commit comments

Comments
 (0)