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 v4] selftests/pidfd: wait for POLLHUP before reading exit info
Date: Tue, 20 Oct 2026 15:45:18 -0400 [thread overview]
Message-ID: <179252551833.59967.12617794775210688694@gmail.com> (raw)
In-Reply-To: <atc59R5-oBnyOIb8@redhat.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.
The zero-timeout liveness check in autokill_pidfd_open_no_effect keeps
POLLIN; it verifies that the child has not exited yet.
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 | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/tools/testing/selftests/pidfd/pidfd_autoreap_test.c b/tools/testing/selftests/pidfd/pidfd_autoreap_test.c
index 1c586482f..59bf9b5b3 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);
@@ -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
next prev parent reply other threads:[~2026-10-20 19:46 UTC|newest]
Thread overview: 12+ 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-18 16:30 ` Oleg Nesterov
2026-10-17 19:23 ` [PATCH v2] selftests/pidfd: wait for POLLHUP before reading exit info fujo
2026-10-18 16:25 ` Oleg Nesterov
2026-10-18 16:48 ` [PATCH v3] " fujo
2026-10-20 9:52 ` Oleg Nesterov
2026-10-20 19:45 ` fujo
2026-10-20 19:45 ` fujo [this message]
2026-10-18 16:48 ` [PATCH v2] " fujo
2026-10-18 19:27 ` Oleg Nesterov
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=179252551833.59967.12617794775210688694@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®