Skip to content

Commit 09c2c35

Browse files
Mikulas Patockaaxboe
authored andcommitted
block: fix integer overflow in __blkdev_sectors_to_bio_pages()
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]>
1 parent dbec491 commit 09c2c35

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

block/blk-lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
269269
*/
270270
static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects)
271271
{
272-
sector_t bytes = (nr_sects << 9) + PAGE_SIZE - 1;
272+
sector_t pages = DIV_ROUND_UP_SECTOR_T(nr_sects, PAGE_SIZE / 512);
273273

274-
return min(bytes >> PAGE_SHIFT, (sector_t)BIO_MAX_PAGES);
274+
return min(pages, (sector_t)BIO_MAX_PAGES);
275275
}
276276

277277
/**

0 commit comments

Comments
 (0)