Skip to contentSkip to conversation

null_blk: fix zone read length beyond write pointer

PATCH Applied Keith Busch 5 participants 5 messages Nov 12, 2025 – Nov 13, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 null_blk: fix zone read length beyond write pointer

From: Keith Busch <[email protected]>

Fix up the divisor calculating the number of zone sectors being read and handle a read that straddles the zone write pointer. The length is rounded up a sector boundary, so be sure to truncate any excess bytes off to avoid copying past the data segment.

Fixes 3451cf34f51bb70 ("null_blk: allow byte aligned memory offsets")
---
 drivers/block/null_blk/main.c  | 5 ++++-
 drivers/block/null_blk/zoned.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/block/null_blk/main.c +4 -1
index f1e67962ecaeb..c7c0fb79a6bf6 100644
@@ -1240,9 +1240,12 @@ static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
 
 	p = kmap_local_page(page) + off;
 	if (!is_write) {
-		if (dev->zoned)
+		if (dev->zoned) {
 			valid_len = null_zone_valid_read_len(nullb,
 				pos >> SECTOR_SHIFT, len);
+			if (valid_len && valid_len != len)
+				valid_len -= pos & (SECTOR_SIZE - 1);
+		}
 
 		if (valid_len) {
 			copy_from_nullb(nullb, p, pos, valid_len);
drivers/block/null_blk/zoned.c +1 -1
index dbf292a8eae96..0ada35dc0989e 100644
@@ -242,7 +242,7 @@ size_t null_zone_valid_read_len(struct nullb *nullb,
 {
 	struct nullb_device *dev = nullb->dev;
 	struct nullb_zone *zone = &dev->zones[null_zone_no(dev, sector)];
-	unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SHIFT);
+	unsigned int nr_sectors = DIV_ROUND_UP(len, SECTOR_SIZE);
 
 	/* Read must be below the write pointer position */
 	if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL ||
Signature · 1 line
2.47.3
Tested-by on v1 1/1
#1 lore raw
Quoted 4 lines · Keith Busch

Fix up the divisor calculating the number of zone sectors being read and handle a read that straddles the zone write pointer. The length is rounded up a sector boundary, so be sure to truncate any excess bytes off to avoid copying past the data segment.

maintainer Applied
#2 lore raw
In reply to Keith Busch
Quoted 6 lines · Keith Busch

Fix up the divisor calculating the number of zone sectors being read and handle a read that straddles the zone write pointer. The length is rounded up a sector boundary, so be sure to truncate any excess bytes off to avoid copying past the data segment.

Applied, thanks!

[1/1] null_blk: fix zone read length beyond write pointer

      commit: 3749ea4deeba6049ea97e653d964568a45543e37

Best regards,

Signature · 1 line
Jens Axboe
Reviewed-by on v1 1/1
#3 lore raw
In reply to Keith Busch
Quoted 9 lines · Keith Busch

From: Keith Busch<[email protected]>

Fix up the divisor calculating the number of zone sectors being read and handle a read that straddles the zone write pointer. The length is rounded up a sector boundary, so be sure to truncate any excess bytes off to avoid copying past the data segment.

Fixes 3451cf34f51bb70 ("null_blk: allow byte aligned memory offsets")

Looks good.

-ck

Reviewed-by on v1 1/1
#4 lore raw
In reply to Keith Busch
Quoted 9 lines · Keith Busch

From: Keith Busch <[email protected]>

Fix up the divisor calculating the number of zone sectors being read and handle a read that straddles the zone write pointer. The length is rounded up a sector boundary, so be sure to truncate any excess bytes off to avoid copying past the data segment.

Fixes 3451cf34f51bb70 ("null_blk: allow byte aligned memory offsets")
Signature · 2 lines
Damien Le Moal
Western Digital Research