From: John Garry <john.g.garry@oracle.com>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, martin.petersen@oracle.com,
hch@lst.de, hare@suse.de, bvanassche@acm.org, dlemoal@kernel.org,
John Garry <john.g.garry@oracle.com>
Subject: [PATCH v2 1/2] block: avoid possible overflow for chunk_sectors check in blk_stack_limits()
Date: Tue, 29 Jul 2025 09:14:47 +0000 [thread overview]
Message-ID: <20250729091448.1691334-2-john.g.garry@oracle.com> (raw)
In-Reply-To: <20250729091448.1691334-1-john.g.garry@oracle.com>
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
next prev parent reply other threads:[~2025-07-29 9:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 9:14 [PATCH v2 0/2] block: make some queue limits checks more robust John Garry
2025-07-29 9:14 ` John Garry [this message]
2025-07-29 11:05 ` [PATCH v2 1/2] block: avoid possible overflow for chunk_sectors check in blk_stack_limits() Damien Le Moal
2025-07-29 9:14 ` [PATCH v2 2/2] block: Enforce power-of-2 physical block size John Garry
2025-07-29 10:19 ` Hannes Reinecke
2025-07-29 11:03 ` Damien Le Moal
2025-07-29 12:27 ` [PATCH v2 0/2] block: make some queue limits checks more robust Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250729091448.1691334-2-john.g.garry@oracle.com \
--to=john.g.garry@oracle.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=dlemoal@kernel.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.