From: fujo <hooyan2024@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: Oleg Nesterov <oleg@redhat.com>,
Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] selftests/pidfd: wait for POLLHUP before reading exit info
Date: Sat, 17 Oct 2026 15:23:10 -0400 [thread overview]
Message-ID: <179226499044.847.17334319321039510150@gmail.com> (raw)
In-Reply-To: <20261017054356.7874-1-hooyan2024@gmail.com>
The CLONE_AUTOREAP tests poll for POLLIN and then immediately call
PIDFD_GET_INFO with PIDFD_INFO_EXIT. PIDFD_INFO_EXIT is only published
from release_task() -> pidfs_exit(), which runs after the pidfd already
reported POLLIN for the exited task. A poller woken by
do_notify_pidfd() can therefore read a mask without PIDFD_INFO_EXIT;
under KASAN the autoreap_multithreaded case fails this way.
POLLHUP is returned once the task linkage has been removed from
struct pid, which happens after pidfs_exit() has published the exit
information. Wait for POLLHUP and check it in revents.
With this change all tests pass ten consecutive runs on an unpatched
kernel.
Signed-off-by: fujo <hooyan2024@gmail.com>
---
.../selftests/pidfd/pidfd_autoreap_test.c | 36 +++++++++----------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/pidfd/pidfd_autoreap_test.c b/tools/testing/selftests/pidfd/pidfd_autoreap_test.c
index 1c586482f..b4f3699ef 100644
--- a/tools/testing/selftests/pidfd/pidfd_autoreap_test.c
+++ b/tools/testing/selftests/pidfd/pidfd_autoreap_test.c
@@ -149,7 +149,7 @@ TEST(autoreap_rejects_thread)
/*
* Basic test: create an autoreap child, let it exit, verify:
- * - pidfd becomes readable (poll returns POLLIN)
+ * - pidfd becomes readable (poll returns POLLHUP)
* - PIDFD_GET_INFO returns the correct exit code
* - waitpid() returns -1/ECHILD (no zombie)
*/
@@ -172,10 +172,10 @@ TEST(autoreap_basic)
/* Wait for the child to exit via pidfd poll. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
- ASSERT_TRUE(pfd.revents & POLLIN);
+ ASSERT_TRUE(pfd.revents & POLLHUP);
/* Verify exit info via PIDFD_GET_INFO. */
ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
@@ -225,10 +225,10 @@ TEST(autoreap_signaled)
/* Wait for exit via pidfd. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
- ASSERT_TRUE(pfd.revents & POLLIN);
+ ASSERT_TRUE(pfd.revents & POLLHUP);
/* Verify signal info. */
ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
@@ -334,10 +334,10 @@ TEST(autoreap_reparent)
/* Wait for it to exit via pidfd poll. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
- ASSERT_TRUE(pfd.revents & POLLIN);
+ ASSERT_TRUE(pfd.revents & POLLHUP);
/*
* The grandchild should have been autoreaped even though
@@ -421,10 +421,10 @@ TEST(autoreap_multithreaded)
/* Wait for the process to fully exit via pidfd poll. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
- ASSERT_TRUE(pfd.revents & POLLIN);
+ ASSERT_TRUE(pfd.revents & POLLHUP);
/* Verify exit info. */
ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
@@ -512,7 +512,7 @@ TEST(autoreap_no_inherit)
/* Wait for the autoreap child to exit. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
@@ -571,7 +571,7 @@ TEST(nnp_sets_no_new_privs)
/* Wait for child to exit. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
@@ -631,7 +631,7 @@ TEST(autoreap_no_new_privs_unset)
ASSERT_GE(pidfd, 0);
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
@@ -695,10 +695,10 @@ TEST(autokill_basic)
/* Wait for the child to die via the pidfd_open'd fd. */
pfd.fd = pollfd_fd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
- ASSERT_TRUE(pfd.revents & POLLIN);
+ ASSERT_TRUE(pfd.revents & POLLHUP);
/* Child should be autoreaped — no zombie. */
usleep(100000);
@@ -799,7 +799,7 @@ TEST(autokill_pidfd_open_no_effect)
/* Verify child is still alive by polling the clone3 pidfd. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 0);
ASSERT_EQ(ret, 0) {
TH_LOG("Child died after closing pidfd_open fd — should still be alive");
@@ -813,10 +813,10 @@ TEST(autokill_pidfd_open_no_effect)
close(pidfd);
pfd.fd = open_fd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
- ASSERT_TRUE(pfd.revents & POLLIN);
+ ASSERT_TRUE(pfd.revents & POLLHUP);
/* Child should be autoreaped — no zombie. */
usleep(100000);
@@ -884,7 +884,7 @@ TEST(autokill_without_nnp_with_cap)
/* Wait for child to exit. */
pfd.fd = pidfd;
- pfd.events = POLLIN;
+ pfd.events = POLLHUP;
ret = poll(&pfd, 1, 5000);
ASSERT_EQ(ret, 1);
--
2.53.0
prev parent reply other threads:[~2026-10-17 19:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 5:43 [RFC PATCH] pidfs: don't report autoreaped tasks readable before exit info exists fujo
2026-10-17 13:48 ` Oleg Nesterov
2026-10-17 19:23 ` fujo
2026-10-17 19:23 ` fujo [this message]
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=179226499044.847.17334319321039510150@gmail.com \
--to=hooyan2024@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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®