Skip to content

Commit

Permalink
mtd: sharpslpart: fix overflow on block_adr calculation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Colin Ian King authored and Boris Brezillon committed Dec 18, 2017
1 parent 9e343e8 commit b1d030f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/mtd/parsers/sharpslpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static int sharpsl_nand_init_ftl(struct mtd_info *mtd, struct sharpsl_ftl *ftl)

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

if (mtd_block_isbad(mtd, block_adr))
continue;
Expand Down Expand Up @@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info *mtd,
return -EINVAL;

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

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

0 comments on commit b1d030f

Please sign in to comment.