KCSAN: data-race in __d_lookup_unhash / dentry_kill

Status: moderation: reported on 2026/11/18 00:04
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+f0aa92852c90551f92d1@syzkaller.appspotmail.com
First crash: 3h24m, last: 3h24m
✨ AI cause bisection: introduced by (AI job) :
commit ba65dc5ef16f82fba77869cecf7a7d515f61446b
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Fri Jun 10 15:32:47 2016 +0000

  much milder d_walk() race

  
✨ AI-generated root cause summary:

In fs/dcache.c, dentry_unlist() performs an unsynchronized read of the adjacent sibling dentry's d_flags (testing DCACHE_DENTRY_CURSOR) under the parent's d_lock and the dying dentry's d_lock, without holding the sibling's d_lock. Concurrently, another thread completing parallel lookup on that sibling dentry holds the sibling's d_lock (but not the parent's d_lock) and modifies its d_flags by clearing DCACHE_PAR_LOOKUP in __d_lookup_unhash(). Because neither operation uses READ_ONCE()/WRITE_ONCE() or explicit data_race() annotations, KCSAN detects a data race on d_flags. This is a benign data race because DCACHE_DENTRY_CURSOR is an immutable property assigned at allocation and is never set on regular dentries nor cleared on cursors.

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

Technical Root Cause Analysis

Involved Functions, Structs, Fields, and Files

  • Files: fs/dcache.c, include/linux/dcache.h
  • Structs & Fields:
    • struct dentry:
      • d_flags (unsigned int, 4 bytes) — flags bitmap indicating dentry state, including DCACHE_PAR_LOOKUP (BIT 24) and DCACHE_DENTRY_CURSOR (BIT 25).
      • d_sib (struct hlist_node) — links the dentry into its parent's d_children list.
      • d_lock (spinlock_t) — protects the dentry's own fields, including d_flags.
      • d_parent (struct dentry *) — pointer to parent dentry, whose d_lock protects the d_children list.
  • Functions:

Mechanism and Trigger Sequence

  1. Context of Task 3289 (dentry_kill() -> dentry_unlist()):

    • A dentry is unreferenced and undergoing eviction. In dentry_kill(), locks are taken in sequence:
      if (!IS_ROOT(dentry)) {
          parent = dentry->d_parent;
          spin_lock(&parent->d_lock);
      }
      spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
      dentry_unlist(dentry);
      
    • Inside dentry_unlist(), after unlinking the dying dentry from parent->d_children with __hlist_del(&dentry->d_sib), the function ensures that the stale pointer left in dentry->d_sib.next does not point to a directory cursor (which can move dynamically when iterating directory contents via lseek):
      while (dentry->d_sib.next) {
          next = hlist_entry(dentry->d_sib.next, struct dentry, d_sib);
          if (likely(!(next->d_flags & DCACHE_DENTRY_CURSOR)))
              break;
          dentry->d_sib.next = next->d_sib.next;
      }
      
    • Crucially, while Task 3289 holds parent->d_lock (which serializes sibling list modifications) and dentry->d_lock, it does not acquire next->d_lock. It performs a plain 4-byte read of next->d_flags without READ_ONCE() or data_race().
  2. Context of Task 4182 (__d_add() -> __d_lookup_unhash()):

    • Task 4182 is completing a parallel lookup for the adjacent sibling dentry (next). During __d_alloc_parallel(), this sibling was inserted at the head of parent->d_children with the DCACHE_PAR_LOOKUP flag set in its d_flags.
    • When lookup completes and the dentry is instantiated/added via __d_add(), it acquires dentry->d_lock (i.e. next->d_lock) and invokes __d_lookup_unhash():
      dentry->d_flags &= ~DCACHE_PAR_LOOKUP;
      
    • Task 4182 holds next->d_lock (the lock designated to serialize updates to its d_flags), but does not hold parent->d_lock. It performs a plain 4-byte read-modify-write on next->d_flags without WRITE_ONCE() or atomics.
  3. Concurrency and Invariant Violation:

    • Because next->d_flags is updated by Task 4182 under next->d_lock without parent->d_lock, and read by Task 3289 under parent->d_lock without next->d_lock, the plain read in dentry_unlist() races concurrently with the plain write in __d_lookup_unhash().
    • The kernel concurrency model treats unsynchronized, unannotated concurrent reads and writes to the same memory location as a data race, triggering the KCSAN report.

