From: AnonymeMeow <anonymemeow@gmail.com>
To: amir73il@gmail.com
Cc: brauner@kernel.org, jack@suse.cz, repnop@google.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
AnonymeMeow <anonymemeow@gmail.com>
Subject: [PATCH v3 2/2] fanotify: allow reporting pidfds for reaped tasks
Date: Sat, 30 May 2026 09:37:32 +0800 [thread overview]
Message-ID: <20260530013732.50811-3-anonymemeow@gmail.com> (raw)
In-Reply-To: <20260530013732.50811-1-anonymemeow@gmail.com>
Fanotify used to refuse to report pidfds for reaped tasks by applying a
pid_has_task() check before calling pidfd_prepare(). This prevented
userspace from obtaining information about the task.
Fanotify events already hold a reference to the task's pid struct, so
the check can be safely dropped and pidfds can be reported for reaped
tasks as well.
Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
fs/notify/fanotify/fanotify_user.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index ebdd48942029..b604e3da58ad 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -904,20 +904,12 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
metadata.fd = fd >= 0 ? fd : FAN_NOFD;
if (pidfd_mode) {
- unsigned int tid_mode = FAN_GROUP_FLAG(group, FAN_REPORT_TID);
- enum pid_type pidtype = tid_mode ? PIDTYPE_PID : PIDTYPE_TGID;
- unsigned int pidfd_flags = tid_mode ? PIDFD_THREAD : 0;
+ unsigned int pidfd_flags = PIDFD_STALE;
- /*
- * The pid_has_task() check for an event->pid is performed
- * preemptively in an attempt to catch out cases where the event
- * listener reads events after the event generating task has
- * already terminated. Depending on flag FAN_REPORT_FD_ERROR,
- * report either -ESRCH or FAN_NOPIDFD to the event listener in
- * those cases with all other pidfd creation errors reported as
- * the error code itself or as FAN_EPIDFD.
- */
- if (metadata.pid && pid_has_task(event->pid, pidtype))
+ if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
+ pidfd_flags |= PIDFD_THREAD;
+
+ if (metadata.pid)
pidfd = pidfd_prepare(event->pid, pidfd_flags, &pidfd_file);
if (!FAN_GROUP_FLAG(group, FAN_REPORT_FD_ERROR) && pidfd < 0)
--
2.54.0
next prev parent reply other threads:[~2026-05-30 1:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 1:37 [PATCH v3 0/2] fanotify: lift pidfd reporting restrictions AnonymeMeow
2026-05-30 1:37 ` [PATCH v3 1/2] fanotify: report thread pidfds for FAN_REPORT_TID AnonymeMeow
2026-05-30 13:51 ` Amir Goldstein
2026-05-30 1:37 ` AnonymeMeow [this message]
2026-05-30 13:51 ` [PATCH v3 2/2] fanotify: allow reporting pidfds for reaped tasks Amir Goldstein
2026-05-30 10:51 ` [RFC][PATCH] fanotify: register event pid for pidfd reporting AnonymeMeow
2026-06-01 15:24 ` Jan Kara
2026-06-02 13:50 ` Christian Brauner
2026-06-08 9:27 ` Jan Kara
2026-06-08 12:30 ` Jan Kara
2026-06-10 7:33 ` Christian Brauner
2026-06-08 10:53 ` [PATCH v3 0/2] fanotify: lift pidfd reporting restrictions Jan Kara
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=20260530013732.50811-3-anonymemeow@gmail.com \
--to=anonymemeow@gmail.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=repnop@google.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®