[PATCH for-rc 1/3] block: fail a delayed bio if its disk was removed
From: Md Haris Iqbal
Date: Sat Dec 05 2026 - 09:19:41 EST
A bio delayed by an error injection rule is resubmitted from a workqueue
with submit_bio_noacct_nocheck(), which skips bio_check_eod(). The
delayed bio holds no queue usage counter, so del_gendisk() does not wait
for it. For disks that don't own their queue, such as sd and sr, the
queue is unfrozen again after del_gendisk(). When sd is unbound while a
bio is delayed, the resubmitted bio reaches scsi_queue_rq() after the
driver is gone:
BUG: kernel NULL pointer dereference, address: 00000000000000c0
Workqueue: blk_error_inject blk_error_inject_delay_work
RIP: 0010:scsi_queue_rq+0x5b2/0xb80
Call Trace:
__blk_mq_issue_directly+0x3f/0xb0
blk_mq_try_issue_directly+0x8e/0x110
blk_mq_submit_bio+0x6b0/0x710
submit_bio_noacct_nocheck+0x2da/0x3c0
process_one_work+0x19b/0x370
Fail the bio instead of resubmitting it if the disk is dead. Rules
that fail the bio after the delay then also end it with BLK_STS_IOERR.
Fixes: 6bd856cc9996 ("block: allow error injection rules to delay bios")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Link: https://sashiko.dev/#/patchset/20261111215838.103356-1-haris.iqbal%40linux.dev?part=2
Signed-off-by: Md Haris Iqbal <haris.iqbal@xxxxxxxxx>
---
block/error-injection.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/block/error-injection.c b/block/error-injection.c
index a6de52229ef3..88544eb41c08 100644
--- a/block/error-injection.c
+++ b/block/error-injection.c
@@ -66,6 +66,12 @@ static void blk_error_inject_delay_work(struct work_struct *work)
kfree(d);
+ /* the disk was removed while the bio was delayed */
+ if (test_bit(GD_DEAD, &bio->bi_bdev->bd_disk->state)) {
+ bio_io_error(bio);
+ return;
+ }
+
if (status != BLK_STS_OK) {
blk_error_inject_fail(bio, status);
return;
--
2.53.0