syzbot
BUG: unable to handle kernel paging request in blk_mq_exit_hctx
Status:
upstream: reported syz repro on 2026/11/02 03:47
Subsystems:
block
ext4
Labels:
prio:low
[Documentation on labels]
Reported-by: syzbot+5307e3bcacec2ce4c2f0@syzkaller.appspotmail.com
First crash: 23h37m, last: 11h02m
✨ AI-generated root cause summary:
When dm_setup_md_queue() fails after add_disk() (for instance during bd_link_disk_holder() or dm_sysfs_init()), the error path invokes del_gendisk(), which calls blk_mq_exit_queue() -> blk_mq_exit_hctx(), freeing each hardware context flush queue and setting hctx->fq = NULL. However, md->type remains DM_TYPE_NONE and the mapped device is not torn down. When userspace retries table_load on the device, dm_setup_md_queue() and dm_mq_init_request_queue() run again, invoking blk_mq_init_allocated_queue() on the existing queue. During __blk_mq_realloc_hw_ctxs(), blk_mq_exit_hctx() is called on the existing hardware contexts, unconditionally dereferencing hctx->fq->flush_rq (offset 0x78) when hctx->fq is NULL, causing a kernel null-pointer dereference crash.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Files Involved
drivers/md/dm.c: dm_setup_md_queue()
drivers/md/dm-rq.c: dm_mq_init_request_queue()
drivers/md/dm-ioctl.c: table_load()
block/blk-mq.c: blk_mq_init_allocated_queue(), __blk_mq_realloc_hw_ctxs(), blk_mq_exit_hctx(), blk_mq_exit_hw_queues(), blk_mq_exit_queue()
block/genhd.c: __del_gendisk(), del_gendisk()
- Structures:
struct mapped_device, struct request_queue, struct blk_mq_hw_ctx, struct blk_flush_queue
2. Trigger Mechanism and Lifecycle Invariant Violation
-
Initial Device Creation & Table Load:
- A device-mapper device is created via
alloc_dev() with md->type = DM_TYPE_NONE, and a request queue is allocated via md->disk = blk_alloc_disk(NULL, ...); md->queue = md->disk->queue;.
- Userspace issues a
DM_TABLE_LOAD ioctl (table_load() in drivers/md/dm-ioctl.c).
- Seeing that
dm_get_md_type(md) == DM_TYPE_NONE, table_load() invokes dm_setup_md_queue(md, t).
-
Transition to Request-Based Queue & Error in dm_setup_md_queue():
- For a request-based table (
type == DM_TYPE_REQUEST_BASED), dm_setup_md_queue() invokes dm_mq_init_request_queue(md, t).
dm_mq_init_request_queue() allocates md->tag_set and calls blk_mq_init_allocated_queue(md->tag_set, md->queue).
- Hardware contexts (
struct blk_mq_hw_ctx *hctx) and flush queues (hctx->fq) are allocated and stored in q->queue_hw_ctx[].
- Next,
dm_setup_md_queue() calls add_disk(md->disk).
- If a subsequent setup step fails (such as
bd_link_disk_holder() or dm_sysfs_init()), execution branches to out_undo_holders:
out_undo_holders:
list_for_each_entry_continue_reverse(td, &md->table_devices, list)
bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
del_gendisk(md->disk);
mutex_unlock(&md->table_devices_lock);
return r;
del_gendisk(md->disk) executes __del_gendisk(). Because queue_is_mq(q) and test_bit(GD_OWNS_QUEUE, &disk->state) are true, it calls blk_mq_exit_queue(q).
blk_mq_exit_queue() invokes blk_mq_exit_hw_queues() -> blk_mq_exit_hctx().
blk_mq_exit_hctx() tears down the flush queue:
call_srcu(&set->tags_srcu, &hctx->fq->rcu_head, blk_free_flush_queue_callback);
hctx->fq = NULL;
list_add(&hctx->hctx_list, &q->unused_hctx_list);
- Crucially,
del_gendisk() and blk_mq_exit_queue() do not clear q->queue_hw_ctx[].
- Furthermore,
dm_setup_md_queue() returns the error code without ever setting md->type = type. Thus, md->type remains DM_TYPE_NONE, but the mapped device remains active in user space and the DM IDR/hash tables.
-
Subsequent Table Load & NULL Pointer Dereference:
- Userspace retries
DM_TABLE_LOAD on the same mapped device.
- Because
dm_get_md_type(md) is still DM_TYPE_NONE, table_load() calls dm_setup_md_queue(md, t) again.
dm_setup_md_queue() again executes dm_mq_init_request_queue(md, t) on md->queue.
dm_mq_init_request_queue() allocates a new tag set and calls blk_mq_init_allocated_queue(md->tag_set, md->queue).
blk_mq_init_allocated_queue() calls blk_mq_realloc_hw_ctxs(set, q) -> __blk_mq_realloc_hw_ctxs(set, q).
- In
__blk_mq_realloc_hw_ctxs(), the loop checks previously allocated hardware contexts:
for (i = 0; i < set->nr_hw_queues; i++) {
int old_node;
int node = blk_mq_get_hctx_node(set, i);
struct blk_mq_hw_ctx *old_hctx = hctxs[i];
if (old_hctx) {
old_node = old_hctx->numa_node;
blk_mq_exit_hctx(q, set, old_hctx, i);
}
- Because
hctxs[i] (q->queue_hw_ctx[i]) still contains old_hctx from the previous failed run, blk_mq_exit_hctx(q, set, old_hctx, i) is called a second time.
- At the beginning of
blk_mq_exit_hctx() (block/blk-mq.c:3957):
struct request *flush_rq = hctx->fq->flush_rq;
- Because
old_hctx->fq was already cleared to NULL during the previous del_gendisk(), reading hctx->fq->flush_rq attempts to access offset 0x78 of NULL.
- On 64-bit systems (with KASAN reading shadow memory at
0xdfff800000000000 + (0x78 >> 3) = 0xdfff80000000000f), this triggers a level 1 translation fault and kernel crash (Oops: null-ptr-deref).
Sample crash report:
Unable to handle kernel paging request at virtual address dfff80000000000f
KASAN: null-ptr-deref in range [0x0000000000000078-0x000000000000007f]
Mem abort info:
ESR = 0x0000000096000005
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x05: level 1 translation fault
Data abort info:
ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000
CM = 0, WnR = 0, TnD = 0, TagAccess = 0
GCS = 0, Overlay = 0, DirtyBit = 0
[dfff80000000000f] address between user and kernel address ranges
Internal error: Oops: 0000000096000005 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 9108 Comm: syz.5.600 Not tainted syzkaller #0 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 83400005 (Nzcv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : blk_mq_exit_hctx+0x64/0x494 block/blk-mq.c:3957
lr : blk_mq_exit_hctx+0x40/0x494 block/blk-mq.c:3956
sp : ffff8000984475d0
x29: ffff8000984475e0 x28: 0000000000000000 x27: 1fffe0001b03332a
x26: dfff800000000000 x25: ffff0000d8199950 x24: ffff0000c3aeffc0
x23: 0000000000000078 x22: 0000000000000000 x21: ffff0000d3857000
x20: ffff0000d8199800 x19: ffff0000eabc5388 x18: ffff8001237ae000
x17: ffff0001acf6ce07 x16: ffff0000dad68014 x15: 0000000000000001
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: ffff0000eabc53bc x9 : 0000000000000000
x8 : 000000000000000f x7 : 0000000000000000 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000003 x3 : 0000000000000000
x2 : ffff0000d8199800 x1 : ffff0000dad68000 x0 : 0000000000000000
Call trace:
blk_mq_exit_hctx+0x64/0x494 block/blk-mq.c:3957 (P)
__blk_mq_realloc_hw_ctxs+0x1f0/0x548 block/blk-mq.c:4583
blk_mq_realloc_hw_ctxs block/blk-mq.c:4623 [inline]
blk_mq_init_allocated_queue+0x2a8/0xc44 block/blk-mq.c:4653
dm_mq_init_request_queue+0x2d8/0x474 drivers/md/dm-rq.c:573
dm_setup_md_queue+0x134/0x434 drivers/md/dm.c:2611
table_load+0x3d4/0x764 drivers/md/dm-ioctl.c:1661
ctl_ioctl drivers/md/dm-ioctl.c:2221 [inline]
dm_ctl_ioctl+0x884/0xbbc drivers/md/dm-ioctl.c:2243
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x60/0x1d8 arch/arm64/kernel/entry-common.c:796
el0t_64_sync_handler+0x44/0x104 arch/arm64/kernel/entry-common.c:815
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:606
Code: 97cfdb27 f9400328 9101e117 d343fee8 (387a6908)
---[ end trace 0000000000000000 ]---
----------------
Code disassembly (best guess):
0: 97cfdb27 bl 0xffffffffff3f6c9c
4: f9400328 ldr x8, [x25]
8: 9101e117 add x23, x8, #0x78
c: d343fee8 lsr x8, x23, #3
* 10: 387a6908 ldrb w8, [x8, x26] <-- trapping instruction
* Struck through repros no longer work on HEAD.