KCSAN: data-race in __d_drop / fast_dput (4)

Status: moderation: reported on 2026/11/20 00:09
Subsystems: fs
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+018da129184660eb882f@syzkaller.appspotmail.com
First crash: 2d21h, last: 2d12h
✨ AI-generated root cause summary:

A data race occurs between __d_drop() writing NULL to dentry->d_hash.pprev during dentry eviction and fast_dput() reading dentry->d_hash.pprev via d_unhashed() -> hlist_bl_unhashed() in retain_dentry(). In fast_dput(), retain_dentry(dentry, false) intentionally checks dentry hash status locklessly under rcu_read_lock() after atomically decrementing the lockref counter to zero. If another task concurrently looks up the negative dentry, drops it, and invokes dentry_kill() -> __d_drop(), the store to pprev races with the read because hlist_bl_unhashed() and __d_drop() lack READ_ONCE()/WRITE_ONCE() annotations. Both outcomes of the boolean check are safely tolerated by the lockless fast_dput() logic without causing memory corruption or refcount inconsistencies.

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

Technical Root Cause Analysis

1. Functions, Structs, and Fields Involved

  • Source Files: fs/dcache.c, include/linux/list_bl.h, include/linux/dcache.h
  • Functions: __d_drop(), dentry_kill(), fast_dput(), retain_dentry(), d_unhashed(), hlist_bl_unhashed()
  • Structs & Fields:
    • struct dentry: field dentry->d_hash.pprev (member of struct hlist_bl_node), dentry->d_lockref, dentry->d_flags
    • struct hlist_bl_node: h->pprev

2. Detailed Interleaving and Mechanism

The reported KCSAN data race occurs between:

  1. An unmarked store to dentry->d_hash.pprev in __d_drop():
    void __d_drop(struct dentry *dentry)
    {
        if (!d_unhashed(dentry)) {
            ___d_drop(dentry);
            dentry->d_hash.pprev = NULL; /* line 609 */
            write_seqcount_invalidate(&dentry->d_seq);
        }
    }
    
  2. An unmarked load from dentry->d_hash.pprev in hlist_bl_unhashed() called via d_unhashed() in retain_dentry():
    static inline bool hlist_bl_unhashed(const struct hlist_bl_node *h)
    {
        return !h->pprev; /* include/linux/list_bl.h:54 */
    }
    

This race is triggered during concurrent directory operations (such as concurrent unlinkat() calls operating on the same path):

  1. Task 5148 (filename_unlinkat -> end_dirop -> dput -> fast_dput):

    • Task 5148 has unlinked the file via vfs_unlink(). d_delete() turns the victim dentry into a negative dentry while keeping it hashed.
    • Task 5148 then unlocks the parent directory inode (inode_unlock()) and calls dput(de).
    • In fast_dput(), Task 5148 holds rcu_read_lock() and invokes lockref_put_return(&dentry->d_lockref), which atomically decrements the reference count from 1 to 0 and returns 0.
    • Before taking dentry->d_lock, fast_dput() calls retain_dentry(dentry, false) locklessly under RCU to check if taking the lock can be avoided.
    • At line 903 of fs/dcache.c, retain_dentry() checks d_unhashed(dentry):
      if (unlikely(d_unhashed(dentry)))
          return false;
      
      which expands to reading dentry->d_hash.pprev via hlist_bl_unhashed(&dentry->d_hash).
  2. Task 2977 (filename_unlinkat -> start_dirop -> lookup_one_qstr_excl -> dput):

    • Concurrently, Task 2977 acquires the parent directory lock and looks up the same file name via lookup_dcache() -> __d_lookup().
    • __d_lookup() finds the negative dentry still on the hash chain, locks dentry->d_lock, increments dentry->d_lockref.count from 0 to 1, and unlocks dentry->d_lock.
    • Seeing that the dentry is negative without LOOKUP_CREATE, lookup_one_qstr_excl() calls dput(dentry).
    • In Task 2977's fast_dput(), lockref_put_return() decrements dentry->d_lockref.count back from 1 to 0.
    • Task 2977's retain_dentry(dentry, false) returns false (or falls back to the locked path where retain_dentry(dentry, true) returns false), returning false from fast_dput().
    • Task 2977 proceeds to finish_dput() -> dentry_kill(dentry):
      lockref_mark_dead(&dentry->d_lockref); /* sets count to __LOCKREF_DEAD_VAL (-128) */
      ...
      __d_drop(dentry); /* lines 855 and 609: dentry->d_hash.pprev = NULL */
      
  3. The Race Condition:

    • While Task 2977 executes dentry->d_hash.pprev = NULL under dentry->d_lock, Task 5148 reads dentry->d_hash.pprev in hlist_bl_unhashed() without holding dentry->d_lock.
    • Because neither the load nor the store is marked with READ_ONCE() / WRITE_ONCE(), KCSAN detects a data race on dentry->d_hash.pprev.

