* [PATCH] proc: use pid_has_task() in proc_inode_is_dead()
@ 2026-12-02 17:52 Jiayi Zhang
2026-12-03 9:22 ` Oleg Nesterov
0 siblings, 1 reply; 2+ messages in thread
From: Jiayi Zhang @ 2026-12-02 17:52 UTC (permalink / raw)
To: Christian Brauner, Andrew Morton
Cc: Oleg Nesterov, linux-fsdevel, linux-kernel,
syzbot+d608d486bd3b7062bafc, syzkaller-bugs
proc_inode_is_dead() tests whether the pid still has a task by reading
pid->tasks[PIDTYPE_PID].first with a plain load. The list is changed
with RCU list operations when the task is released, so the read races
with detach_pid() when a /proc/<pid> dentry is put while the task is
released. KCSAN reports:
BUG: KCSAN: data-race in detach_pid / pid_delete_dentry
write (marked) to 0xffff888101d47270 of 8 bytes by task 6239 on cpu 0:
__hlist_del include/linux/list.h:1045 [inline]
hlist_del_rcu include/linux/rculist.h:599 [inline]
__change_pid kernel/pid.c:413 [inline]
detach_pid+0xb1/0x1a0 kernel/pid.c:426
__unhash_process kernel/exit.c:141 [inline]
__exit_signal kernel/exit.c:206 [inline]
release_task+0x67e/0xba0 kernel/exit.c:267
read to 0xffff888101d47270 of 8 bytes by task 7384 on cpu 1:
proc_inode_is_dead fs/proc/base.c:2067 [inline]
pid_delete_dentry+0x30/0x50 fs/proc/base.c:2076
retain_dentry fs/dcache.c:913 [inline]
finish_dput+0xd8/0x1d0 fs/dcache.c:1033
dput+0x43/0x50 fs/dcache.c:1073
proc_invalidate_siblings_dcache+0x1e6/0x2c0 fs/proc/inode.c:143
The race does not cause a functional problem. If the reader still sees
the task, pid_delete_dentry() keeps the dentry, and pid_revalidate() or
proc_flush_pid() drops it later. proc_task_readdir() uses the same
helper and can at worst list an empty directory once, as noted in
commit d855a4b79f49 ("proc: don't (ab)use ->group_leader in
proc_task_readdir() paths").
Use pid_has_task(), the helper other lockless callers use for this
check. It tests the list with hlist_empty(), which reads the head with
READ_ONCE().
Fixes: 13b41b09491e ("[PATCH] proc: Use struct pid not struct task_ref")
Reported-by: syzbot+d608d486bd3b7062bafc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d608d486bd3b7062bafc
Signed-off-by: Jiayi Zhang <zhangjiayi1014@gmail.com>
---
The syzbot report is still in moderation and has not been sent to the
lists; the Closes: link shows it.
Tested in QEMU with a test program that forks short-lived children
while other threads stat, open and read /proc/<pid> of those children
(KCSAN report filter set to these functions): without the patch 2 of 5
instances reported the race within 10 minutes; with the patch none of
10 instances did (two of them stopped earlier with an RCU stall from
the load, which also happened without the patch). The kernel was
fe6ff8d5d675; fs/proc/base.c there is the same as on master.
AI tools assisted with the analysis, the code and the changelog.
fs/proc/base.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7685660..c40b47a 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2064,7 +2064,7 @@ out:
static inline bool proc_inode_is_dead(struct inode *inode)
{
- return !proc_pid(inode)->tasks[PIDTYPE_PID].first;
+ return !pid_has_task(proc_pid(inode), PIDTYPE_PID);
}
int pid_delete_dentry(const struct dentry *dentry)
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] proc: use pid_has_task() in proc_inode_is_dead()
2026-12-02 17:52 [PATCH] proc: use pid_has_task() in proc_inode_is_dead() Jiayi Zhang
@ 2026-12-03 9:22 ` Oleg Nesterov
0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2026-12-03 9:22 UTC (permalink / raw)
To: Jiayi Zhang
Cc: Christian Brauner, Andrew Morton, linux-fsdevel, linux-kernel,
syzbot+d608d486bd3b7062bafc, syzkaller-bugs
On 12/02, Jiayi Zhang wrote:
>
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -2064,7 +2064,7 @@ out:
>
> static inline bool proc_inode_is_dead(struct inode *inode)
> {
> - return !proc_pid(inode)->tasks[PIDTYPE_PID].first;
> + return !pid_has_task(proc_pid(inode), PIDTYPE_PID);
> }
The same change is alredy in Christian' tree, see
[PATCH] proc: use pid_has_task() in proc_inode_is_dead()
https://lore.kernel.org/all/atObuVZXbl9n-zFq@redhat.com/
Oleg.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 9:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 17:52 [PATCH] proc: use pid_has_task() in proc_inode_is_dead() Jiayi Zhang
2026-12-03 9:22 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox