Skip to contentSkip to conversation

block: fix EOD return for device with nr_sectors == 0

PATCH In review Jens Axboe 3 participants 4 messages Sep 22, 2025 Block layer

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 block: fix EOD return for device with nr_sectors == 0

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 [email protected]
Fixes d0a2b527d8c3 ("block: tone down bio_check_eod")

---

block/blk-core.c +3 -1
index 4201504158a1..a27185cd8ede 100644
@@ -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,
Signature · 1 line
Jens Axboe
Tested-by on v1 1/1
#1 lore raw
Quoted 22 lines · Jens Axboe

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 [email protected]
Fixes d0a2b527d8c3 ("block: tone down bio_check_eod")

---

block/blk-core.c +0 -0
index 4201504158a1..a27185cd8ede 100644
@@ -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);

block/blk-core.c static inline int bio_check_eod(struct bio *bio) · line 567

Quoted 10 lines
block/blk-core.c +3 -1
 
-	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,

Hi,
I tested the patch and it *does not* reproduce the original syzkaller bug [1].

[1] https://syzkaller.appspot.com./bug?extid=4b12286339fe4c2700c1

author maintainer
#2 lore raw
Quoted 36 lines · Sahil Chandna
Quoted 21 lines · Jens Axboe

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 [email protected]
Fixes d0a2b527d8c3 ("block: tone down bio_check_eod")

---

block/blk-core.c +0 -0
index 4201504158a1..a27185cd8ede 100644
@@ -557,9 +557,11 @@ static inline int bio_check_eod(struct bio *bio)
      sector_t maxsector = bdev_nr_sectors(bio->bi_bdev);

block/blk-core.c static inline int bio_check_eod(struct bio *bio) · line 567

Quoted 10 lines
block/blk-core.c +3 -0
      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,

Hi,
I tested the patch and it *does not* reproduce the original syzkaller bug [1].

Quoted 3 lines

[1] https://syzkaller.appspot.com./bug?extid=4b12286339fe4c2700c1

Thanks for testing! And for reporting the issue in the first place.

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

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.

Ooops. The fix looks good: