Skip to content

Commit b1d030f

Browse files
Colin Ian KingBoris Brezillon
authored andcommitted
mtd: sharpslpart: fix overflow on block_adr calculation
Multiplying block_num and mtd->erasesize may potentially overflow as they are both unsigned ints and so the multiplication is evaluated in unsigned int arithmetic. Cast block_adr to off_t to ensure multiplication is off_t sized to avoid any potential overflow. Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow") Signed-off-by: Colin Ian King <colin.king@canonical.com> Acked-by: Andrea Adami <andrea.adami@gmail.com> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
1 parent 9e343e8 commit b1d030f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/mtd/parsers/sharpslpart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int sharpsl_nand_init_ftl(struct mtd_info *mtd, struct sharpsl_ftl *ftl)
192192

193193
/* create physical-logical table */
194194
for (block_num = 0; block_num < phymax; block_num++) {
195-
block_adr = block_num * mtd->erasesize;
195+
block_adr = (loff_t)block_num * mtd->erasesize;
196196

197197
if (mtd_block_isbad(mtd, block_adr))
198198
continue;
@@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info *mtd,
244244
return -EINVAL;
245245

246246
block_num = ftl->log2phy[log_num];
247-
block_adr = block_num * mtd->erasesize;
247+
block_adr = (loff_t)block_num * mtd->erasesize;
248248
block_ofs = mtd_mod_by_eb((u32)from, mtd);
249249

250250
err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);

0 commit comments

Comments
 (0)