Skip to content

Commit

Permalink
block: fix integer overflow in __blkdev_sectors_to_bio_pages()
Browse files Browse the repository at this point in the history
Fix possible integer overflow in __blkdev_sectors_to_bio_pages if
sector_t is 32-bit.

Signed-off-by: Mikulas Patocka <[email protected]>
Fixes: 615d22a ("block: Fix __blkdev_issue_zeroout loop")
Reviewed-by: Damien Le Moal <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Mikulas Patocka authored and axboe committed Sep 11, 2017
1 parent dbec491 commit 09c2c35
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions block/blk-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
*/
static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects)
{
sector_t bytes = (nr_sects << 9) + PAGE_SIZE - 1;
sector_t pages = DIV_ROUND_UP_SECTOR_T(nr_sects, PAGE_SIZE / 512);

return min(bytes >> PAGE_SHIFT, (sector_t)BIO_MAX_PAGES);
return min(pages, (sector_t)BIO_MAX_PAGES);
}

/**
Expand Down

0 comments on commit 09c2c35

Please sign in to comment.