Skip to content

Commit 9358bdb

Browse files
Ivan Stepchenkomiquelraynal
authored andcommitted
mtd: fix possible integer overflow in erase_xfer()
The expression '1 << EraseUnitSize' is evaluated in int, which causes a negative result when shifting by 31 - the upper bound of the valid range [10, 31], enforced by scan_header(). This leads to incorrect extension when storing the result in 'erase->len' (uint64_t), producing a large unexpected value. Found by Linux Verification Center (linuxtesting.org) with Svace. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Ivan Stepchenko <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent d22d5f4 commit 9358bdb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/mtd/ftl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static int erase_xfer(partition_t *part,
344344
return -ENOMEM;
345345

346346
erase->addr = xfer->Offset;
347-
erase->len = 1 << part->header.EraseUnitSize;
347+
erase->len = 1ULL << part->header.EraseUnitSize;
348348

349349
ret = mtd_erase(part->mbd.mtd, erase);
350350
if (!ret) {

0 commit comments

Comments
 (0)