Linux block layer
 help / color / mirror / Atom feed
* [PATCH] block: fix EOD return for device with nr_sectors == 0
@ 2025-09-22 11:58 Jens Axboe
  2025-09-22 13:48 ` Sahil Chandna
  2025-09-22 16:57 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Jens Axboe @ 2025-09-22 11:58 UTC (permalink / raw)
  To: linux-block@vger.kernel.org; +Cc: Sahil Chandna

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")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/block/blk-core.c b/block/blk-core.c
index 4201504158a1..a27185cd8ede 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -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,

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: fix EOD return for device with nr_sectors == 0
  2025-09-22 11:58 [PATCH] block: fix EOD return for device with nr_sectors == 0 Jens Axboe
@ 2025-09-22 13:48 ` Sahil Chandna
  2025-09-22 15:35   ` Jens Axboe
  2025-09-22 16:57 ` Christoph Hellwig
  1 sibling, 1 reply; 4+ messages in thread
From: Sahil Chandna @ 2025-09-22 13:48 UTC (permalink / raw)
  To: Jens Axboe, linux-block@vger.kernel.org



On 9/22/25 5:28 PM, Jens Axboe wrote:
> 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")
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> 
> ---
> 
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 4201504158a1..a27185cd8ede 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -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,
> 
Hi,
I tested the patch and it *does not* reproduce the original syzkaller 
bug [1].
Tested-by: Sahil Chandna <chandna.linuxkernel@gmail.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: fix EOD return for device with nr_sectors == 0
  2025-09-22 13:48 ` Sahil Chandna
@ 2025-09-22 15:35   ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-09-22 15:35 UTC (permalink / raw)
  To: Sahil Chandna, linux-block@vger.kernel.org

On 9/22/25 7:48 AM, Sahil Chandna wrote:
> 
> 
> On 9/22/25 5:28 PM, Jens Axboe wrote:
>> 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")
>> Signed-off-by: Jens Axboe <axboe@kernel.dk>
>>
>> ---
>>
>> diff --git a/block/blk-core.c b/block/blk-core.c
>> index 4201504158a1..a27185cd8ede 100644
>> --- a/block/blk-core.c
>> +++ b/block/blk-core.c
>> @@ -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,
>>
> Hi,
> I tested the patch and it *does not* reproduce the original syzkaller bug [1].
> Tested-by: Sahil Chandna <chandna.linuxkernel@gmail.com>
> 
> [1] https://syzkaller.appspot.com./bug?extid=4b12286339fe4c2700c1

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

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: fix EOD return for device with nr_sectors == 0
  2025-09-22 11:58 [PATCH] block: fix EOD return for device with nr_sectors == 0 Jens Axboe
  2025-09-22 13:48 ` Sahil Chandna
@ 2025-09-22 16:57 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2025-09-22 16:57 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block@vger.kernel.org, Sahil Chandna

On Mon, Sep 22, 2025 at 05:58:41AM -0600, Jens Axboe wrote:
> 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:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-22 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 11:58 [PATCH] block: fix EOD return for device with nr_sectors == 0 Jens Axboe
2025-09-22 13:48 ` Sahil Chandna
2025-09-22 15:35   ` Jens Axboe
2025-09-22 16:57 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox