syzbot
WARNING in free_percpu
Status:
upstream: reported on 2026/11/29 09:20
Subsystems:
scsi
Labels:
prio:normal
[Documentation on labels]
Reported-by: syzbot+4138704b4276d9a57251@syzkaller.appspotmail.com
First crash: 4d01h, last: 4d01h
✨ AI-generated root cause summary:
In sbitmap_init_node() (lib/sbitmap.c), if init_alloc_hint() succeeds in allocating sb->alloc_hint via alloc_percpu_gfp() and the subsequent kvzalloc_node() for sb->map fails, the error path calls free_percpu(sb->alloc_hint) without resetting sb->alloc_hint to NULL. When scsi_alloc_sdev() (drivers/scsi/scsi_scan.c) fails in scsi_realloc_sdev_budget_map(), it tears down the device via __scsi_remove_device(), which drops the final device reference and invokes scsi_device_dev_release() -> sbitmap_free(&sdev->budget_map). Because sdev->budget_map.alloc_hint still holds the dangling pointer to the already-freed per-CPU area, sbitmap_free() calls free_percpu() on it a second time, triggering the WARN_ON_ONCE(1) in free_percpu() (mm/percpu.c).
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
The bug is a dangling pointer / double-free of struct sbitmap::alloc_hint in sbitmap_init_node() (lib/sbitmap.c), triggered on an allocation failure path during SCSI device initialization.
Mechanism
-
Triggering path (drivers/scsi/scsi_scan.c):
- During a SCSI host scan initiated via sysfs (
store_scan() -> scsi_scan_host_selected() -> scsi_probe_and_add_lun()), scsi_alloc_sdev() allocates a zero-initialized struct scsi_device *sdev via kzalloc() and initializes its device structures with scsi_sysfs_device_initialize(sdev) (which sets the release handler on sdev->sdev_gendev to scsi_device_dev_release()).
scsi_alloc_sdev() then calls scsi_realloc_sdev_budget_map(sdev, depth) (at drivers/scsi/scsi_scan.c:363). Because sdev->budget_map.map is initially NULL (need_alloc == true, 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);
passing alloc_hint = true.
-
Root cause (lib/sbitmap.c):
-
Double-free manifestation (drivers/scsi/scsi_sysfs.c, include/linux/sbitmap.h, mm/percpu.c):
Fix Direction
Reset sb->alloc_hint = NULL; after free_percpu(sb->alloc_hint); in the error path of sbitmap_init_node() in lib/sbitmap.c (and clearing sb->alloc_hint = NULL; in sbitmap_free() in include/linux/sbitmap.h is also good defensive hygiene).
▶
▼
Last patch testing requests (1)
Sample crash report:
* Struck through repros no longer work on HEAD.