syzbot
KCSAN: data-race in dentry_kill / lockref_get_not_dead
Status:
moderation: reported on 2026/11/17 06:24
Subsystems:
fs
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+e9e7603aef221419e3ee@syzkaller.appspotmail.com
First crash: 4h56m, last: 4h56m
✨ AI-generated root cause summary:
A KCSAN data race is flagged between lockref_get_not_dead() in lib/lockref.c and dentry_kill() in fs/dcache.c. During an RCU-walk unlazy operation, lockref_get_not_dead() invokes CMPXCHG_LOOP to optimistically read the 8-byte lockref->lock_count (aliasing spinlock_t lock and int count) via READ_ONCE without holding the lock. Concurrently, dentry_kill() decrements parent->d_lockref.count via an unmarked 4-byte read-modify-write (--parent->d_lockref.count) while holding parent->d_lock. Because the lockless 8-byte read overlaps the concurrent unmarked 4-byte write, KCSAN detects a data race, even though the operation is benign due to lockref's lock-checking validation and fallback to spin_lock.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Involved Structures, Functions, and Source Files
2. Triggering Mechanism and Race Sequence
-
Reader Path (lockref_get_not_dead in task 4498):
-
Writer Path (dentry_kill in task 3284):
-
KCSAN Detection:
- KCSAN observes an 8-byte marked read (
READ_ONCE(lockref->lock_count)) on CPU 0 overlapping an unmarked 4-byte read-modify-write (--parent->d_lockref.count) on CPU 1.
- Because plain C read-modify-writes (
--parent->d_lockref.count) do not carry WRITE_ONCE() or atomic annotations, KCSAN flags the concurrent access as a data race.
3. Correctness and Synchronization Analysis (Benign Data Race)
This data race is benign by design of the lockref subsystem:
- When task 3284 executes
--parent->d_lockref.count, it holds parent->d_lock (parent->d_lockref.lock).
- If task 4498's
READ_ONCE(lockref->lock_count) runs while parent->d_lock is held by task 3284:
old.lock contains the locked state (arch_spin_value_unlocked(old.lock.rlock.raw_lock) evaluates to 0).
- The
while loop condition fails immediately; CMPXCHG_LOOP terminates without performing try_cmpxchg64_relaxed() and without using any potentially torn or in-transition counter value.
lockref_get_not_dead() falls back to spin_lock(&lockref->lock), which properly blocks until task 3284 releases parent->d_lock, ensuring strict serialization.
- If task 4498's
READ_ONCE(lockref->lock_count) runs before task 3284 acquires the lock, old.lock reflects an unlocked state. However, before task 4498 can execute try_cmpxchg64_relaxed(), task 3284 acquires the lock. The 64-bit cmpxchg instruction will then compare old.lock_count (which has the unlocked lock value) against current memory (which has the locked spinlock value). The comparison fails, old.lock_count is reloaded with the locked state, and execution falls back to taking the spinlock.
- Consequently, reference counts cannot be corrupted, dentries cannot be freed prematurely, and execution behavior in real-world setups is fully preserved.
Sample crash report:
* Struck through repros no longer work on HEAD.