syzbot
KCSAN: data-race in detach_pid / pid_delete_dentry
Status:
moderation: reported on 2026/11/18 00:04
Subsystems:
kernel
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+d608d486bd3b7062bafc@syzkaller.appspotmail.com
First crash: 1h49m, last: 1h49m
✨ AI-generated root cause summary:
In fs/proc/base.c, proc_inode_is_dead() open-codes the check for whether a PID has active tasks by performing a plain, unmarked read of proc_pid(inode)->tasks[PIDTYPE_PID].first without holding tasklist_lock. Concurrently, when a task is reaped (e.g., via release_task() -> __exit_signal() -> detach_pid()), __hlist_del() modifies this pointer using a marked write (WRITE_ONCE). Because proc_inode_is_dead() does not use !pid_has_task() or hlist_empty() (which perform a READ_ONCE), KCSAN reports a data race between detach_pid() and pid_delete_dentry().
▶
▼
✨ Full AI root cause analysis
Technical Analysis of KCSAN Data-Race in detach_pid / pid_delete_dentry
1. Functions, Structs, and Files Involved
- Write side:
- File:
kernel/pid.c, include/linux/list.h, kernel/exit.c
- Functions:
release_task() $\to$ __exit_signal() $\to$ __unhash_process() $\to$ detach_pid() $\to$ __change_pid() $\to$ hlist_del_rcu() $\to$ __hlist_del()
- Field:
pid->tasks[PIDTYPE_PID].first (a struct hlist_node * within struct pid).
- Read side:
- File:
fs/proc/base.c, fs/dcache.c
- Functions:
dput() $\to$ finish_dput() $\to$ retain_dentry() $\to$ pid_delete_dentry() $\to$ proc_inode_is_dead() (also called from proc_task_readdir())
- Field:
proc_pid(inode)->tasks[PIDTYPE_PID].first.
2. Root Cause and Mechanism
-
Write Path (detach_pid):
When a task is reaped (e.g., via wait4() calling wait_task_zombie() $\to$ release_task()), release_task() acquires write_lock_irq(&tasklist_lock) and calls __exit_signal(). In __unhash_process(), the task's thread PID is detached via detach_pid(post->pids, p, PIDTYPE_PID), which calls __change_pid().
__change_pid() removes the task's link using hlist_del_rcu(&task->pid_links[type]). In __hlist_del(), the list head pointer is cleared via:
WRITE_ONCE(*pprev, next);
When the detached task is the head of the list, *pprev points to pid->tasks[PIDTYPE_PID].first. This write is explicitly marked with WRITE_ONCE.
-
Read Path (pid_delete_dentry):
In procfs, dentries representing /proc/<pid> or its descendants use pid_dentry_operations, where .d_delete is assigned to pid_delete_dentry().
When any dentry is released via dput() (for instance, when unhashing dentries during proc_flush_pid() or on standard file close / dentry eviction), finish_dput() invokes retain_dentry(), which checks dentry->d_op->d_delete(dentry):
int pid_delete_dentry(const struct dentry *dentry)
{
return proc_inode_is_dead(d_inode(dentry));
}
In fs/proc/base.c:
static inline bool proc_inode_is_dead(struct inode *inode)
{
return !proc_pid(inode)->tasks[PIDTYPE_PID].first;
}
retain_dentry() and pid_delete_dentry() execute without holding tasklist_lock.
-
The Invariant / Concurrency Violation:
proc_inode_is_dead() reads proc_pid(inode)->tasks[PIDTYPE_PID].first using a plain, unmarked memory access.
Everywhere else in the kernel where lockless checks for active tasks on a struct pid are performed (such as pidfd_show_fdinfo(), show_timer(), posix cpu timers, or pidfd_prepare()), the kernel uses:
pid_has_task(pid, type);
defined in include/linux/pid.h:
static inline bool pid_has_task(struct pid *pid, enum pid_type type)
{
return !hlist_empty(&pid->tasks[type]);
}
which invokes hlist_empty() (include/linux/list.h):
static inline int hlist_empty(const struct hlist_head *h)
{
return !READ_ONCE(h->first);
}
Because proc_inode_is_dead() open-codes the empty check rather than calling !pid_has_task(proc_pid(inode), PIDTYPE_PID) (or using READ_ONCE()), an unmarked read races with the concurrent WRITE_ONCE() in detach_pid(), triggering the KCSAN data-race report.
Sample crash report:
* Struck through repros no longer work on HEAD.