block: fix integer overflow in __blkdev_sectors_to_bio_pages()
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 11 Sep 2017 15:46:49 +0000 (09:46 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 Sep 2017 15:46:49 +0000 (09:46 -0600)
Fix possible integer overflow in __blkdev_sectors_to_bio_pages if
sector_t is 32-bit.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 615d22a51c04 ("block: Fix __blkdev_issue_zeroout loop")
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-lib.c

index e01adb5145b3a0e82e17aa3f72c58074c6a05893..62240f8832ca6e62f8f3e5dddedb9428a978250d 100644 (file)
@@ -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);
 }
 
 /**