linux/block
Chao Shi 26cb8ebbfa block: stop the timeout timer when releasing a never added disk
disk_release() undoes blk_mq_init_allocated_queue() for a disk whose
probe failed before add_disk(), but it only calls blk_mq_exit_queue().
Nothing there stops q->timeout, and that timer rolls forward: it stays
pending until it next expires, not until the last request completes.
So if the driver issued any I/O before adding the disk, the
request_queue is freed while still linked into a timer wheel bucket.

Commit 6f8191fdf4 ("block: simplify disk shutdown") dropped the
blk_cleanup_queue() call that used to stop it.  __del_gendisk() and
blk_mq_destroy_queue() still do; only the probe failure path lost it.

nvme gets there because nvme_update_ns_info() submits Report Zones or
FDP io-mgmt-recv on ns->queue before the disk is added, so a later
failure - a concurrent reset setting NVME_CTRL_FROZEN, or
device_add_disk() failing - lands in put_disk() with the timer armed:

  BUG: KASAN: slab-use-after-free in detach_if_pending+0x30c/0x340
  Write of size 8 at addr ffff888004d71310 by task kworker/u8:2/37
   __timer_delete_sync+0x156/0x240 kernel/time/timer.c:1621
   blk_sync_queue+0x22/0x40 block/blk-core.c:222
   nvme_sync_queues+0x100/0x150 drivers/nvme/host/core.c:5362
   nvme_reset_work+0x138/0x930 drivers/nvme/host/pci.c:3264

  Allocated by task 34:
   __blk_mq_alloc_disk+0x33/0x100 block/blk-mq.c:4462
   nvme_alloc_ns+0x290/0x3870 drivers/nvme/host/core.c:4146

  Freed by task 0:
   blk_free_queue_rcu+0x3a/0x50 block/blk-core.c:254
   rcu_core+0xc10/0x1730 kernel/rcu/tree.c:2857

The queue being synced there is ctrl->admin_q, only a victim sharing a
timer wheel bucket with the freed queue's dangling entry; other runs
tripped in enqueue_timer(), __run_timers() or blk_mq_timeout_work().
Failing nvme_alloc_ns() with a debug patch makes it deterministic: one
leaked timer trips KASAN within seconds, while 1987 patched releases
produced no splat.

Stop the timer and the queue work items before blk_mq_exit_queue(), like
blk_mq_destroy_queue() does.

Found by FuzzNvme.

