Skip to content

fanotify: Adding pidfd support to the fanotify API

Matthew Bobrowski linux-api linux-fsdevel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 32 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2pidfd_create(): remove static qualifier and declare pidfd_create() in linux/pid.hinclude/linux/pid.h kernel/pid.c+2 -13 replies
2/2fanotify: Add pidfd support to the fanotify APIfs/notify/fanotify/fanotify_user.c include/linux/fanotify.h include/uapi/linux/fanotify.h+33 -428 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] fanotify: Adding pidfd support to the fanotify API

Hey Jan/Amir/Christian,

This is the RFC patch series for adding pidfd support to the fanotify API.

tl;dr rather than returning a pid within struct fanotify_event_metadata, a pidfd is returned instead when fanotify has been explicitly told to do so via the new FAN_REPORT_PIDFD flag.

The main driver behind returning a pidfd within an event instead of a pid is that it permits userspace applications to better detect if they've possibly lost a TOCTOU race. A common paradigm among userspace applications that make use of the fanotify API is to crawl /proc/<pid> upon receiving an event. Userspace applications do this in order to further ascertain contextual meta-information about the process that was responsible for generating the filesystem event. On high pressure systems, where pid recycling isn't uncommon, it's no longer considered as a reliable approach to directly sift through /proc/<pid> and have userspace applications use the information contained within /proc/<pid> as it could, and does, lead to program execution inaccuracies.

Now when a pidfd is returned in an event, a userspace application can:

a) Obtain the pid responsible for generating the filesystem event from the pidfds fdinfo.

b) Detect whether the userspace application lost the procfs access race by sending a 0 signal on the pidfd and checking the return value. A -ESRCH is indicative of the userspace application losing the race, meaning that the pid has been recycled.

Matthew Bobrowski (2):
pidfd_create(): remove static qualifier and declare pidfd_create() in
linux/pid.h
fanotify: Add pidfd support to the fanotify API

 fs/notify/fanotify/fanotify_user.c | 33 +++++++++++++++++++++++++++---
 include/linux/fanotify.h           |  2 +-
 include/linux/pid.h                |  1 +
 include/uapi/linux/fanotify.h      |  2 ++
 kernel/pid.c                       |  2 +-
 5 files changed, 35 insertions(+), 5 deletions(-)
Signature · 3 lines
2.31.1.368.gbe11c130af-goog

/M