kernel BUG in lookup

Status: upstream: reported on 2026/11/23 14:51
Subsystems: dm
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+dbad68398c8646e5a382@syzkaller.appspotmail.com
First crash: 4d07h, last: 4d07h
✨ AI cause bisection: introduced by (AI job) :
commit 9b1cc9f251affdd27f29fe46d0989ba76c33faf6
Author: Joe Thornber <ejt@redhat.com>
Date: Fri Jan 23 10:00:07 2015 +0000

  dm cache: share cache-metadata object across inactive and active DM tables

✨ AI-generated root cause summary:

In drivers/md/dm-cache-metadata.c, dm_cache_metadata_close() checks if the reference count drops to zero using refcount_dec_and_test() outside table_lock before acquiring table_lock to unlink the entry from the global table list. When a concurrent thread invokes dm_cache_metadata_open() -> lookup_or_open() for the same block device, it acquires table_lock while the entry remains on the list with a refcount of 0, causing lookup() to invoke refcount_inc() on a zero reference count and triggering a refcount saturation BUG/warning. When the closing thread subsequently frees the object, the lookup caller is left holding a pointer to freed memory, causing a use-after-free.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 4405c18c95d2:

Bug Analysis and Technical Explanation

Involved Files, Functions, and Data Structures


Root Cause and Trigger Mechanism

To prevent multiple cache target instances from opening separate dm-bufio clients on the same metadata device when reload occurs before suspend, dm-cache-metadata.c caches open metadata instances in a global linked list table, synchronized by table_lock.

In lookup():

static struct dm_cache_metadata *lookup(struct block_device *bdev)
{
	struct dm_cache_metadata *cmd;

	list_for_each_entry(cmd, &table, list)
		if (cmd->bdev == bdev) {
			refcount_inc(&cmd->ref_count);
			return cmd;
		}

	return NULL;
}

lookup() is called with table_lock held. If a matching entry is found, it unconditionally calls refcount_inc(&cmd->ref_count) to take a reference before returning cmd.

However, dm_cache_metadata_close() manages the object teardown as follows:

void dm_cache_metadata_close(struct dm_cache_metadata *cmd)
{
	if (refcount_dec_and_test(&cmd->ref_count)) {
		mutex_lock(&table_lock);
		list_del(&cmd->list);
		mutex_unlock(&table_lock);

		if (!cmd->fail_io)
			__destroy_persistent_data_objects(cmd, true);
		kfree(cmd);
	}
}

The bug is that refcount_dec_and_test(&cmd->ref_count) at line 880 is performed outside table_lock.

When Thread A closes the metadata structure when cmd->ref_count == 1:

  1. Thread A executes refcount_dec_and_test(&cmd->ref_count). The refcount transitions from 1 to 0, and the function returns true.
  2. Before Thread A can acquire mutex_lock(&table_lock) at line 881, Thread B enters lookup_or_open() (triggered via dm_ctl_ioctl -> table_load -> cache_ctr -> dm_cache_metadata_open).
  3. Thread B acquires table_lock and runs lookup(bdev).
  4. Because Thread A has not yet called list_del(&cmd->list), cmd is still present in table.
  5. Thread B matches cmd->bdev == bdev and calls refcount_inc(&cmd->ref_count).
  6. Since cmd->ref_count is already 0, refcount_inc() detects an increment from 0 (REFCOUNT_ADD_UAF) and triggers refcount_warn_saturate():
    refcount_t: addition on 0; use-after-free.
    kernel BUG at lib/refcount.c:34!
    

To avoid this race condition, dm_cache_metadata_close() must ensure the refcount cannot drop to 0 while the object remains visible to lookup(), for instance by decrementing under table_lock (or via refcount_dec_and_mutex_lock(&cmd->ref_count, &table_lock)).

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
00d918d7 repro-c 💥 kernel BUG in lookup 2026/11/22 00:06 2026/11/22 00:06 2026/11/22 03:35 b2c69459
62801fe8 bisect-cause ❓ kernel BUG in lookup 2026/11/19 13:59 2026/11/19 13:59 2026/11/19 14:53 2006bdcc
bf994146 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ kernel BUG in lookup 2026/11/19 13:57 2026/11/19 13:57 2026/11/19 14:45 2006bdcc
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [dm?] kernel BUG in lookup 0 (1) 2026/11/23 14:51

