KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit

Status: moderation: reported on 2026/11/17 07:48
Subsystems: scsi
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+f266e0fe6df87b348a47@syzkaller.appspotmail.com
First crash: 2d07h, last: 2h06m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
commit 4bb659b156996f2993dc16fad71fec9ee070153c
Author: Jens Axboe <axboe@fb.com>
Date: Fri May 9 15:36:49 2014 +0000

  blk-mq: implement new and more efficient tagging scheme

commit 88459642cba452630326b9cab1c651e09577d4e4
Author: Omar Sandoval <osandov@fb.com>
Date: Sat Sep 17 14:38:44 2016 +0000

  blk-mq: abstract tag allocation out into sbitmap library
  
✨ AI-generated root cause summary:

In lib/sbitmap.c:__sbitmap_get_word(), find_next_zero_bit() performs an unmarked plain load on struct sbitmap_word::word to optimistically locate a zero bit. Concurrently, another thread executing __sbitmap_get_word() modifies the same sbitmap_word::word via the marked atomic primitive test_and_set_bit_lock(). KCSAN flags this plain read racing against an atomic write as a data race, though the race is benign because allocation is strictly gated by the atomic test-and-set operation.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Technical Mechanism & Root Cause

The report describes a Kernel Concurrency Sanitizer (KCSAN) data-race warning between _find_next_zero_bit() and sbitmap_find_bit() / __sbitmap_get_word().

1. Functions, Structs, and Fields Involved

2. Detailed Bug Trigger and Concurrency Flow

  1. Thread 0 (task 6224):

    • Calls sbitmap_get() -> __sbitmap_get() -> sbitmap_find_bit() -> sbitmap_find_bit_in_word() -> __sbitmap_get_word(&map->word, ...).
    • At lib/sbitmap.c:167, it attempts to find an available clear bit in map->word by invoking:
      nr = find_next_zero_bit(word, depth, hint);
      
    • In _find_next_zero_bit() (lib/find_bit.c:215), the macro FIND_NEXT_BIT(~addr[idx], ...) performs a plain memory read of addr[idx] (i.e. map->word). This read is unmarked (not using READ_ONCE() or atomic access primitives).
  2. Thread 1 (task 6223):

    • Concurrently executes __sbitmap_get_word(&map->word, ...) on another CPU.
    • Having previously identified a candidate zero bit index nr, it attempts to claim the bit at lib/sbitmap.c:181:
      if (!test_and_set_bit_lock(nr, word))
          break;
      
    • test_and_set_bit_lock() performs a marked atomic read-modify-write operation (lock bts on x86, instrumented via instrument_atomic_read_write).
  3. KCSAN Flag:

    • KCSAN observes an unmarked plain read on map->word concurrently with an atomic read-modify-write modification to the exact same 8-byte location, flagging it as a data race.

3. Invariant Verification and Benign Nature

  • Design Pattern: This is a classic optimistic/speculative lookup pattern in lockless algorithms. find_next_zero_bit() is strictly used as an un-synchronized hint search to find a candidate zero bit in map->word.
  • Exclusion Guarantees: Exclusive bit reservation is enforced by test_and_set_bit_lock(nr, word). If another CPU (e.g., Task 6223) claimed that bit in the interim, test_and_set_bit_lock() returns non-zero (true), rejecting the claim and causing the loop to advance hint = nr + 1 and retry.
  • Exhaustion Handling: If no zero bits are found (nr >= depth), __sbitmap_get_word() returns -1, prompting sbitmap_find_bit_in_word() to invoke sbitmap_deferred_clear(), which flushes deferred cleared bits under map->swap_lock.
  • Eliminating the Warning: Similar to how __sbitmap_queue_get_batch() was cleaned up in commit 6ad0d7e0f4b6 ("sbitmap: use READ_ONCE to access map->word"), this KCSAN report can be eliminated by taking a marked local snapshot via unsigned long val = READ_ONCE(*word); and passing &val to find_next_zero_bit().
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
8784d020 bisect-cause ❓ KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit 2026/11/17 07:47 2026/11/17 07:47 2026/11/17 08:19 a3e64cfc
cd47f104 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit 2026/11/17 07:44 2026/11/17 07:44 2026/11/17 07:49 a3e64cfc
838ff464 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit 2026/11/17 07:30 2026/11/17 07:30 2026/11/17 07:47 a3e64cfc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit

