1. Root Cause Analysis
The reported Kernel Concurrency Sanitizer (KCSAN) data race occurs on the 4-byte d_flags field of struct dentry between __follow_mount_rcu() in fs/namei.c and maybe_free_mountpoint() in fs/namespace.c:
-
Reader side (task 12655, fs/namei.c:1714):
During RCU path walk (LOOKUP_RCU), the kernel executes step_into() -> step_into_slowpath() -> handle_mounts() -> __follow_mount_rcu(). When following mounts across mountpoints (or stacked mounts where the target is a mount's root mounted->mnt.mnt_root), __follow_mount_rcu() samples dentry->d_flags (flags = dentry->d_flags;) without acquiring dentry->d_lock and without using concurrency-marking primitives such as READ_ONCE() or data_race().
-
Writer side (task 12654, fs/namespace.c:979):
Concurrently, another task is performing a mount operation via do_mount() -> path_mount() -> do_new_mount() -> do_new_mount_fc(). While locking the mount target, do_lock_mount() calls get_mountpoint(), which attaches a pinned mountpoint (d_set_mounted(dentry) sets dentry->d_flags |= DCACHE_MOUNTED). When do_new_mount_fc() completes or fails (e.g., do_add_mount() error) and cleans up via __cleanup(unlock_mount) -> unlock_mount() -> __unlock_mount() -> unpin_mountpoint(), it invokes maybe_free_mountpoint(). Because no mounts remain attached to this mountpoint structure, it clears the flag:
spin_lock(&dentry->d_lock);
dentry->d_flags &= ~DCACHE_MOUNTED;
spin_unlock(&dentry->d_lock);
This is a plain read-modify-write on dentry->d_flags while holding dentry->d_lock and read_seqlock_excl(&mount_lock).
Because the read in __follow_mount_rcu() is neither locked nor annotated with READ_ONCE(), KCSAN flags the concurrent unsynchronized access as a data race.
2. Runtime Consequences in Production Builds
In a production kernel without debugging sanitizers (KCSAN, KASAN, etc.):
-
Memory Corruption (false):
The accessed dentry->d_flags field is a 32-bit naturally aligned integer. On all supported architectures, single-word aligned reads and writes are atomic with respect to word tearing.
-
Denial of Service (false):
The value read into flags in __follow_mount_rcu() is only tested for specific bit flags (DCACHE_MANAGE_TRANSIT, DCACHE_MOUNTED, and DCACHE_NEED_AUTOMOUNT). Furthermore, all mount tree mutations in __unlock_mount() occur under read_seqlock_excl(&mount_lock). If __follow_mount_rcu() reads a stale or changing state of dentry->d_flags, it immediately verifies the mount generation sequence via read_seqretry(&mount_lock, nd->m_seq). If any modification occurred, __follow_mount_rcu() returns false, gracefully aborting RCU-walk mode and falling back to ref-walk mode via try_to_unlazy_next() / traverse_mounts(). No deadlocks, panics, or hangs occur.
-
Information Leak ("none"):
No uninitialized data or kernel pointers are exposed or leaked to userspace.
-
Candidate Classifications (IsNetCandidate = false, IsKVMCandidate = false):
The bug is entirely contained within the VFS path lookup and namespace mounting subsystems (fs/namei.c and fs/namespace.c).