WARNING in scsi_device_dev_release

Status: upstream: reported C repro on 2026/11/29 23:07
Subsystems: block
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+01c4f5314d8c18f22177@syzkaller.appspotmail.com
First crash: 1d09h, last: 1d09h
✨ AI cause bisection: introduced by (AI job) :
commit c548e62bcf6adc7066ff201e9ecc88e536dd8890
Author: Ming Lei <ming.lei@redhat.com>
Date: Fri Jan 22 02:33:08 2021 +0000

  scsi: sbitmap: Move allocation hint into sbitmap

✨ AI-generated root cause summary:

In sbitmap_init_node() (lib/sbitmap.c), when kvzalloc_node() fails to allocate sb->map after init_alloc_hint() has already succeeded, the error path calls free_percpu(sb->alloc_hint) without resetting sb->alloc_hint to NULL. During SCSI device allocation failure cleanup in scsi_alloc_sdev(), __scsi_remove_device() drops the device reference and triggers scsi_device_dev_release(), which unconditionally calls sbitmap_free(&sdev->budget_map). Because sb->alloc_hint still holds the dangling per-CPU pointer (and sbitmap_free() in include/linux/sbitmap.h also does not clear sb->alloc_hint), free_percpu() is invoked a second time on the already-freed per-CPU allocation, triggering the WARN_ON_ONCE(1) in mm/percpu.c.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 822ba3a89c78:

Root Cause Analysis

The warning in free_percpu() (mm/percpu.c:2262) is caused by a double free of struct sbitmap::alloc_hint when sbitmap_init_node() fails partway through initialization during SCSI device allocation.

1. Dangling sb->alloc_hint on sbitmap_init_node() failure

In lib/sbitmap.c, sbitmap_init_node() allocates sb->alloc_hint via init_alloc_hint() (alloc_percpu_gfp(unsigned int, flags)) before allocating sb->map:

	if (alloc_hint) {
		if (init_alloc_hint(sb, flags))
			return -ENOMEM;
	} else {
		sb->alloc_hint = NULL;
	}

	sb->map = kvzalloc_node(sb->map_nr * sizeof(*sb->map), flags, node);
	if (!sb->map) {
		free_percpu(sb->alloc_hint);
		return -ENOMEM;
	}

If init_alloc_hint() succeeds (sb->alloc_hint is non-NULL) and the subsequent kvzalloc_node() for sb->map fails, sbitmap_init_node() calls free_percpu(sb->alloc_hint) and returns -ENOMEM without setting sb->alloc_hint = NULL. This leaves sb->alloc_hint containing a dangling per-CPU pointer.

Additionally, sbitmap_free() in include/linux/sbitmap.h resets sb->map = NULL after freeing it, but likewise does not reset sb->alloc_hint = NULL after free_percpu(sb->alloc_hint).

2. Trigger path through SCSI device scanning

  1. A write to /sys/class/scsi_host/host*/scan (store_scan() -> scsi_scan_host_selected() -> ... -> scsi_probe_and_add_lun()) calls scsi_alloc_sdev() (drivers/scsi/scsi_scan.c).
  2. scsi_alloc_sdev() zero-allocates struct scsi_device *sdev (kzalloc), calls scsi_sysfs_device_initialize(sdev) (which sets sdev->sdev_gendev.type = &scsi_dev_type whose release callback is scsi_device_dev_release), and then calls scsi_realloc_sdev_budget_map(sdev, depth).
  3. On initial allocation (sdev->budget_map.map == NULL, need_free == false), scsi_realloc_sdev_budget_map() calls:
    ret = sbitmap_init_node(&sdev->budget_map,
                            scsi_device_max_queue_depth(sdev),
                            new_shift, GFP_NOIO,
                            sdev->request_queue->node, false, true);
    
  4. When init_alloc_hint() succeeds and kvzalloc_node() fails inside sbitmap_init_node(), sdev->budget_map.alloc_hint is freed once and left dangling, and scsi_realloc_sdev_budget_map() returns -ENOMEM.
  5. scsi_alloc_sdev() jumps to out_device_destroy: and calls __scsi_remove_device(sdev) (drivers/scsi/scsi_sysfs.c), which cleans up the queue/work and calls put_device(&sdev->sdev_gendev).
  6. Dropping the last reference invokes scsi_device_dev_release() (drivers/scsi/scsi_sysfs.c:482), which unconditionally calls sbitmap_free(&sdev->budget_map) (relying on sbitmap_free() being safe on uninitialized or failed budget_map structs).
  7. sbitmap_free() calls free_percpu(sb->alloc_hint) a second time on the already-freed per-CPU pointer. pcpu_free_area() in mm/percpu.c sees the allocation bit already cleared in chunk->alloc_map, returns 0, and free_percpu() hits WARN_ON_ONCE(1) at mm/percpu.c:2262.

