]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
null_blk: fix zone read length beyond write pointer
authorKeith Busch <kbusch@kernel.org>
Wed, 12 Nov 2025 16:42:18 +0000 (08:42 -0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 12 Nov 2025 17:02:56 +0000 (10:02 -0700)
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")
Signed-off-by: Keith Busch <kbusch@kernel.org>
Tested-by: Bart van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/null_blk/main.c
drivers/block/null_blk/zoned.c

index f1e67962ecaeb9afc408609de3c0932dad486cef..c7c0fb79a6bf6b695966e5a011441fbd3c93abe5 100644 (file)
@@ -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);
index dbf292a8eae96920ed6cae5eccadf8fba676bf99..0ada35dc0989e3ad29d67589d7f6f9533258351d 100644 (file)
@@ -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 ||