Lifecycle and Practical Correctness

  • DCACHE_DENTRY_CURSOR (BIT(25)) is an immutable attribute set strictly at cursor initialization in d_alloc_cursor() (fs/dcache.c:2132) before the cursor is attached to any list; it is never set on normal dentries and never cleared on cursors throughout their lifecycle.
  • Concurrent writers to next->d_flags (such as __d_lookup_unhash() modifying DCACHE_PAR_LOOKUP, BIT(24)) are fully serialized amongst themselves under next->d_lock, avoiding lost updates.
  • Clearing BIT(24) neither sets nor clears BIT(25). Consequently, the bit test in dentry_unlist() always evaluates identically and correctly (false for any non-cursor dentry).
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
d415a79e bisect-cause ❓ KCSAN: data-race in __d_lookup_unhash / dentry_kill 2026/11/17 21:38 2026/11/17 21:38 2026/11/17 22:21 ca622473
56f1151f assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __d_lookup_unhash / dentry_kill 2026/11/17 21:33 2026/11/17 21:33 2026/11/17 22:04 ca622473
0967e775 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in __d_lookup_unhash / dentry_kill 2026/11/17 21:31 2026/11/17 21:31 2026/11/17 22:12 ca622473

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

read to 0xffff888105c82d80 of 4 bytes by task 3289 on cpu 1:
 dentry_unlist fs/dcache.c:725 [inline]
 dentry_kill+0x2c5/0x4f0 fs/dcache.c:871
 finish_dput+0x16/0x1d0 fs/dcache.c:1032
 dput+0x43/0x50 fs/dcache.c:1073
 handle_mounts fs/namei.c:1759 [inline]
 step_into_slowpath+0x38c/0x4c0 fs/namei.c:2110
 step_into fs/namei.c:2158 [inline]
 walk_component fs/namei.c:2294 [inline]
 lookup_last fs/namei.c:2795 [inline]
 path_lookupat+0x2eb/0x4c0 fs/namei.c:2819
 filename_lookup+0x18f/0x390 fs/namei.c:2848
 vfs_statx+0x96/0x170 fs/stat.c:357
 vfs_fstatat+0x118/0x170 fs/stat.c:377
 __do_sys_newfstatat fs/stat.c:542 [inline]
 __se_sys_newfstatat+0x55/0x3e0 fs/stat.c:536
 __x64_sys_newfstatat+0x55/0x70 fs/stat.c:536
 x64_sys_call+0xee6/0x2550 arch/x86/include/generated/asm/syscalls_64.h:263
 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 0xffff888105c82d80 of 4 bytes by task 4182 on cpu 0:
 __d_lookup_unhash+0x59/0x130 fs/dcache.c:3100
 __d_add+0xaa/0x1a0 fs/dcache.c:3135
 d_splice_alias_ops+0xe3/0x3b0 fs/dcache.c:3491
 d_splice_alias+0x1f/0x30 fs/dcache.c:3520
 simple_lookup+0xb7/0xd0 fs/libfs.c:81
 lookup_open+0x6aa/0x10a0 fs/namei.c:4536
 open_last_lookups fs/namei.c:4774 [inline]
 path_openat+0x492/0x11e0 fs/namei.c:5013
 do_file_open+0x16c/0x290 fs/namei.c:5045
 do_sys_openat2+0xa1/0x140 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0xf2/0x120 fs/open.c:1460
 x64_sys_call+0x1f72/0x2550 arch/x86/include/generated/asm/syscalls_64.h:258
 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: 4182 Comm: udevd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 21:27 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __d_lookup_unhash / dentry_kill
* Struck through repros no longer work on HEAD.