Root Cause
The data race is caused by an unmarked read of inodes->first in proc_invalidate_siblings_dcache() (fs/proc/inode.c:114):
rcu_read_lock();
while ((node = hlist_first_rcu(inodes))) {
struct proc_inode *ei = hlist_entry(node, struct proc_inode, sibling_inodes);
...
spin_lock(lock);
hlist_del_init_rcu(&ei->sibling_inodes);
spin_unlock(lock);
In include/linux/rculist.h:649, hlist_first_rcu() is defined as an lvalue/pointer expression rather than an RCU load primitive:
#define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first)))
It is meant to be passed to rcu_dereference() / rcu_dereference_raw() (for reads) or rcu_assign_pointer() (for writes). Calling hlist_first_rcu(inodes) directly without rcu_dereference() and without holding lock performs a plain, unmarked read of inodes->first.
Triggering Mechanism
- Multiple
struct proc_inode directory entries associated with a struct pid (e.g., /proc/<tgid> or /proc/<tgid>/task/<tid>) are linked into pid->inodes via ei->sibling_inodes (proc_pid_make_base_inode() in fs/proc/base.c:1991), protected by pid->lock.
- During task teardown (
release_task() -> proc_flush_pid() in fs/proc/base.c:3457), proc_invalidate_siblings_dcache(&pid->inodes, &pid->lock) is called to invalidate and drop cached dentries for all sibling proc inodes on pid->inodes.
- Concurrently, another task evicts a proc directory inode referencing the same
pid (in this trace, task 6951 in proc_invalidate_siblings_dcache() -> dput(dir) triggers parent dentry/inode eviction down to proc_evict_inode() -> proc_pid_evict_inode() in fs/proc/base.c:1918). proc_pid_evict_inode() acquires spin_lock(&pid->lock) and calls hlist_del_init_rcu(&ei->sibling_inodes) -> __hlist_del() (include/linux/list.h:1045), which updates *pprev (pid->inodes.first when deleting the head element) via WRITE_ONCE(*pprev, next).
- At the same time, task 5112 (in
wait_task_zombie() -> release_task() -> proc_flush_pid() -> proc_invalidate_siblings_dcache()) reads pid->inodes.first via the unmarked hlist_first_rcu(inodes) at fs/proc/inode.c:114 without holding pid->lock, causing KCSAN to report a data race between the marked write in __hlist_del() and the unmarked read in proc_invalidate_siblings_dcache(). (The same pattern also applies to proc_sys_invalidate_dcache() / proc_sys_evict_inode() in fs/proc/proc_sysctl.c using sysctl_lock.)
Invariant / Fix Context
proc_invalidate_siblings_dcache() holds rcu_read_lock() across the list-head read until after igrab(&ei->vfs_inode), and proc_inode is freed via RCU (destroy_inode() -> call_rcu(&inode->i_rcu, i_callback) -> proc_free_inode()), while list mutations are serialized by spin_lock(lock). Using rcu_dereference(hlist_first_rcu(inodes)) (or reading inodes->first inside spin_lock(lock) directly, as the loop already acquires lock on every iteration) eliminates the unmarked read and satisfies RCU/KCSAN rules.