Technical Root Cause Analysis
1. Functions, Structs, and Fields Involved
2. Mechanism and Lifecycle Violation
In the VFS directory cache subsystem, dentry->d_flags is a shared 32-bit integer that stores two distinct categories of bitflags:
- Static / Immutable Operation Flags: Flags such as
DCACHE_OP_HASH (BIT(0)), DCACHE_OP_COMPARE (BIT(1)), DCACHE_OP_REVALIDATE (BIT(2)), etc. These are assigned at dentry allocation/initialization time (__d_alloc() via sb->s_d_flags or d_set_d_op()) before the dentry is published, reflecting filesystem-specific operations (d_op). Once published, these bits are immutable for the lifetime of the dentry.
- Dynamic / Mutable State Flags: Flags such as
DCACHE_MOUNTED (BIT(15)), DCACHE_LRU_LIST (BIT(18)), DCACHE_REFERENCED (BIT(6)), DCACHE_CANT_MOUNT (BIT(8)), etc., which are updated at runtime under dentry->d_lock.
The data race is triggered by the following sequence:
-
Task 7833 (Read): While resolving a pathname in link_path_walk() (e.g. during an openat syscall), the task traverses path components. When processing a normal path component, it accesses the current directory dentry (struct dentry *parent = nd->path.dentry;) locklessly without holding parent->d_lock (to avoid high contention during path traversal). At fs/namei.c:2632, it checks whether the filesystem implements a custom hashing callback:
if (unlikely(parent->d_flags & DCACHE_OP_HASH)) {
err = parent->d_op->d_hash(parent, &nd->last);
...
}
This is executed as a plain C read (testl $1, (%rax)).
-
Task 7827 (Write): Concurrently, another thread calls mount() targeting that directory dentry. In d_set_mounted() (fs/dcache.c:1653), the task holds dentry->d_lock and marks the dentry as a mountpoint:
dentry->d_flags |= DCACHE_MOUNTED;
This is executed as a plain C read-modify-write (orl $0x8000, (%rdi)).
Because both immutable flags (DCACHE_OP_HASH) and mutable state flags (DCACHE_MOUNTED) occupy the same 32-bit word, and neither the read in link_path_walk() nor the write in d_set_mounted() uses marked memory accesses (READ_ONCE() / WRITE_ONCE() or data_race()), KCSAN flags this concurrent unannotated read and write to the same 4-byte memory address (0xffff8881004103c0) as a data race under the Linux Kernel Memory Model.