syzbot
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: 9h29m, last: 9h29m
✨ 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
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
-
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().
-
Context of Task 4182 (__d_add() -> __d_lookup_unhash()):
-
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).
Sample crash report:
* Struck through repros no longer work on HEAD.