read-write (marked) to 0xffff888100200800 of 8 bytes by task 7679 on cpu 0:
 instrument_atomic_read_write include/linux/instrumented.h:113 [inline]
 test_and_set_bit_lock include/asm-generic/bitops/instrumented-lock.h:57 [inline]
 __sbitmap_get_word lib/sbitmap.c:181 [inline]
 sbitmap_find_bit_in_word lib/sbitmap.c:200 [inline]
 sbitmap_find_bit+0x240/0x420 lib/sbitmap.c:245
 __sbitmap_get lib/sbitmap.c:277 [inline]
 sbitmap_get+0xa3/0x1a0 lib/sbitmap.c:291
 __sbitmap_queue_get+0x15/0x20 lib/sbitmap.c:511
 __blk_mq_get_tag+0x104/0x2c0 block/blk-mq-tag.c:127
 blk_mq_get_tag+0x144/0x720 block/blk-mq-tag.c:166
 __blk_mq_alloc_requests+0x82b/0x1020 block/blk-mq.c:600
 blk_mq_get_new_requests block/blk-mq.c:3064 [inline]
 blk_mq_submit_bio+0xc11/0x1310 block/blk-mq.c:3205
 __submit_bio+0x68/0x250 block/blk-core.c:674
 __submit_bio_noacct_mq block/blk-core.c:757 [inline]
 submit_bio_noacct_nocheck+0x168/0x650 block/blk-core.c:791
 submit_bio_noacct+0x810/0xa80 block/blk-core.c:929
 submit_bio+0x2a4/0x2c0 block/blk-core.c:970
 blk_crypto_submit_bio include/linux/blk-crypto.h:212 [inline]
 __bh_submit+0x427/0x460 fs/buffer.c:1148
 bh_submit fs/buffer.c:1162 [inline]
 __sync_dirty_buffer+0x1d4/0x2d0 fs/buffer.c:2724
 sync_dirty_buffer+0x1a/0x30 fs/buffer.c:2737
 fat_set_state+0x17f/0x1e0 fs/fat/inode.c:750
 fat_fill_super+0x1a75/0x1d00 fs/fat/inode.c:1892
 vfat_fill_super+0x24/0x30 fs/fat/namei_vfat.c:1214
 get_tree_bdev_flags+0x297/0x300 fs/super.c:1821
 get_tree_bdev+0x1f/0x30 fs/super.c:1844
 vfat_get_tree+0x1c/0x30 fs/fat/namei_vfat.c:1219
 vfs_get_tree+0x57/0x1d0 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount+0x288/0x730 fs/namespace.c:3986
 path_mount+0x4ad/0xba0 fs/namespace.c:4337
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount+0x28c/0x2e0 fs/namespace.c:4540
 __x64_sys_mount+0x67/0x80 fs/namespace.c:4540
 x64_sys_call+0xc3b/0x2550 arch/x86/include/generated/asm/syscalls_64.h:166
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff888100200800 of 8 bytes by task 6729 on cpu 1:
 _find_next_zero_bit+0x29/0xa0 lib/find_bit.c:215
 find_next_zero_bit include/linux/find.h:190 [inline]
 __sbitmap_get_word lib/sbitmap.c:167 [inline]
 sbitmap_find_bit_in_word lib/sbitmap.c:200 [inline]
 sbitmap_find_bit+0x205/0x420 lib/sbitmap.c:245
 __sbitmap_get lib/sbitmap.c:277 [inline]
 sbitmap_get+0xa3/0x1a0 lib/sbitmap.c:291
 __sbitmap_queue_get+0x15/0x20 lib/sbitmap.c:511
 __blk_mq_get_tag+0x104/0x2c0 block/blk-mq-tag.c:127
 blk_mq_get_tag+0x144/0x720 block/blk-mq-tag.c:166
 __blk_mq_alloc_requests+0x82b/0x1020 block/blk-mq.c:600
 blk_mq_get_new_requests block/blk-mq.c:3064 [inline]
 blk_mq_submit_bio+0xc11/0x1310 block/blk-mq.c:3205
 __submit_bio+0x68/0x250 block/blk-core.c:674
 __submit_bio_noacct_mq block/blk-core.c:757 [inline]
 submit_bio_noacct_nocheck+0x168/0x650 block/blk-core.c:791
 submit_bio_noacct+0x810/0xa80 block/blk-core.c:929
 submit_bio+0x2a4/0x2c0 block/blk-core.c:970
 blk_crypto_submit_bio include/linux/blk-crypto.h:212 [inline]
 __bh_submit+0x427/0x460 fs/buffer.c:1148
 bh_submit fs/buffer.c:1162 [inline]
 block_read_full_folio+0x60e/0x650 fs/buffer.c:2386
 blkdev_read_folio+0x1c/0x30 block/fops.c:503
 filemap_read_folio+0x40/0x150 mm/filemap.c:2549
 filemap_update_page mm/filemap.c:2636 [inline]
 filemap_get_pages+0xe98/0x1020 mm/filemap.c:2766
 filemap_read+0x20d/0x8d0 mm/filemap.c:2853
 blkdev_read_iter+0x29c/0x390 block/fops.c:892
 new_sync_read fs/read_write.c:473 [inline]
 vfs_read+0x6ac/0x7d0 fs/read_write.c:554
 ksys_read+0xdc/0x1a0 fs/read_write.c:696
 __do_sys_read fs/read_write.c:705 [inline]
 __se_sys_read fs/read_write.c:703 [inline]
 __x64_sys_read+0x40/0x50 fs/read_write.c:703
 x64_sys_call+0x2135/0x2550 arch/x86/include/generated/asm/syscalls_64.h:1
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 6729 Comm: udevd Tainted: G        W           syzkaller #0 PREEMPT(lazy) 
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (8):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/19 09:03 upstream 4405c18c95d2 f138241c .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/18 22:02 upstream 4405c18c95d2 2006bdcc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/18 18:58 upstream 20eef29b7c84 2006bdcc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/18 06:59 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/17 21:36 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/17 17:04 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/17 10:09 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
2026/11/17 04:02 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in _find_next_zero_bit / sbitmap_find_bit
* Struck through repros no longer work on HEAD.