Skip to content

Commit 448dfec

Browse files
johnpgarryaxboe
authored andcommitted
block: avoid possible overflow for chunk_sectors check in blk_stack_limits()
In blk_stack_limits(), we check that the t->chunk_sectors value is a multiple of the t->physical_block_size value. However, by finding the chunk_sectors value in bytes, we may overflow the unsigned int which holds chunk_sectors, so change the check to be based on sectors. Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: John Garry <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 459779d commit 448dfec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

block/blk-settings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
857857
}
858858

859859
/* chunk_sectors a multiple of the physical block size? */
860-
if ((t->chunk_sectors << 9) & (t->physical_block_size - 1)) {
860+
if (t->chunk_sectors % (t->physical_block_size >> SECTOR_SHIFT)) {
861861
t->chunk_sectors = 0;
862862
t->flags |= BLK_FLAG_MISALIGNED;
863863
ret = -1;

0 commit comments

Comments
 (0)