Fixes: 6f8191fdf4 ("block: simplify disk shutdown")
Acked-by: Weidong Zhu <weizhu@fiu.edu>
Signed-off-by: Chao Shi <coshi036@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20260727201257.211635-1-coshi036@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-07-29 05:23:20 -06:00
..
partitions partitions: aix: bound the lvd scan to one sector 2026-07-15 16:32:49 -06:00
badblocks.c
bdev.c block: Avoid mounting the bdev pseudo-filesystem in userspace 2026-05-26 11:01:55 -06:00
bfq-cgroup.c blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs() 2026-06-24 06:42:19 -06:00
bfq-iosched.c block, bfq: don't grab queue_lock to initialize bfq 2026-06-24 06:42:31 -06:00
bfq-iosched.h
bfq-wf2q.c
bio-integrity-auto.c block: fix GFP_ flags confusion in bio_integrity_alloc_buf 2026-06-24 06:53:25 -06:00
bio-integrity-fs.c block: fix GFP_ flags confusion in bio_integrity_alloc_buf 2026-06-24 06:53:25 -06:00
bio-integrity.c block: handle REQ_OP_ZONE_APPEND in __bio_integrity_action 2026-06-24 06:53:25 -06:00
bio.c block: fix aligning of bounced dio read bios 2026-07-16 06:11:37 -06:00
blk-cgroup-fc-appid.c
blk-cgroup-rwstat.c blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs() 2026-06-24 06:42:19 -06:00
blk-cgroup-rwstat.h
blk-cgroup.c blk-cgroup: fix leaks and online flag on radix_tree_insert failure 2026-07-15 16:31:43 -06:00
blk-cgroup.h blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs() 2026-06-24 06:42:19 -06:00
blk-core.c block: Remove redundant plug in __submit_bio() 2026-06-16 10:06:27 -06:00
blk-crypto-fallback.c for-7.2/block-20260615 2026-06-16 13:02:47 +05:30
blk-crypto-internal.h
blk-crypto-profile.c block/crypto: Annotate the crypto functions 2026-06-05 13:41:11 -06:00
blk-crypto-sysfs.c blk-crypto: make blk_crypto_attr instances const 2026-03-17 19:29:16 -06:00
blk-crypto.c - small cleanups in dm-vdo, dm-raid, dm-cache, dm-zoned-metadata 2026-06-16 13:20:54 +05:30
blk-flush.c
blk-ia-ranges.c block: ia-ranges: make blk_ia_range_sysfs_entry instances const 2026-03-17 19:29:16 -06:00
blk-integrity.c
blk-ioc.c
blk-iocost.c blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs() 2026-06-24 06:42:19 -06:00
blk-iolatency.c blk-cgroup: delay freeing policy data after rcu grace period 2026-06-24 06:37:54 -06:00
blk-ioprio.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
blk-ioprio.h
blk-lib.c block: add a bio_submit_or_kill helper 2026-04-07 08:22:24 -06:00
blk-map.c block: free copied pages when blk_rq_map_kern() fails 2026-07-16 06:08:14 -06:00
blk-merge.c block: propagate in_flight to whole disk on partition I/O 2026-06-09 10:12:50 -06:00
blk-mq-cpumap.c
blk-mq-debugfs.c block/blk-mq-debugfs: Improve lock context annotations 2026-06-05 13:41:11 -06:00
blk-mq-debugfs.h blk-mq-debugfs: remove blk_mq_debugfs_unregister_rqos() 2026-02-02 07:05:19 -07:00
blk-mq-dma.c block: fix partial IOVA mapping cleanup in blk_rq_dma_map_iova 2026-02-12 04:23:31 -07:00
blk-mq-sched.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
blk-mq-sched.h blk-mq-sched: unify elevators checking for async requests 2026-02-03 07:45:36 -07:00
blk-mq-sysfs.c blk-mq: make blk_mq_hw_ctx_sysfs_entry instances const 2026-03-17 19:29:16 -06:00
blk-mq-tag.c blk-mq: add tracepoint block_rq_tag_wait 2026-05-26 11:01:54 -06:00
blk-mq.c blk-mq: bound blk_hctx_poll() to one jiffy 2026-06-26 10:41:33 -06:00
blk-mq.h
blk-pm.c
blk-pm.h
blk-rq-qos.c blk-mq-debugfs: remove blk_mq_debugfs_unregister_rqos() 2026-02-02 07:05:19 -07:00
blk-rq-qos.h
blk-settings.c block: clear BLK_FEAT_PCI_P2PDMA in blk_stack_limits() for non-supporting devices 2026-05-26 15:51:48 -06:00
blk-stat.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
blk-stat.h blk-stat: convert struct blk_stat_callback to kernel-doc 2026-02-16 10:21:06 -07:00
blk-sysfs.c block: add configurable error injection 2026-06-12 10:40:35 -06:00
blk-throttle.c blk-cgroup: delay freeing policy data after rcu grace period 2026-06-24 06:37:54 -06:00
blk-throttle.h
blk-timeout.c
blk-wbt.c block: Make WBT latency writes honor enable state 2026-07-01 19:07:20 -06:00
blk-wbt.h blk-wbt: factor out a helper wbt_set_lat() 2026-02-02 07:05:19 -07:00
blk-zoned.c block: avoid potential deadlock on zone revalidation failure 2026-07-01 05:34:35 -06:00
blk.h block: fix race in blk_time_get_ns() returning 0 2026-07-15 16:31:05 -06:00
bsg-lib.c block: switch numa_node to int in blk_mq_hw_ctx and init_request 2026-05-26 11:01:55 -06:00
bsg.c bsg: add io_uring command support to generic layer 2026-03-19 11:38:24 -06:00
disk-events.c loop: fix partition scan race between udev and loop_reread_partitions() 2026-03-31 07:04:34 -06:00
early-lookup.c
elevator.c block: serialize elevator changes for the same queue using a writer lock 2026-07-16 06:08:38 -06:00
elevator.h
error-injection.c block: show operation in error injection rules 2026-07-16 06:08:55 -06:00
error-injection.h block: add configurable error injection 2026-06-12 10:40:35 -06:00
fops.c block: add a bio_endio_status helper 2026-05-28 07:59:18 -06:00
genhd.c block: stop the timeout timer when releasing a never added disk 2026-07-29 05:23:20 -06:00
holder.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ioctl.c block: fix IORING_URING_CMD_REISSUE flags check in blkdev_uring_cmd 2026-06-16 09:56:38 -06:00
ioprio.c
Kconfig block: add configurable error injection 2026-06-12 10:40:35 -06:00
Kconfig.iosched
kyber-iosched.c block/Kyber: Make the lock context annotations compatible with Clang 2026-06-05 13:41:11 -06:00
Makefile block: add configurable error injection 2026-06-12 10:40:35 -06:00
mq-deadline.c block/mq-deadline: Make the lock context annotations compatible with Clang 2026-06-05 13:41:11 -06:00
opal_proto.h sed-opal: Add STACK_RESET command 2026-03-31 07:04:00 -06:00
sed-opal.c sed-opal: Add STACK_RESET command 2026-03-31 07:04:00 -06:00
t10-pi.c blk-integrity: support arbitrary buffer alignment 2026-03-14 07:44:30 -06:00