Fix Direction

  • In lib/sbitmap.c (sbitmap_init_node()), set sb->alloc_hint = NULL; after free_percpu(sb->alloc_hint); on the !sb->map error path.
  • In include/linux/sbitmap.h (sbitmap_free()), set sb->alloc_hint = NULL; after free_percpu(sb->alloc_hint); to keep the teardown symmetric with sb->map = NULL;.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
d8329c3a bisect-cause IsRelease: ❌ ❓ WARNING in scsi_device_dev_release 2026/11/28 15:04 2026/11/28 15:04 2026/11/28 15:34 e1f06033
3d5397e9 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ WARNING in scsi_device_dev_release 2026/11/28 14:41 2026/11/28 14:41 2026/11/28 15:34 e1f06033
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [block?] WARNING in scsi_device_dev_release 0 (1) 2026/11/29 23:07

Sample crash report:
Node 1 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=1048576kB
Node 1 hugepages_total=2 hugepages_free=2 hugepages_surp=0 hugepages_size=2048kB
46836 total pagecache pages
0 pages in swap cache
Free swap  = 124996kB
Total swap = 124996kB
2097051 pages RAM
0 pages HighMem/MovableOnly
438546 pages reserved
0 pages cma reserved
------------[ cut here ]------------
1
WARNING: mm/percpu.c:2262 at free_percpu mm/percpu.c:2262 [inline], CPU#1: syz-executor419/6020
WARNING: mm/percpu.c:2262 at free_percpu+0x7cd/0x1510 mm/percpu.c:2239, CPU#1: syz-executor419/6020
Modules linked in:
CPU: 1 UID: 0 PID: 6020 Comm: syz-executor419 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
RIP: 0010:free_percpu mm/percpu.c:2262 [inline]
RIP: 0010:free_percpu+0x7cd/0x1510 mm/percpu.c:2239
Code: 49 29 c7 4d 01 ef 4c 39 fd 0f 82 12 fa ff ff e9 00 f9 ff ff e8 54 b6 a9 ff 48 8b 34 24 48 c7 c7 40 19 1a 90 e8 d4 6d 91 09 90 <0f> 0b 90 e9 46 ff ff ff e8 36 b6 a9 ff 48 3b 1d bf fe 2a 0c 0f 84
RSP: 0018:ffffc9000398f540 EFLAGS: 00010286
RAX: 8000000000000001 RBX: ffff888020e85c00 RCX: 0000000000000000
RDX: 0000000000000004 RSI: ffffffff8e62e6c9 RDI: 0000000000000001
RBP: 0000000000025cf0 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: 0000607edd7c8cf0
R13: 0000000000000000 R14: ffff888020e85c80 R15: 0000000000025cf0
FS:  000055557344d400(0000) GS:ffff88812255d000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f2957eab708 CR3: 000000005a68c000 CR4: 00000000003526f0
Call Trace:
 <TASK>
 sbitmap_free include/linux/sbitmap.h:187 [inline]
 scsi_device_dev_release+0x5fc/0x12b0 drivers/scsi/scsi_sysfs.c:482
 device_release+0xd2/0x270 drivers/base/core.c:2640
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1f7/0x640 lib/kobject.c:737
 put_device+0x1f/0x30 drivers/base/core.c:3886
 __scsi_remove_device+0x2a3/0x430 drivers/scsi/scsi_sysfs.c:1527
 scsi_alloc_sdev+0xc2a/0xe90 drivers/scsi/scsi_scan.c:384
 scsi_probe_and_add_lun+0x555/0xd30 drivers/scsi/scsi_scan.c:1227
 __scsi_scan_target+0x1a3/0x4b0 drivers/scsi/scsi_scan.c:1803
 scsi_scan_channel+0x1b6/0x1e0 drivers/scsi/scsi_scan.c:1897
 scsi_scan_host_selected+0x307/0x3f0 drivers/scsi/scsi_scan.c:1922
 scsi_scan drivers/scsi/scsi_sysfs.c:151 [inline]
 store_scan+0x435/0x480 drivers/scsi/scsi_sysfs.c:191
 dev_attr_store+0x58/0x80 drivers/base/core.c:2509
 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145
 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345
 new_sync_write fs/read_write.c:575 [inline]
 vfs_write+0x6af/0x1040 fs/read_write.c:667
 ksys_pwrite64+0x113/0x230 fs/read_write.c:774
 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:0x7fef31abed37
Code: 48 89 fa 4c 89 df e8 98 1d 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffe60061720 EFLAGS: 00000202 ORIG_RAX: 0000000000000012
RAX: ffffffffffffffda RBX: 000055557344d400 RCX: 00007fef31abed37
RDX: 0000000000000005 RSI: 00007fef31af40c8 RDI: 0000000000000006
RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 00007ffe60061820
R13: 0000000000000002 R14: 0000000000000004 R15: 000055557344d3d8
 </TASK>

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/28 14:41 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 822ba3a89c78 bda6e3c6 .config console log report C ci-upstream-kasan-gce-selinux-root WARNING in scsi_device_dev_release
* Struck through repros no longer work on HEAD.