Sample crash report:
refcount_t: addition on 0; use-after-free.
------------[ cut here ]------------
kernel BUG at lib/refcount.c:34!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
CPU: 0 UID: 0 PID: 6177 Comm: syz.3.65 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:refcount_warn_saturate.cold+0x12/0x14 lib/refcount.c:34
Code: 89 ea be 01 00 00 00 48 c7 c7 60 f8 c3 90 e8 0b 5a 01 00 e9 13 fc 04 04 e8 01 b7 d7 00 48 c7 c7 60 4b 81 8c e8 65 9c eb ff 90 <0f> 0b e8 ed b6 d7 00 48 c7 c7 00 4c 81 8c e8 51 9c eb ff 90 0f 0b
RSP: 0018:ffffc900030377e0 EFLAGS: 00010286
RAX: 000000000000002a RBX: ffff888028614000 RCX: 0000000000000000
RDX: 000000000000002a RSI: ffffffff81ec3719 RDI: fffff52000606eed
RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000
R10: ffffc900030375a7 R11: 0000000000000001 R12: ffff888021894500
R13: ffff888021894500 R14: 0000000000000001 R15: dffffc0000000000
FS:  00007fe6b9bf66c0(0000) GS:ffff8880d4468000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe6b9bd4ff8 CR3: 0000000060d1a000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 __refcount_add include/linux/refcount.h:289 [inline]
 __refcount_inc include/linux/refcount.h:366 [inline]
 refcount_inc include/linux/refcount.h:383 [inline]
 lookup+0x105/0x120 drivers/md/dm-cache-metadata.c:809
 lookup_or_open drivers/md/dm-cache-metadata.c:825 [inline]
 dm_cache_metadata_open+0x99/0x900 drivers/md/dm-cache-metadata.c:867
 cache_create drivers/md/dm-cache-target.c:2491 [inline]
 cache_ctr+0x180e/0x3ab0 drivers/md/dm-cache-target.c:2656
 dm_table_add_target+0x58b/0xee0 drivers/md/dm-table.c:765
 populate_table drivers/md/dm-ioctl.c:1602 [inline]
 table_load+0x3b9/0x7b0 drivers/md/dm-ioctl.c:1645
 ctl_ioctl+0x4d2/0xcc0 drivers/md/dm-ioctl.c:2221
 dm_ctl_ioctl+0x22/0x30 drivers/md/dm-ioctl.c:2243
 vfs_ioctl fs/ioctl.c:52 [inline]
 __do_sys_ioctl fs/ioctl.c:598 [inline]
 __se_sys_ioctl fs/ioctl.c:584 [inline]
 __x64_sys_ioctl+0x18e/0x210 fs/ioctl.c:584
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fe6bb9a9559
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fe6b9bf6028 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007fe6bbc26180 RCX: 00007fe6bb9a9559
RDX: 0000200000000740 RSI: 00000000c138fd09 RDI: 0000000000000004
RBP: 00007fe6bba38136 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007fe6bbc26218 R14: 00007fe6bbc26180 R15: 00007ffd9c449728
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:refcount_warn_saturate.cold+0x12/0x14 lib/refcount.c:34
Code: 89 ea be 01 00 00 00 48 c7 c7 60 f8 c3 90 e8 0b 5a 01 00 e9 13 fc 04 04 e8 01 b7 d7 00 48 c7 c7 60 4b 81 8c e8 65 9c eb ff 90 <0f> 0b e8 ed b6 d7 00 48 c7 c7 00 4c 81 8c e8 51 9c eb ff 90 0f 0b
RSP: 0018:ffffc900030377e0 EFLAGS: 00010286
RAX: 000000000000002a RBX: ffff888028614000 RCX: 0000000000000000
RDX: 000000000000002a RSI: ffffffff81ec3719 RDI: fffff52000606eed
RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000
R10: ffffc900030375a7 R11: 0000000000000001 R12: ffff888021894500
R13: ffff888021894500 R14: 0000000000000001 R15: dffffc0000000000
FS:  00007fe6b9bf66c0(0000) GS:ffff8880d4468000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe6b9bd4ff8 CR3: 0000000060d1a000 CR4: 0000000000352ef0

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/19 07:55 upstream 4405c18c95d2 2006bdcc .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream kernel BUG in lookup
* Struck through repros no longer work on HEAD.