KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (18)

Status: moderation: reported on 2026/11/19 00:08
Subsystems: ext4
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+785951b7fab6dfb99cab@syzkaller.appspotmail.com
First crash: 1d09h, last: 7h35m
✨ AI-generated root cause summary:

A data race occurs in fs/buffer.c between has_bh_in_lru() and invalidate_bh_lrus_cpu() due to unsynchronized concurrent access to the per-CPU buffer head LRU array, bh_lrus. While task 4160 on CPU 0 executes invalidate_bh_lrus() via on_each_cpu_cond(), it invokes has_bh_in_lru() to inspect remote CPUs' bh_lrus.bhs[] entries using plain reads without locks or atomic read annotations. Concurrently, task 3369 on CPU 1 executes invalidate_bh_lrus_cpu() via workqueue folio draining and calls __invalidate_bh_lrus(), which clears bh_lrus.bhs[] to NULL using plain writes while holding only its local CPU's bh_lru_lock(). Because neither access uses atomic primitives (such as READ_ONCE/WRITE_ONCE) or data_race() annotations, KCSAN flags the concurrent load and store as a data race.

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

Root Cause Analysis

Involved Functions, Structs, Fields, and Files


Technical Breakdown & Mechanism

  1. Per-CPU LRU Cache and Synchronization Rules:

    • In fs/buffer.c, the buffer cache maintains a per-CPU LRU structure defined by struct bh_lru and instantiated as bh_lrus. Each CPU caches up to BH_LRU_SIZE (16) buffer_head pointers in bhs[].
    • Under standard operations (bh_lru_install, lookup_bh_lru, and invalidate_bh_lrus_cpu), each CPU accesses its own per-CPU instance of bh_lrus protected by bh_lru_lock(), which expands to local_irq_disable() on SMP configurations. This local interrupt disable only synchronizes local execution against interrupts or preemption on the same CPU, providing no cross-CPU mutual exclusion.
  2. The Read Path (has_bh_in_lru):

    • When a filesystem or block device triggers buffer invalidation (e.g., during unmount ext4_put_super() -> invalidate_bdev()), it calls invalidate_bh_lrus().
    • invalidate_bh_lrus() invokes on_each_cpu_cond(has_bh_in_lru, invalidate_bh_lru, NULL, 1).
    • On CPU 0, smp_call_function_many_cond() iterates through online CPUs and runs the predicate function has_bh_in_lru(cpu, NULL) to determine whether an IPI must be sent to that CPU:
      bool has_bh_in_lru(int cpu, void *dummy)
      {
          struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu);
          int i;
      
          for (i = 0; i < BH_LRU_SIZE; i++) {
              if (b->bhs[i])
                  return true;
          }
      
          return false;
      }
      
    • CPU 0 directly dereferences the remote CPU's per_cpu_ptr(&bh_lrus, cpu)->bhs[i] with plain loads, holding neither a cross-CPU spinlock nor using atomic access primitives like READ_ONCE() or data_race().
  3. The Concurrent Write Path (__invalidate_bh_lrus via invalidate_bh_lrus_cpu):

    • Simultaneously on CPU 1, per-CPU folio draining work (lru_add_drain_per_cpu() -> lru_add_and_bh_lrus_drain()) calls invalidate_bh_lrus_cpu().
    • invalidate_bh_lrus_cpu() calls __invalidate_bh_lrus(b) under bh_lru_lock() (local IRQ disable):
      static void __invalidate_bh_lrus(struct bh_lru *b)
      {
          int i;
      
          for (i = 0; i < BH_LRU_SIZE; i++) {
              brelse(b->bhs[i]);
              b->bhs[i] = NULL;
          }
      }
      
    • Line 1430 (b->bhs[i] = NULL;) performs a plain 8-byte store to clear the cached pointer.
  4. The Race Condition:

    • While CPU 1 executes b->bhs[i] = NULL; at fs/buffer.c:1430, CPU 0 concurrently evaluates if (b->bhs[i]) at fs/buffer.c:1452 for CPU 1's per-CPU array.
    • Because both the read and write accesses are unannotated plain C memory accesses to the same memory location (0xffff888237d27d00), KCSAN flags this as a data race between has_bh_in_lru and invalidate_bh_lrus_cpu.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
