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 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), 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
Based on kernel commit 8d7fe9885c62:

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

  1. 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.
  2. Root cause (lib/sbitmap.c):

    • In sbitmap_init_node() (lib/sbitmap.c:101-142), init_alloc_hint(sb, flags) (lib/sbitmap.c:12-27) allocates per-CPU memory via alloc_percpu_gfp(unsigned int, flags) and stores it in sb->alloc_hint.
    • Immediately afterward, sbitmap_init_node() attempts to allocate sb->map (lib/sbitmap.c:132-136):
      sb->map = kvzalloc_node(sb->map_nr * sizeof(*sb->map), flags, node);
      if (!sb->map) {
          free_percpu(sb->alloc_hint);
          return -ENOMEM;
      }
      
    • When kvzalloc_node() fails (e.g., under OOM or fault injection), sbitmap_init_node() frees sb->alloc_hint with free_percpu(), but fails to reset sb->alloc_hint = NULL, leaving a dangling per-CPU pointer inside sdev->budget_map.
  3. Double-free manifestation (drivers/scsi/scsi_sysfs.c, include/linux/sbitmap.h, mm/percpu.c):

    • Because scsi_realloc_sdev_budget_map() returns -ENOMEM, scsi_alloc_sdev() jumps to out_device_destroy: (drivers/scsi/scsi_scan.c:383-384) and calls __scsi_remove_device(sdev).
    • __scsi_remove_device() (drivers/scsi/scsi_sysfs.c:1527) calls put_device(&sdev->sdev_gendev), dropping the final reference and invoking device_release() -> scsi_device_dev_release().
    • scsi_device_dev_release() (drivers/scsi/scsi_sysfs.c:482) unconditionally calls sbitmap_free(&sdev->budget_map) (include/linux/sbitmap.h:185-190), which executes:
      free_percpu(sb->alloc_hint);
      kvfree(sb->map);
      sb->map = NULL;
      
    • Calling free_percpu() on the dangling sb->alloc_hint attempts to free the per-CPU allocation a second time. In free_percpu() (mm/percpu.c:2257-2264), pcpu_free_area() sees that the allocation bit in chunk->alloc_map is already cleared, returns size == 0, and triggers WARN_ON_ONCE(1) at mm/percpu.c:2262.

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).

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
fe902d64 repro-c Reproduced: ✅ ❓ WARNING in free_percpu 2026/11/28 06:16 2026/11/28 06:16 2026/11/28 07:43 e1f06033
9d4aee9e bisect-cause IsRelease: ❌ ❓ WARNING in free_percpu 2026/11/25 09:01 2026/11/25 09:01 2026/11/25 09:32 bda6e3c6
14a77f01 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ WARNING in free_percpu 2026/11/25 08:37 2026/11/25 08:37 2026/11/25 09:14 bda6e3c6
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [scsi?] WARNING in free_percpu 0 (1) 2026/11/29 09:20
▶ ▼ Last patch testing requests (1)
Created Duration User Patch Repo Result
2026/11/28 08:57 5h43m retest repro git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 822ba3a89c7896b26e4beb70e2ebffb881924dfe report job log log

Sample crash report:
------------[ cut here ]------------
1
WARNING: mm/percpu.c:2262 at free_percpu mm/percpu.c:2262 [inline], CPU#1: syz.9.1840/15973
WARNING: mm/percpu.c:2262 at free_percpu+0x7cd/0x1510 mm/percpu.c:2239, CPU#1: syz.9.1840/15973
Modules linked in:
CPU: 1 UID: 0 PID: 15973 Comm: syz.9.1840 Tainted: G             L      syzkaller #0 PREEMPT(full) 
Tainted: [L]=SOFTLOCKUP
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 34 bf a9 ff 48 8b 34 24 48 c7 c7 40 14 1a 90 e8 34 99 90 09 90 <0f> 0b 90 e9 46 ff ff ff e8 16 bf a9 ff 48 3b 1d 1f fa 2a 0c 0f 84
RSP: 0018:ffffc9000543f548 EFLAGS: 00010286
RAX: 8000000000000001 RBX: ffff888023a82400 RCX: 0000000000000000
RDX: 0000000000000004 RSI: ffffffff8e62d962 RDI: 0000000000000001
RBP: 0000000000008c98 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: 0000607edd7a7c98
R13: 0000000000000000 R14: ffff888023a82480 R15: 0000000000008c98
FS:  00007f0d6dfb46c0(0000) GS:ffff888122561000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000200000007000 CR3: 000000005a0c3000 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_write+0x12a/0x250 fs/read_write.c:719
 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:0x7f0d6d1a9a19
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:00007f0d6dfb4028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f0d6d435fa0 RCX: 00007f0d6d1a9a19
RDX: 0000000000000005 RSI: 00002000000004c0 RDI: 0000000000000007
RBP: 00007f0d6d239156 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f0d6d436038 R14: 00007f0d6d435fa0 R15: 00007ffd731f8988
 </TASK>

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/25 08:37 upstream 8d7fe9885c62 bda6e3c6 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root WARNING in free_percpu
* Struck through repros no longer work on HEAD.