From: Jiayi Zhang <zhangjiayi1014@gmail.com>
To: Christian Brauner <brauner@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+d608d486bd3b7062bafc@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com
Subject: [PATCH] proc: use pid_has_task() in proc_inode_is_dead()
Date: Wed, 2 Dec 2026 17:52:10 +0000 [thread overview]
Message-ID: <20261202175210.4123870-1-zhangjiayi1014@gmail.com> (raw)
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
next reply other threads:[~2026-12-02 17:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 17:52 Jiayi Zhang [this message]
2026-12-03 9:22 ` Oleg Nesterov
2026-12-03 10:32 ` Jiayi Zhang
-- strict thread matches above, loose matches on Subject: below --
2026-10-17 16:00 Oleg Nesterov
2026-10-21 14:01 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202175210.4123870-1-zhangjiayi1014@gmail.com \
--to=zhangjiayi1014@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=syzbot+d608d486bd3b7062bafc@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®