9ea746b3 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (18) 2026/11/18 17:07 2026/11/18 17:07 2026/11/18 17:15 2006bdcc
e4887dd3 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (18) 2026/11/18 16:57 2026/11/18 16:57 2026/11/18 17:42 2006bdcc
▶ ▼ Similar bugs (17)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (3) fs 6 1 1498d 1498d 0/29 auto-obsoleted due to no activity on 2022/11/16 21:51
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (5) fs 6 2 1303d 1315d 0/29 auto-obsoleted due to no activity on 2023/05/30 05:48
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (7) ext4 6 3 1129d 1156d 0/29 auto-obsoleted due to no activity on 2023/11/20 11:49
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (9) fs 6 1 1034d 1034d 0/29 auto-obsoleted due to no activity on 2024/02/23 17:16
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (16) ext4 6 2 269d 281d 0/29 auto-obsoleted due to no activity on 2026/04/19 01:25
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (11) exfat 6 1 807d 807d 0/29 auto-obsoleted due to no activity on 2024/10/07 09:54
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (6) ext4 6 1 1193d 1193d 0/29 auto-obsoleted due to no activity on 2023/09/17 01:43
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (17) race:benign prio:high fs 6 1 70d 70d 0/29 auto-obsoleted due to no activity on 2026/11/04 01:34
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (10) fs 6 1 950d 950d 0/29 auto-obsoleted due to no activity on 2024/05/17 23:40
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (13) ext4 6 2 705d 706d 0/29 auto-obsoleted due to no activity on 2025/02/08 00:12
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (2) fs 6 14 1542d 1749d 0/29 auto-closed as invalid on 2022/10/03 06:12
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (14) fs 6 1 603d 603d 0/29 auto-obsoleted due to no activity on 2025/05/20 16:51
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (8) ext4 6 1 1084d 1073d 0/29 auto-obsoleted due to no activity on 2024/01/04 10:47
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu ext4 6 137 1821d 1979d 0/29 auto-closed as invalid on 2021/12/28 13:59
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (15) ext4 6 4 496d 534d 0/29 auto-obsoleted due to no activity on 2025/09/04 15:11
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (12) fs 6 1 763d 763d 0/29 auto-obsoleted due to no activity on 2024/11/20 10:12
upstream KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu (4) ext4 6 3 1408d 1459d 0/29 auto-obsoleted due to no activity on 2023/03/11 22:09

Sample crash report:
EXT4-fs (loop3): unmounting filesystem 00000000-0000-0000-0000-000000000000.
==================================================================
BUG: KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu

write to 0xffff888237c27ce8 of 8 bytes by task 3770 on cpu 0:
 __invalidate_bh_lrus fs/buffer.c:1430 [inline]
 invalidate_bh_lrus_cpu+0xa7/0xe0 fs/buffer.c:1475
 lru_add_and_bh_lrus_drain mm/folio.c:763 [inline]
 lru_add_drain_per_cpu+0x57/0x70 mm/folio.c:782
 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 0xffff888237c27ce8 of 8 bytes by task 13029 on cpu 1:
 has_bh_in_lru+0x54/0x1f0 fs/buffer.c:1452
 smp_call_function_many_cond+0x2f3/0xc10 kernel/smp.c:962
 on_each_cpu_cond_mask+0x35/0x50 kernel/smp.c:1195
 on_each_cpu_cond include/linux/smp.h:105 [inline]
 invalidate_bh_lrus+0x2a/0x30 fs/buffer.c:1461
 invalidate_bdev+0x42/0x70 block/bdev.c:99
 ext4_put_super+0x67f/0x820 fs/ext4/super.c:1376
 generic_shutdown_super+0xf4/0x230 fs/super.c:723
 kill_block_super+0x2a/0x70 fs/super.c:1852
 ext4_kill_sb+0x42/0x80 fs/ext4/super.c:7578
 deactivate_locked_super+0x89/0x150 fs/super.c:558
 deactivate_super+0xac/0xc0 fs/super.c:586
 cleanup_mnt+0x143/0x1c0 fs/namespace.c:1396
 __cleanup_mnt+0x19/0x20 fs/namespace.c:1403
 task_work_run+0x145/0x1a0 kernel/task_work.c:233
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 __exit_to_user_mode_loop kernel/entry/common.c:70 [inline]
 exit_to_user_mode_loop+0x1fa/0x940 kernel/entry/common.c:101
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:343 [inline]
 do_syscall_64+0x23b/0x3a0 arch/x86/entry/syscall_64.c:107
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

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

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/18 17:13 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu
2026/11/17 15:05 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in has_bh_in_lru / invalidate_bh_lrus_cpu
* Struck through repros no longer work on HEAD.