From: John Garry Date: Tue, 29 Jul 2025 09:14:47 +0000 (+0000) Subject: block: avoid possible overflow for chunk_sectors check in blk_stack_limits() X-Git-Tag: v6.1.149~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31f2f080898e50cbf2bae62d35f9f2a997547b38;p=thirdparty%2Fkernel%2Fstable.git block: avoid possible overflow for chunk_sectors check in blk_stack_limits() [ Upstream commit 448dfecc7ff807822ecd47a5c052acedca7d09e8 ] 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 Reviewed-by: Martin K. Petersen Signed-off-by: John Garry Reviewed-by: Damien Le Moal Link: https://lore.kernel.org/r/20250729091448.1691334-2-john.g.garry@oracle.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- diff --git a/block/blk-settings.c b/block/blk-settings.c index c702f408bbc0a..305b47a38429e 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -628,7 +628,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, } /* chunk_sectors a multiple of the physical block size? */ - if ((t->chunk_sectors << 9) & (t->physical_block_size - 1)) { + if (t->chunk_sectors % (t->physical_block_size >> SECTOR_SHIFT)) { t->chunk_sectors = 0; t->misaligned = 1; ret = -1;