syzbot
KCSAN: data-race in dentry_kill / lockref_put_return
Status:
moderation: reported on 2026/11/18 02:44
Subsystems:
fs
Labels:
race:benign
prio:low
[Documentation on labels]
Reported-by: syzbot+ef5941ce3fbbd4b5f7d8@syzkaller.appspotmail.com
First crash: 1d10h, last: 19h45m
✨ AI-generated root cause summary:
KCSAN reported a data race between an unmarked 4-byte decrement of a parent dentry's reference count (--parent->d_lockref.count) in dentry_kill() under parent->d_lock and an optimistic, lockless 8-byte READ_ONCE(lockref->lock_count) in CMPXCHG_LOOP called via fast_dput() -> lockref_put_return(). On 64-bit SMP systems with USE_CMPXCHG_LOCKREF, struct lockref unions the 64-bit lock_count with the 32-bit spinlock lock and 32-bit count. Because the write to count in dentry_kill() is a plain (unmarked) C read-modify-write without WRITE_ONCE(), KCSAN flags concurrent overlapping access with the lockless 8-byte marked read as a data race under C memory model rules. However, because parent->d_lock is held throughout the decrement and released with release semantics, the optimistic cmpxchg loop either observes the spinlock as locked (immediately failing and falling back to the locked path) or fails the 64-bit cmpxchg comparison, making this race functionally benign.
▶
▼
✨ Full AI root cause analysis
Technical Analysis of KCSAN Bug Report: Data Race in dentry_kill / lockref_put_return
1. Functions, Structs, and Files Involved
2. Race Condition Mechanism and Triggering Sequence
The race is triggered when one task drops a reference to a dentry locklessly while another task kills one of that dentry's children and updates the parent's refcount under parent->d_lock:
-
Task 3695 (CPU 0) – dentry_kill slow path (fs/dcache.c:868-878):
-
Task 3692 (CPU 1) – fast_dput -> lockref_put_return (fs/dcache.c:970, lib/lockref.c:92):
- Concurrently, Task 3692 drops its reference to the same
parent dentry (e.g. from vfs_statx -> path_put -> dput).
fast_dput() invokes lockref_put_return(&dentry->d_lockref), which executes CMPXCHG_LOOP:
old.lock_count = READ_ONCE(lockref->lock_count);
while (likely(arch_spin_value_unlocked(old.lock.rlock.raw_lock))) {
struct lockref new = old;
new.count--;
if (old.count <= 0)
return -1;
if (likely(try_cmpxchg64_relaxed(&lockref->lock_count,
&old.lock_count,
new.lock_count))) {
return new.count;
}
if (!--retry)
break;
}
- At line 15 of
lib/lockref.c, Task 3692 issues an 8-byte marked read READ_ONCE(lockref->lock_count) starting at offset +0 (0xffff8881058a8740).
-
KCSAN Flagging:
- KCSAN sets a watchpoint covering the 8-byte range
0xffff8881058a8740–0xffff8881058a8748 during Task 3692's READ_ONCE.
- Task 3695 executes the unmarked write to
parent->d_lockref.count at 0xffff8881058a8744 (within the watched range).
- Because Task 3692 does not hold
parent->d_lock, the two tasks do not share a common synchronization lock from the perspective of KCSAN's lockset/happens-before tracker. Under the formal C/LKMM model, an unmarked write racing concurrently with a read to overlapping bytes is classified as a data race.
3. Correctness & Invariant Verification
Despite KCSAN's report, this race is functionally safe on hardware and represents the intended design of optimistic lockref concurrency:
- Lock Protection During Decrement: Task 3695 holds
parent->d_lock (with acquire ordering upon lock entry) while executing --parent->d_lockref.count, and releases it via spin_unlock(&parent->d_lock) with release ordering.
- Cmpxchg Safeguards:
- If Task 3692 executes
READ_ONCE(lockref->lock_count) while Task 3695 holds parent->d_lock, the lower 32-bit field (old.lock) contains a non-zero (locked) value. The condition arch_spin_value_unlocked(old.lock.rlock.raw_lock) evaluates to false. The cmpxchg loop terminates without executing, returning -1. In fast_dput(), this causes Task 3692 to fall back to the slow path (spin_lock(&dentry->d_lock)), correctly synchronizing behind Task 3695.
- If Task 3692 reads
lock_count before Task 3695 acquires the spinlock, Task 3695 then acquires parent->d_lock and updates count. When Task 3692 reaches try_cmpxchg64_relaxed(), the 64-bit atomic comparison compares lockref->lock_count in memory against old.lock_count. Because the lock state (and count) has changed, the cmpxchg fails, reloading old.lock_count with the updated, locked state.
- Therefore, no reference count corruption, tear, or lost decrement can occur.
Sample crash report:
* Struck through repros no longer work on HEAD.