All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>
Subject: [PATCH v7 07/16] block: improve blkdev_get_zone_info()
Date: Tue,  8 Sep 2026 17:57:36 +0900	[thread overview]
Message-ID: <20260908085745.1082697-8-dlemoal@kernel.org> (raw)
In-Reply-To: <20260908085745.1082697-1-dlemoal@kernel.org>

Add a zone state array bound check to ensure that like
disk_zone_get_state(), we never attempt to access the zone state array
beyond its size.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 block/blk-zoned.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 14c88d11f243..93d862d44e7c 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1025,6 +1025,7 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
 {
 	struct gendisk *disk = bdev->bd_disk;
 	sector_t zone_sectors = bdev_zone_sectors(bdev);
+	unsigned int zno = disk_zone_no(disk, sector);
 	struct blk_zone_wplug *zwplug;
 	unsigned long flags;
 	u8 *zones_state, zs;
@@ -1032,23 +1033,23 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
 	if (!bdev_is_zoned(bdev))
 		return -EOPNOTSUPP;
 
-	if (sector >= get_capacity(disk))
+	if (sector >= get_capacity(disk) || zno >= disk->nr_zones)
 		return -EINVAL;
 
 	memset(zone, 0, sizeof(*zone));
 	sector = bdev_zone_start(bdev, sector);
 
 	if (!blkdev_has_cached_report_zones(bdev))
-		return blkdev_report_zone_fallback(bdev, sector, zone);
+		goto fallback;
 
 	rcu_read_lock();
 	zones_state = rcu_dereference(disk->zones_state);
 	if (!disk->zone_wplugs_hash || !zones_state) {
 		rcu_read_unlock();
-		return blkdev_report_zone_fallback(bdev, sector, zone);
+		goto fallback;
 	}
 
-	zs = zones_state[disk_zone_no(disk, sector)];
+	zs = zones_state[zno];
 	zone->cond = blk_zstate_to_zone_cond(zs);
 	if (blk_zstate_is_conv(zs))
 		zone->type = BLK_ZONE_TYPE_CONVENTIONAL;
@@ -1113,6 +1114,9 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
 	disk_put_zone_wplug(zwplug);
 
 	return 0;
+
+fallback:
+	return blkdev_report_zone_fallback(bdev, sector, zone);
 }
 EXPORT_SYMBOL_GPL(blkdev_get_zone_info);
 
-- 
2.55.0


  parent reply	other threads:[~2026-09-08  8:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  8:57 [PATCH v7 00/16] Improve handling of offline and read-only zones Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 01/16] block: remove disk_free_zone_resources() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 02/16] block: improve capacity handling during zone revalidation Damien Le Moal
2026-09-09  8:51   ` Hannes Reinecke
2026-09-10  5:20   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 03/16] block: refactor disk_revalidate_zone_resources() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 04/16] block: refactor disk_update_zone_resources() Damien Le Moal
2026-09-09  9:09   ` Hannes Reinecke
2026-09-10  5:20   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 05/16] block: remember a zone type regardless of its condition Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 06/16] block: refactor bdev_zone_is_seq() Damien Le Moal
2026-09-08  8:57 ` Damien Le Moal [this message]
2026-09-09  9:11   ` [PATCH v7 07/16] block: improve blkdev_get_zone_info() Hannes Reinecke
2026-09-10  5:21   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 08/16] block: introduce disk_for_all_zone_wplugs() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 09/16] block: serialize zone revalidation Damien Le Moal
2026-09-09  9:20   ` Hannes Reinecke
2026-09-10  5:21   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 10/16] block: drop all zone write plugs on capacity changes Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 11/16] block: retry zone revalidation on capacity change Damien Le Moal
2026-09-09  9:26   ` Hannes Reinecke
2026-09-10  5:24   ` Christoph Hellwig
2026-09-10  5:26     ` Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 12/16] block: propagate readonly and offline conditions to zone write plugs Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 13/16] block: always treat offline and read-only zones as dead Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 14/16] block: fail zone management operations to read-only and offline zones Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 15/16] block: allow read-only and offline conventional zones Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 16/16] block: simplify disk_zone_set_cond() Damien Le Moal

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=20260908085745.1082697-8-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /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.