3. Invariant Safety and Lifecycle Handling

retain_dentry(dentry, false) is explicitly designed to tolerate stale or changing predicates when lockless:

  • rcu_read_lock() is held throughout fast_dput(), ensuring that RCU-delayed freeing (call_rcu(&dentry->d_rcu, __d_free)) prevents memory reclamation while the lockless check executes.
  • If Task 5148 reads the old non-NULL pprev, d_unhashed() returns false, and retain_dentry(dentry, false) may return true. Task 5148 drops its RCU read lock and exits dput(), its reference decrement (1 -> 0) having already been committed prior to Task 2977's acquisition and eviction of the dentry.
  • If Task 5148 reads NULL, retain_dentry(dentry, false) returns false. Task 5148 falls back to the locked slow path at locked: (fs/dcache.c:1021), taking dentry->d_lock. At this point, Task 2977 has already marked the dentry dead via lockref_mark_dead(), setting dentry->d_lockref.count = __LOCKREF_DEAD_VAL (-128). Because dentry->d_lockref.count evaluates to non-zero, fast_dput() unlocks dentry->d_lock and returns true, correctly avoiding any double-free or redundant eviction.

To eliminate the KCSAN warning, access to h->pprev in hlist_bl_unhashed() and the unhashing write in __d_drop() should be annotated with READ_ONCE() / WRITE_ONCE() (or data_race()).

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
f8eb4857 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __d_drop / fast_dput (4) 2026/11/19 14:10 2026/11/19 14:10 2026/11/19 14:19 2006bdcc
42ec0570 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in __d_drop / fast_dput (4) 2026/11/19 14:08 2026/11/19 14:08 2026/11/19 14:42 2006bdcc
▶ ▼ Similar bugs (3)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in __d_drop / fast_dput (2) fs 6 3 1883d 1893d 0/29 auto-closed as invalid on 2021/10/28 07:38
upstream KCSAN: data-race in __d_drop / fast_dput fs 6 1 1966d 1966d 0/29 auto-closed as invalid on 2021/08/06 11:24
upstream KCSAN: data-race in __d_drop / fast_dput (3) prio:low fs 6 159 158d 297d 0/29 auto-obsoleted due to no activity on 2026/08/02 16:10

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

write to 0xffff888105c6c9d0 of 8 bytes by task 2977 on cpu 0:
 __d_drop+0x138/0x230 fs/dcache.c:609
 dentry_kill+0x119/0x4f0 fs/dcache.c:855
 finish_dput+0x16/0x1d0 fs/dcache.c:1032
 dput+0x43/0x50 fs/dcache.c:1073
 lookup_one_qstr_excl+0x156/0x240 fs/namei.c:-1
 __start_dirop fs/namei.c:2926 [inline]
 start_dirop fs/namei.c:2948 [inline]
 filename_unlinkat+0x146/0x400 fs/namei.c:5718
 __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 to 0xffff888105c6c9d0 of 8 bytes by task 5148 on cpu 1:
 hlist_bl_unhashed include/linux/list_bl.h:54 [inline]
 d_unhashed include/linux/dcache.h:402 [inline]
 retain_dentry fs/dcache.c:903 [inline]
 fast_dput+0x64/0x300 fs/dcache.c:1002
 dput+0x1a/0x50 fs/dcache.c:1071
 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

value changed: 0xffff8882376fd7f8 -> 0x0000000000000000

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 5148 Comm: udevd 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/17 11:49 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __d_drop / fast_dput
2026/11/17 03:02 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __d_drop / fast_dput
* Struck through repros no longer work on HEAD.