]> www.infradead.org Git - users/hch/misc.git/commitdiff
block: fix EOD return for device with nr_sectors == 0
authorJens Axboe <axboe@kernel.dk>
Mon, 22 Sep 2025 11:55:41 +0000 (05:55 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 22 Sep 2025 15:35:24 +0000 (09:35 -0600)
A recent commit skipped dumping the usual "attempt to access beyond end
of device" message if the device size is 0 sectors, as that's a common
pattern for devices that have been hot removed. But while it stopped
that message, it also prevented returning -EIO for that condition.
Reinstate the -EIO return, while retaining the quiet operation for
triggering EOD for a device with 0 sectors.

Reported-by: syzbot+4b12286339fe4c2700c1@syzkaller.appspotmail.com
Reported-by: Sahil Chandna <chandna.linuxkernel@gmail.com>
Fixes: d0a2b527d8c3 ("block: tone down bio_check_eod")
Tested-by: Sahil Chandna <chandna.linuxkernel@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c

index 4201504158a17e0a8a188e87ae096e0067c487f1..a27185cd8edead23746e52ab8caf1b75a721fceb 100644 (file)
@@ -557,9 +557,11 @@ static inline int bio_check_eod(struct bio *bio)
        sector_t maxsector = bdev_nr_sectors(bio->bi_bdev);
        unsigned int nr_sectors = bio_sectors(bio);
 
-       if (nr_sectors && maxsector &&
+       if (nr_sectors &&
            (nr_sectors > maxsector ||
             bio->bi_iter.bi_sector > maxsector - nr_sectors)) {
+               if (!maxsector)
+                       return -EIO;
                pr_info_ratelimited("%s: attempt to access beyond end of device\n"
                                    "%pg: rw=%d, sector=%llu, nr_sectors = %u limit=%llu\n",
                                    current->comm, bio->bi_bdev, bio->bi_opf,