KCSAN: data-race in fast_dput / lockref_put_return

Status: moderation: reported on 2026/11/19 00:01
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+1e521f930ff53c1d0b63@syzkaller.appspotmail.com
First crash: 1d20h, last: 41m
✨ AI-generated root cause summary:

A data race occurs between fast_dput() and lockref_put_return() due to mixed marked and unmarked concurrent accesses to struct lockref. In fast_dput(), if an optimistic lockless decrement fails (e.g., ret < 0), the kernel acquires dentry->d_lock and performs a plain, unmarked decrement on dentry->d_lockref.count. Concurrently, another task in fast_dput() executes lockref_put_return(), which performs a marked 8-byte READ_ONCE() of lockref->lock_count (which aliases both lock and count in struct lockref). Under the Linux Kernel Memory Model (LKMM), a concurrent unmarked write racing with a marked read of overlapping bytes triggers a KCSAN data-race report.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 63fdb511c27a:

Root Cause Analysis

1. Components and Data Structures Involved

  • struct lockref (include/linux/lockref.h:25-35): On 64-bit SMP architectures supporting CONFIG_ARCH_USE_CMPXCHG_LOCKREF, struct lockref is defined as a union of an 8-byte field aligned_u64 lock_count and a struct containing a 4-byte spinlock spinlock_t lock followed by a 4-byte integer int count.
  • struct dentry (include/linux/dcache.h:89,114): dentry->d_lockref stores the per-dentry lock and refcount, with dentry->d_lock defined as an alias for dentry->d_lockref.lock.
  • fast_dput() (fs/dcache.c:960-1027) and lockref_put_return() (lib/lockref.c:90-101).

2. Mechanism of the Bug and Reported Failure

  1. Task 16780 (CPU 0) executes dput() → fast_dput() → lockref_put_return(&dentry->d_lockref):

    • To avoid taking dentry->d_lock on common paths, fast_dput() enters an optimistic RCU read-side critical section and calls lockref_put_return().
    • In lib/lockref.c:15 (CMPXCHG_LOOP), lockref_put_return() reads the entire 8-byte union using:
      old.lock_count = READ_ONCE(lockref->lock_count);
      
      This constitutes an 8-byte marked read across both lock and count fields.
  2. Task 2981 (CPU 1) executes dput() → fast_dput() on the same dentry:

    • When its own optimistic lockref_put_return() returns < 0 (for example, due to a collision or contention), fast_dput() takes the slow fallback path at fs/dcache.c:977-986:
      if (unlikely(ret < 0)) {
          spin_lock(&dentry->d_lock);
          rcu_read_unlock();
          if (WARN_ON_ONCE(lockref_is_dead_or_zero(&dentry->d_lockref))) {
              spin_unlock(&dentry->d_lock);
              return true;
          }
          dentry->d_lockref.count--;
          goto locked;
      }
      
    • CPU 1 acquires dentry->d_lock (the lower 4 bytes of dentry->d_lockref) and performs dentry->d_lockref.count--; at line 984. This decrement is an unmarked (plain) 4-byte read-modify-write on dentry->d_lockref.count.
  3. Data Race Trigger:

    • Task 16780's 8-byte marked read of lockref->lock_count overlaps in memory with Task 2981's 4-byte unmarked write to lockref->count.
    • Under the Linux Kernel Memory Model (LKMM) and C concurrency rules, accessing the same or overlapping memory location concurrently with at least one write where one access is marked (READ_ONCE) and the other is unmarked (plain count--) constitutes a data race, which is detected and reported by KCSAN.

3. Invariants and Architectural Guarantees

Although flagged as a formal data race by KCSAN:

  • Task 2981 acquires dentry->d_lock before executing count--.
  • Whenever Task 16780 reads old.lock_count while Task 2981 is modifying count, Task 2981's spinlock is already held. Consequently, in lib/lockref.c:16:
    while (likely(arch_spin_value_unlocked(old.lock.rlock.raw_lock)))
    
    evaluates to false. lockref_put_return() never enters the loop body, never acts on any concurrent or torn count value, and returns -1. Task 16780's fast_dput() then safely falls back to acquiring spin_lock(&dentry->d_lock).
  • Any optimistic cmpxchg in CMPXCHG_LOOP uses try_cmpxchg64_relaxed(&lockref->lock_count, &old.lock_count, new.lock_count), which atomically verifies both the lock state and count value simultaneously. Therefore, the race is benign in non-sanitizer production builds and can be addressed by annotating the access with data_race() or appropriate access markings.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
65868fce assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in fast_dput / lockref_put_return 2026/11/18 09:15 2026/11/18 09:15 2026/11/18 10:30 eb4895d7
b4c341f0 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in fast_dput / lockref_put_return 2026/11/18 08:51 2026/11/18 08:51 2026/11/18 09:20 eb4895d7

Sample crash report:
==================================================================
BUG: KCSAN: data-race in fast_dput / lockref_put_return

read (marked) to 0xffff888105c97a40 of 8 bytes by task 20046 on cpu 1:
 lockref_put_return+0x2f/0x140 lib/lockref.c:92
 fast_dput+0x24/0x300 fs/dcache.c:970
 dput+0x1a/0x50 fs/dcache.c:1071
 path_put+0x1f/0x40 fs/namei.c:728
 do_readlinkat+0x2a2/0x2f0 fs/stat.c:592
 __do_sys_readlink fs/stat.c:609 [inline]
 __se_sys_readlink fs/stat.c:606 [inline]
 __x64_sys_readlink+0x47/0x60 fs/stat.c:606
 x64_sys_call+0x1d41/0x2550 arch/x86/include/generated/asm/syscalls_64.h:90
 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

write to 0xffff888105c97a44 of 4 bytes by task 3009 on cpu 0:
 fast_dput+0x11b/0x300 fs/dcache.c:984
 dput+0x1a/0x50 fs/dcache.c:1071
 step_into_slowpath+0x196/0x4c0 fs/namei.c:2124
 step_into fs/namei.c:2158 [inline]
 walk_component fs/namei.c:2294 [inline]
 link_path_walk+0x953/0xde0 fs/namei.c:-1
 path_lookupat+0x53/0x4c0 fs/namei.c:2818
 filename_lookup+0x18f/0x390 fs/namei.c:2848
 do_readlinkat+0x74/0x2f0 fs/stat.c:575
 __do_sys_readlink fs/stat.c:609 [inline]
 __se_sys_readlink fs/stat.c:606 [inline]
 __x64_sys_readlink+0x47/0x60 fs/stat.c:606
 x64_sys_call+0x1d41/0x2550 arch/x86/include/generated/asm/syscalls_64.h:90
 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: 3009 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (9):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/19 00:01 upstream 4405c18c95d2 2006bdcc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/18 10:01 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/18 10:00 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/18 09:59 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/18 09:59 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/18 04:45 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/17 17:16 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/17 15:32 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
2026/11/17 03:54 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in fast_dput / lockref_put_return
* Struck through repros no longer work on HEAD.