fanotify: lift pidfd reporting restrictions
Subsystems (3)
v3 cover fanotify: lift pidfd reporting restrictions
The pidfd API now supports pidfds for tasks that are not thread group leaders, but fanotify has not caught up yet. This patch set lifts that restriction and allows fanotify to report pidfds referring the event-generating thread.
Additionally, this patch set drops the pid_has_task() check before the pidfd_prepare() call, allowing fanotify to hand out pidfds for reaped tasks, as suggested by Christian.
changes since v2:
- Split the two independent changes into separate patches.
v2: https://lore.kernel.org/lkml/[email protected]/
AnonymeMeow (2):
fanotify: report thread pidfds for FAN_REPORT_TID
fanotify: allow reporting pidfds for reaped tasks
fs/notify/fanotify/fanotify_user.c | 33 +++++++----------------------- 1 file changed, 7 insertions(+), 26 deletions(-)
Signature · 1 line
2.54.0
PATCH v3 1/2 fanotify: report thread pidfds for FAN_REPORT_TID
The FAN_REPORT_PIDFD and FAN_REPORT_TID flags used to be mutually exclusive because by the time the pidfd support was introduced to fanotify, pidfds could only be created for thread group leaders. Now that the pidfd API supports thread-specific pidfds via PIDFD_THREAD, this restriction can be lifted.
--- fs/notify/fanotify/fanotify_user.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
fs/notify/fanotify/fanotify_user.c +8 -19
@@ -19,6 +19,7 @@#include <linux/memcontrol.h> #include <linux/statfs.h> #include <linux/exportfs.h> +#include <linux/pidfd.h> #include <asm/ioctls.h>
@@ -903,25 +904,21 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, metadata.fd = fd >=0 ? fd :FAN_NOFD ;if (pidfd_mode) { -/* -* Complain if the FAN_REPORT_PIDFD and FAN_REPORT_TID mutual -* exclusion is ever lifted. At the time of incoporating pidfd -* support within fanotify, the pidfd API only supported the -* creation of pidfds for thread-group leaders. -*/ -WARN_ON_ONCE (FAN_GROUP_FLAG (group,FAN_REPORT_TID )); +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 ;/* -* The PIDTYPE_TGID check for an event->pid is performed +* 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 process has +* 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_TGID )) - pidfd =pidfd_prepare (event->pid,0 , &pidfd_file); +if (metadata.pid &&pid_has_task (event->pid, pidtype)) + pidfd =pidfd_prepare (event->pid, pidfd_flags, &pidfd_file);if (!FAN_GROUP_FLAG (group,FAN_REPORT_FD_ERROR ) && pidfd <0 ) pidfd = pidfd == -ESRCH ?FAN_NOPIDFD :FAN_EPIDFD ;
@@ -1628,14 +1625,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)#endif return -EINVAL ; -/* -* A pidfd can only be returned for a thread-group leader; thus -* FAN_REPORT_PIDFD and FAN_REPORT_TID need to remain mutually -* exclusive. -*/ -if ((flags &FAN_REPORT_PIDFD ) && (flags &FAN_REPORT_TID )) -return -EINVAL ; -/* Don't allow mixing mnt events with inode events for now */ if (flags &FAN_REPORT_MNT ) {if (class !=FAN_CLASS_NOTIF )
Signature · 1 line
2.54.0
Re: [PATCH v3 1/2] fanotify: report thread pidfds for FAN_REPORT_TID
Quoted 8 lines · AnonymeMeow
The
FAN_REPORT_PIDFDandFAN_REPORT_TIDflags used to be mutually exclusive because by the time the pidfd support was introduced to fanotify, pidfds could only be created for thread group leaders. Now that the pidfd API supports thread-specific pidfds viaPIDFD_THREAD, this restriction can be lifted.Signed-off-by AnonymeMeow <[email protected]>
Thanks,
Amir.
Quoted 67 lines
--- fs/notify/fanotify/fanotify_user.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)fs/notify/fanotify/fanotify_user.c +8
-20@@ -19,6 +19,7 @@#include <linux/memcontrol.h> #include <linux/statfs.h> #include <linux/exportfs.h> +#include <linux/pidfd.h> #include <asm/ioctls.h> @@ -903,25 +904,21 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, metadata.fd = fd >=0 ? fd :FAN_NOFD ;if (pidfd_mode) { -/* -* Complain if the FAN_REPORT_PIDFD and FAN_REPORT_TID mutual -* exclusion is ever lifted. At the time of incoporating pidfd -* support within fanotify, the pidfd API only supported the -* creation of pidfds for thread-group leaders. -*/ -WARN_ON_ONCE (FAN_GROUP_FLAG (group,FAN_REPORT_TID )); +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 ;/* -* The PIDTYPE_TGID check for an event->pid is performed +* 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 process has +* 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_TGID )) - pidfd =pidfd_prepare (event->pid,0 , &pidfd_file); +if (metadata.pid &&pid_has_task (event->pid, pidtype)) + pidfd =pidfd_prepare (event->pid, pidfd_flags, &pidfd_file);if (!FAN_GROUP_FLAG (group,FAN_REPORT_FD_ERROR ) && pidfd <0 ) pidfd = pidfd == -ESRCH ?FAN_NOPIDFD :FAN_EPIDFD ;@@ -1628,14 +1625,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)#endif return -EINVAL ; -/* -* A pidfd can only be returned for a thread-group leader; thus -* FAN_REPORT_PIDFD and FAN_REPORT_TID need to remain mutually -* exclusive. -*/ -if ((flags &FAN_REPORT_PIDFD ) && (flags &FAN_REPORT_TID )) -return -EINVAL ; -/* Don't allow mixing mnt events with inode events for now */ if (flags &FAN_REPORT_MNT ) {if (class !=FAN_CLASS_NOTIF ) --2.54.0
PATCH v3 2/2 fanotify: allow reporting pidfds for reaped tasks
In reply to AnonymeMeowFanotify 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.
--- fs/notify/fanotify/fanotify_user.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
fs/notify/fanotify/fanotify_user.c +5 -13
@@ -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 )
Signature · 1 line
2.54.0
Re: [PATCH v3 2/2] fanotify: allow reporting pidfds for reaped tasks
Quoted 9 lines · AnonymeMeow
Fanotify used to refuse to report pidfds for reaped tasks by applying a
pid_has_task()check before callingpidfd_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.
I'd add:
So when people come shouting we know who to blame ;)
Quoted 1 line
Signed-off-by AnonymeMeow <[email protected]>
No need to post v4 just for adding those
Just add them if you happen to send v4 due some other review comments and anyway we need to wait for Jan to wait in on this change
Thanks,
Amir.
Quoted 37 lines
--- fs/notify/fanotify/fanotify_user.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)fs/notify/fanotify/fanotify_user.c +5
-14@@ -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
RFC PATCH 1/1 fanotify: register event pid for pidfd reporting
In reply to AnonymeMeowpidfd_prepare() may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, so pidfd_prepare() can later create a pidfd for the reaped task.
---
Hi, Christian,
I tested this patch set and found that fanotify still usually can not report pidfds for reaped tasks, because the event pid may not have been registered before it exits, and registering it after the task has been reaped is not allowed, so fanotify still fails to report a pidfd for the event.
This patch registers the event pid when the fanotify event is created. With this change, the current LTP fanotify21 test fails as expected.
But I do not know whether it is worth doing so to improve fanotify's ability to report pidfds for reaped tasks. And, what should fanotify do if pidfs_register_pid() fails? Should the error be reported to userspace through the pidfd info record, using the raw error when FAN_REPORT_FD_ERROR is set and FAN_EPIDFD otherwise? But the event struct in fanotify does not have spare space to store this error code. Or should it just ignore the failure here and let pidfd_prepare() fail later in copy_event_to_user()? I would appreciate your feedback.
With Best Regards,
AnonymeMeow
--- fs/notify/fanotify/fanotify.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/notify/fanotify/fanotify.c +10 -0
@@ -14,6 +14,7 @@#include <linux/sched/mm.h> #include <linux/statfs.h> #include <linux/stringhash.h> +#include <linux/pidfs.h> #include "fanotify.h"
@@ -868,6 +869,15 @@ static struct fanotify_event *fanotify_alloc_event(else pid =get_pid (task_tgid (current)); +if (FAN_GROUP_FLAG (group,FAN_REPORT_PIDFD )) { +int err =pidfs_register_pid (pid); +if (err) { +/* +* What to do here? Pass this err to userspace via pidfd? +*/ + } + } +/* Mix event info, FAN_ONDIR flag and pid into event merge key */ hash ^=hash_long ((unsigned long )pid | ondir,FANOTIFY_EVENT_HASH_BITS );fanotify_init_event (event, hash, mask);
Signature · 1 line
2.54.0
Jan Kara
maintainerRe: [RFC][PATCH] fanotify: register event pid for pidfd reporting
Quoted 7 lines · AnonymeMeow
pidfd_prepare()may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, sopidfd_prepare()can later create a pidfd for the reaped task.Signed-off-by AnonymeMeow <[email protected]>
So the two patches in this series so far look good to me. This patch looks OK to me as well and since the overhead of allocation etc. is only once per registered task, I think it's fine but let's wait a bit whether Christian agrees this is what needs to be done.
Honza
Quoted 62 lines
---
Hi, Christian,
I tested this patch set and found that fanotify still usually can not report pidfds for reaped tasks, because the event pid may not have been registered before it exits, and registering it after the task has been reaped is not allowed, so fanotify still fails to report a pidfd for the event.
This patch registers the event pid when the fanotify event is created. With this change, the current LTP fanotify21 test fails as expected.
But I do not know whether it is worth doing so to improve fanotify's ability to report pidfds for reaped tasks. And, what should fanotify do if
pidfs_register_pid()fails? Should the error be reported to userspace through the pidfd info record, using the raw error whenFAN_REPORT_FD_ERRORis set andFAN_EPIDFDotherwise? But the event struct in fanotify does not have spare space to store this error code. Or should it just ignore the failure here and letpidfd_prepare()fail later incopy_event_to_user()? I would appreciate your feedback.With Best Regards,
AnonymeMeow--- fs/notify/fanotify/fanotify.c | 10 ++++++++++ 1 file changed, 10 insertions(+)fs/notify/fanotify/fanotify.c +10
-0@@ -14,6 +14,7 @@#include <linux/sched/mm.h> #include <linux/statfs.h> #include <linux/stringhash.h> +#include <linux/pidfs.h> #include "fanotify.h" @@ -868,6 +869,15 @@ static struct fanotify_event *fanotify_alloc_event(else pid =get_pid (task_tgid (current)); +if (FAN_GROUP_FLAG (group,FAN_REPORT_PIDFD )) { +int err =pidfs_register_pid (pid); +if (err) { +/* +* What to do here? Pass this err to userspace via pidfd? +*/ + } + } +/* Mix event info, FAN_ONDIR flag and pid into event merge key */ hash ^=hash_long ((unsigned long )pid | ondir,FANOTIFY_EVENT_HASH_BITS );fanotify_init_event (event, hash, mask);Signature · 1 line
2.54.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [RFC][PATCH] fanotify: register event pid for pidfd reporting
Quoted 11 lines · Jan Kara
Quoted 7 lines · AnonymeMeow
pidfd_prepare()may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, sopidfd_prepare()can later create a pidfd for the reaped task.Signed-off-by AnonymeMeow <[email protected]>So the two patches in this series so far look good to me. This patch looks OK to me as well and since the overhead of allocation etc. is only once per
It's a kmem cache so should not matter at all...
Quoted 2 lines
registered task, I think it's fine but let's wait a bit whether Christian agrees this is what needs to be done.
pidfs_register_pid() can only fail with ENOMEM or if the task is already dead. The latter cannot happen because even for a non-empty thread group where the thread-group leader already exited but subthreads are still alive the thread-group leader cannot be reaped. So the only error here is ENOMEM which means we should defo fail this, imho.
And yes, I think this is worth doing. Because you get a persistent handle on the task that generated that event + all the exit information even if that thask has been reaped in the meantime. I'm pretty sure if you're using fanotify that's a rather huge win for apps that need it.
Jan Kara
maintainerRe: [RFC][PATCH] fanotify: register event pid for pidfd reporting
Quoted 24 lines · Christian Brauner
Quoted 11 lines · Jan Kara
Quoted 7 lines · AnonymeMeow
pidfd_prepare()may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, sopidfd_prepare()can later create a pidfd for the reaped task.Signed-off-by AnonymeMeow <[email protected]>So the two patches in this series so far look good to me. This patch looks OK to me as well and since the overhead of allocation etc. is only once per
It's a kmem cache so should not matter at all...
Quoted 2 lines
registered task, I think it's fine but let's wait a bit whether Christian agrees this is what needs to be done.
pidfs_register_pid()can only fail with ENOMEM or if the task is already dead. The latter cannot happen because even for a non-empty thread group where the thread-group leader already exited but subthreads are still alive the thread-group leader cannot be reaped. So the only error here is ENOMEM which means we should defo fail this, imho.
Quoted 4 lines
And yes, I think this is worth doing. Because you get a persistent handle on the task that generated that event + all the exit information even if that thask has been reaped in the meantime. I'm pretty sure if you're using fanotify that's a rather huge win for apps that need it.
OK, thanks for opinion. So I've somewhat massaged the error handling in the patch AnonymeMeow. Attached is what I currently have in my tree (testing pending).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
From f1d94103161de2b233193faeeeb933a2f3c5584a Mon Sep 17 00:00:00 2001
From: AnonymeMeow <[email protected]>
Date: Sat, 30 May 2026 18:51:17 +0800
Subject: [PATCH] fanotify: register event pid for pidfd reporting
pidfd_prepare() may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, so pidfd_prepare() can later create a pidfd for the reaped task.
[JK: Reworked error handling ]
--- fs/notify/fanotify/fanotify.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
fs/notify/fanotify/fanotify.c +15 -7
@@ -14,6 +14,7 @@#include <linux/sched/mm.h> #include <linux/statfs.h> #include <linux/stringhash.h> +#include <linux/pidfs.h> #include "fanotify.h"
@@ -760,7 +761,7 @@ static struct fanotify_event *fanotify_alloc_event(bool name_event = false;unsigned int hash =0 ;bool ondir = mask &FAN_ONDIR ; -struct pid *pid; +struct pid *pid =NULL ;if ((fid_mode &FAN_REPORT_DIR_FID ) && dirid) {/*
@@ -839,6 +840,16 @@ static struct fanotify_event *fanotify_alloc_event(/* Whoever is interested in the event, pays for the allocation. */ old_memcg =set_active_memcg (group->memcg); +if (FAN_GROUP_FLAG (group,FAN_REPORT_TID )) + pid =get_pid (task_pid (current)); +else + pid =get_pid (task_tgid (current)); + +/* Prepare task for creating pidfd for it even if it exits */ +if (FAN_GROUP_FLAG (group,FAN_REPORT_PIDFD )) +if (pidfs_register_pid (pid)) + goto out; +if (fanotify_is_perm_event (mask)) { event =fanotify_alloc_perm_event (data, data_type, gfp); }else if (fanotify_is_error_event (mask)) {
@@ -860,17 +871,14 @@ static struct fanotify_event *fanotify_alloc_event(if (!event) goto out; -if (FAN_GROUP_FLAG (group,FAN_REPORT_TID )) - pid =get_pid (task_pid (current)); -else - pid =get_pid (task_tgid (current)); -/* Mix event info, FAN_ONDIR flag and pid into event merge key */ hash ^=hash_long ((unsigned long )pid | ondir,FANOTIFY_EVENT_HASH_BITS );fanotify_init_event (event, hash, mask); event->pid = pid; - + pid =NULL ; out: +if (pid) +put_pid (pid);set_active_memcg (old_memcg);return event; }
Signature · 1 line
2.51.0
Jan Kara
maintainerRe: [RFC][PATCH] fanotify: register event pid for pidfd reporting
Quoted 25 lines · Jan Kara
Quoted 24 lines · Christian Brauner
Quoted 11 lines · Jan Kara
Quoted 7 lines · AnonymeMeow
pidfd_prepare()may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, sopidfd_prepare()can later create a pidfd for the reaped task.Signed-off-by AnonymeMeow <[email protected]>So the two patches in this series so far look good to me. This patch looks OK to me as well and since the overhead of allocation etc. is only once per
It's a kmem cache so should not matter at all...
Quoted 2 lines
registered task, I think it's fine but let's wait a bit whether Christian agrees this is what needs to be done.
pidfs_register_pid()can only fail with ENOMEM or if the task is already dead. The latter cannot happen because even for a non-empty thread group where the thread-group leader already exited but subthreads are still alive the thread-group leader cannot be reaped. So the only error here is ENOMEM which means we should defo fail this, imho.
Quoted 8 lines
Quoted 4 lines
And yes, I think this is worth doing. Because you get a persistent handle on the task that generated that event + all the exit information even if that thask has been reaped in the meantime. I'm pretty sure if you're using fanotify that's a rather huge win for apps that need it.
OK, thanks for opinion. So I've somewhat massaged the error handling in the patch AnonymeMeow. Attached is what I currently have in my tree (testing pending).
OK, reverted that for now since I've found further versions of the series in my huge inbox after a few days of vacation now :).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [RFC][PATCH] fanotify: register event pid for pidfd reporting
Quoted 31 lines · Jan Kara
Quoted 30 lines · Jan Kara
Quoted 28 lines · Christian Brauner
Quoted 11 lines · Jan Kara
Quoted 7 lines · AnonymeMeow
pidfd_prepare()may still fail if userspace reads the event after the task has been reaped and the pid has not been registered with pidfs. Register the event pid with pidfs when creating the fanotify event if pidfd reporting was requested, sopidfd_prepare()can later create a pidfd for the reaped task.Signed-off-by AnonymeMeow <[email protected]>So the two patches in this series so far look good to me. This patch looks OK to me as well and since the overhead of allocation etc. is only once per
It's a kmem cache so should not matter at all...
Quoted 2 lines
registered task, I think it's fine but let's wait a bit whether Christian agrees this is what needs to be done.
pidfs_register_pid()can only fail with ENOMEM or if the task is already dead. The latter cannot happen because even for a non-empty thread group where the thread-group leader already exited but subthreads are still alive the thread-group leader cannot be reaped. So the only error here is ENOMEM which means we should defo fail this, imho.And yes, I think this is worth doing. Because you get a persistent handle on the task that generated that event + all the exit information even if that thask has been reaped in the meantime. I'm pretty sure if you're using fanotify that's a rather huge win for apps that need it.
Quoted 6 lines
Quoted 3 lines
OK, thanks for opinion. So I've somewhat massaged the error handling in the patch AnonymeMeow. Attached is what I currently have in my tree (testing pending).
OK, reverted that for now since I've found further versions of the series in my huge inbox after a few days of vacation now :).
Fsck flooded inboxes, vacation is important. :)
Jan Kara
maintainerQuoted 8 lines · AnonymeMeow
The pidfd API now supports pidfds for tasks that are not thread group leaders, but fanotify has not caught up yet. This patch set lifts that restriction and allows fanotify to report pidfds referring the event-generating thread.
Additionally, this patch set drops the
pid_has_task()check before thepidfd_prepare()call, allowing fanotify to hand out pidfds for reaped tasks, as suggested by Christian.
Quoted 6 lines
changes since v2:
- Split the two independent changes into separate patches.
OK, I have taken these patches into my tree now. Can you please send fixes for LTP tests fanotify20 and fanotify21?
Honza
Quoted 11 lines
AnonymeMeow (2):
fanotify: report thread pidfds forFAN_REPORT_TID
fanotify: allow reporting pidfds for reaped tasksfs/notify/fanotify/fanotify_user.c | 33 +++++++----------------------- 1 file changed, 7 insertions(+), 26 deletions(-)Signature · 1 line
2.54.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR