]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: avoid possible overflow for chunk_sectors check in blk_stack_limits()
authorJohn Garry <john.g.garry@oracle.com>
Tue, 29 Jul 2025 09:14:47 +0000 (09:14 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Aug 2025 16:41:32 +0000 (18:41 +0200)
[ 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 <hare@suse.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://lore.kernel.org/r/20250729091448.1691334-2-john.g.garry@oracle.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-settings.c

index 1a82980d52e93aae0ffd2103b84aa1a21f5d9115..44dabc636a592f1cf5ce791ac0df6c7b6d58afef 100644 (file)
@@ -792,7 +792,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->flags |= BLK_FLAG_MISALIGNED;
                ret = -1;