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: 2d00h, last: 6h03m
✨ 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 0xffff8881016b4200 of 8 bytes by task 63 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_shallow lib/sbitmap.c:307 [inline]
 sbitmap_get_shallow lib/sbitmap.c:335 [inline]
 sbitmap_queue_get_shallow+0xaf/0x1b0 lib/sbitmap.c:572
 __blk_mq_get_tag+0xf5/0x2c0 block/blk-mq-tag.c:125
 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]
 ext4_io_submit fs/ext4/page-io.c:399 [inline]
 io_submit_add_bh fs/ext4/page-io.c:455 [inline]
 ext4_bio_write_folio+0x927/0xc80 fs/ext4/page-io.c:550
 mpage_submit_folio+0x100/0x120 fs/ext4/inode.c:2215
 mpage_process_page_bufs+0x3fa/0x570 fs/ext4/inode.c:2322
 mpage_prepare_extent_to_map+0x889/0xcb0 fs/ext4/inode.c:2870
 ext4_do_writepages+0x7ba/0x26c0 fs/ext4/inode.c:3018
 ext4_writepages+0x1d1/0x340 fs/ext4/inode.c:3166
 do_writepages+0x1ce/0x310 mm/page-writeback.c:2562
 __writeback_single_inode+0x7b/0x7f0 fs/fs-writeback.c:1809
 writeback_sb_inodes+0x4d9/0xac0 fs/fs-writeback.c:2120
 __writeback_inodes_wb+0x8e/0x190 fs/fs-writeback.c:2196
 wb_writeback+0x21e/0x560 fs/fs-writeback.c:2307
 wb_check_start_all fs/fs-writeback.c:2433 [inline]
 wb_do_writeback fs/fs-writeback.c:2480 [inline]
 wb_workfn+0x579/0xb70 fs/fs-writeback.c:2518
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
 worker_thread+0x56c/0x770 kernel/workqueue.c:3659
 kthread+0x248/0x2a0 kernel/kthread.c:436
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

read to 0xffff8881016b4200 of 8 bytes by task 3327 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]
 ext4_mpage_readpages+0xdd0/0xe20 fs/ext4/readpage.c:317
 ext4_readahead+0xad/0xc0 fs/ext4/readpage.c:356
 read_pages+0xa8/0x5c0 mm/readahead.c:174
 page_cache_ra_unbounded+0x307/0x3f0 mm/readahead.c:315
 do_page_cache_ra mm/readahead.c:348 [inline]
 page_cache_ra_order+0x149/0x220 mm/readahead.c:558
 do_sync_mmap_readahead+0x2c1/0x380 mm/filemap.c:3466
 filemap_fault+0x3e2/0xab0 mm/filemap.c:3620
 __do_fault mm/memory.c:5691 [inline]
 do_read_fault mm/memory.c:6136 [inline]
 do_fault mm/memory.c:6270 [inline]
 do_pte_missing mm/memory.c:4797 [inline]
 handle_pte_fault mm/memory.c:6689 [inline]
 __handle_mm_fault mm/memory.c:6841 [inline]
 handle_mm_fault+0x2183/0x3880 mm/memory.c:7008
 do_user_addr_fault+0x3ce/0xde0 arch/x86/mm/fault.c:1343
 handle_page_fault arch/x86/mm/fault.c:1483 [inline]
 exc_page_fault+0x62/0xa0 arch/x86/mm/fault.c:1536
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595

value changed: 0xfec000000007ffff -> 0xfec00000000fffff

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 3327 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (7):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
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.