Thread (7 messages) 7 messages, 4 authors, 2025-07-29
STALE360d LANDED: 4 (4M)
Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 1/2] block: avoid possible overflow for chunk_sectors check in blk_stack_limits()

From: John Garry <john.g.garry@oracle.com>
Date: 2025-07-29 09:15:33
Subsystem: block layer, the rest · Maintainers: Jens Axboe, Linus Torvalds

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>
---
 block/blk-settings.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index a6ac293f47e34..fa53a330f9b99 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -795,7 +795,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;
-- 
2.43.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help