KCSAN: data-race in dentry_kill / lockref_get_not_dead

Status: moderation: reported on 2026/11/17 06:24
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+e9e7603aef221419e3ee@syzkaller.appspotmail.com
First crash: 12h15m, last: 3h52m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  bc08b449ee14 lockref: implement lockless reference count updates using cmpxchg()
  1c18edd1b7a0 __dentry_kill(): new locking scheme
  e7d33bb5ea82 lockref: add ability to mark lockrefs "dead"
  
✨ AI-generated root cause summary:

A KCSAN data race is flagged between lockref_get_not_dead() in lib/lockref.c and dentry_kill() in fs/dcache.c. During an RCU-walk unlazy operation, lockref_get_not_dead() invokes CMPXCHG_LOOP to optimistically read the 8-byte lockref->lock_count (aliasing spinlock_t lock and int count) via READ_ONCE without holding the lock. Concurrently, dentry_kill() decrements parent->d_lockref.count via an unmarked 4-byte read-modify-write (--parent->d_lockref.count) while holding parent->d_lock. Because the lockless 8-byte read overlaps the concurrent unmarked 4-byte write, KCSAN detects a data race, even though the operation is benign due to lockref's lock-checking validation and fallback to spin_lock.

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

Root Cause Analysis

1. Involved Structures, Functions, and Source Files


2. Triggering Mechanism and Race Sequence

  1. Reader Path (lockref_get_not_dead in task 4498):

    • During an RCU-walk path resolution unlazy operation (try_to_unlazy()), task 4498 attempts to legitimize a dentry reference (the parent directory dentry) by calling lockref_get_not_dead(&path->dentry->d_lockref).
    • lockref_get_not_dead() enters macro CMPXCHG_LOOP (lib/lockref.c:11-27), which begins with an optimistic lockless 8-byte load:
      old.lock_count = READ_ONCE(lockref->lock_count);
      
    • This 8-byte read accesses memory 0xffff888105d35800 through 0xffff888105d35807, covering both the spinlock and the reference counter without acquiring parent->d_lock.
  2. Writer Path (dentry_kill in task 3284):

    • Concurrently, task 3284 is destroying a child dentry inside dentry_kill().
    • dentry_kill() locks the parent dentry via spin_lock(&parent->d_lock) at line 868.
    • Once the child is unlisted and freed, line 877 decrements the parent's reference counter:
      if (parent && --parent->d_lockref.count) {
          spin_unlock(&parent->d_lock);
          return NULL;
      }
      
    • --parent->d_lockref.count is a 4-byte non-atomic read-modify-write located at offset +4 (0xffff888105d35804).
  3. KCSAN Detection:

    • KCSAN observes an 8-byte marked read (READ_ONCE(lockref->lock_count)) on CPU 0 overlapping an unmarked 4-byte read-modify-write (--parent->d_lockref.count) on CPU 1.
    • Because plain C read-modify-writes (--parent->d_lockref.count) do not carry WRITE_ONCE() or atomic annotations, KCSAN flags the concurrent access as a data race.

3. Correctness and Synchronization Analysis (Benign Data Race)

This data race is benign by design of the lockref subsystem:

  • When task 3284 executes --parent->d_lockref.count, it holds parent->d_lock (parent->d_lockref.lock).
  • If task 4498's READ_ONCE(lockref->lock_count) runs while parent->d_lock is held by task 3284:
    • old.lock contains the locked state (arch_spin_value_unlocked(old.lock.rlock.raw_lock) evaluates to 0).
    • The while loop condition fails immediately; CMPXCHG_LOOP terminates without performing try_cmpxchg64_relaxed() and without using any potentially torn or in-transition counter value.
    • lockref_get_not_dead() falls back to spin_lock(&lockref->lock), which properly blocks until task 3284 releases parent->d_lock, ensuring strict serialization.
  • If task 4498's READ_ONCE(lockref->lock_count) runs before task 3284 acquires the lock, old.lock reflects an unlocked state. However, before task 4498 can execute try_cmpxchg64_relaxed(), task 3284 acquires the lock. The 64-bit cmpxchg instruction will then compare old.lock_count (which has the unlocked lock value) against current memory (which has the locked spinlock value). The comparison fails, old.lock_count is reloaded with the locked state, and execution falls back to taking the spinlock.
  • Consequently, reference counts cannot be corrupted, dentries cannot be freed prematurely, and execution behavior in real-world setups is fully preserved.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
c7f163c7 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in dentry_kill / lockref_get_not_dead 2026/11/17 06:22 2026/11/17 06:22 2026/11/17 06:49 a3e64cfc
3357f59b bisect-cause ❓ KCSAN: data-race in dentry_kill / lockref_get_not_dead 2026/11/17 06:14 2026/11/17 06:14 2026/11/17 07:04 a3e64cfc
05f5e79f assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in dentry_kill / lockref_get_not_dead 2026/11/17 06:13 2026/11/17 06:13 2026/11/17 06:22 a3e64cfc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in dentry_kill / lockref_get_not_dead

read (marked) to 0xffff8881005b35c0 of 8 bytes by task 3659 on cpu 1:
 lockref_get_not_dead+0x2f/0x1d0 lib/lockref.c:147
 __legitimize_path fs/namei.c:880 [inline]
 legitimize_path fs/namei.c:890 [inline]
 try_to_unlazy+0x1f1/0x580 fs/namei.c:954
 complete_walk+0xc5/0x200 fs/namei.c:1070
 path_parentat fs/namei.c:2868 [inline]
 __filename_parentat+0x1d2/0x460 fs/namei.c:2890
 filename_parentat fs/namei.c:2908 [inline]
 filename_unlinkat+0x91/0x400 fs/namei.c:5706
 __do_sys_unlink fs/namei.c:5772 [inline]
 __se_sys_unlink+0x2b/0xe0 fs/namei.c:5769
 __x64_sys_unlink+0x1f/0x30 fs/namei.c:5769
 x64_sys_call+0x18ee/0x2550 arch/x86/include/generated/asm/syscalls_64.h:88
 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-write to 0xffff8881005b35c4 of 4 bytes by task 3285 on cpu 0:
 dentry_kill+0x377/0x4f0 fs/dcache.c:877
 finish_dput+0x16/0x1d0 fs/dcache.c:1032
 dput+0x43/0x50 fs/dcache.c:1073
 end_dirop fs/namei.c:2962 [inline]
 filename_unlinkat+0x212/0x400 fs/namei.c:5740
 __do_sys_unlink fs/namei.c:5772 [inline]
 __se_sys_unlink+0x2b/0xe0 fs/namei.c:5769
 __x64_sys_unlink+0x1f/0x30 fs/namei.c:5769
 x64_sys_call+0x18ee/0x2550 arch/x86/include/generated/asm/syscalls_64.h:88
 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: 0 UID: 0 PID: 3285 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 10:20 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in dentry_kill / lockref_get_not_dead
2026/11/17 10:19 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in dentry_kill / lockref_get_not_dead
2026/11/17 01:57 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in dentry_kill / lockref_get_not_dead
* Struck through repros no longer work on HEAD.