[PATCH v5 0/3] pidfd: Add task path ioctls
Chen Linxuan via B4 Relay
devnull+me.black-desk.cn at kernel.org
Fri Nov 6 07:12:20 UTC 2026
Obtaining a target task's executable, working directory or root
currently requires following /proc/<pid>/{exe,cwd,root}. Add
PIDFD_GET_EXE, PIDFD_GET_CWD and PIDFD_GET_ROOT so callers holding a
pidfd can obtain these paths without requiring procfs to be mounted or
visible.
Each ioctl takes a zero argument and returns an O_PATH file descriptor
with FD_CLOEXEC set. Targets must be visible in the caller's active pid
namespace. Reuse the procfs path getters and hold exec_update_lock
across PTRACE_MODE_READ_FSCREDS authorization and path acquisition.
Following Christian Brauner's review, use a dedicated task_path_open()
helper after releasing exec_update_lock. It calls ->d_weak_revalidate()
with flags zero when the filesystem provides it, propagates a negative
error, maps a zero result to ESTALE, and otherwise opens the path with
O_PATH. This gives filesystems such as failfs the opportunity to refuse
an O_PATH descriptor without starting a pathname lookup.
The first patch factors out the task path getters. The second prepares
scoped task access for the pidfd ioctls. The third adds the three ioctls
and task_path_open().
This series depends on the separately submitted pid-namespace visibility
restriction:
https://lore.kernel.org/all/20261027-pidfd-task-access-v1-1-d46cf0fa4ca1@black-desk.cn/
Tested with virtme-ng.
Sashiko AI review reported the missing weak revalidation in v4.
This entire patch series was generated with LLM assistance. I defined
the requirements, guided the implementation, reviewed the changes, and
made the design decisions.
---
Changes in v5:
- Add task_path_open() as suggested by Christian Brauner, replacing the
direct dentry_open() call from v4. Revalidate with flags zero outside
exec_update_lock and return filesystem errors without lookup retries.
- Link to v4:
https://lore.kernel.org/all/20261027-pidfd-get-paths-v4-0-e2a6a47e3c95@black-desk.cn/
To: Alexander Viro <viro at zeniv.linux.org.uk>
To: Christian Brauner <brauner at kernel.org>
To: Jan Kara <jack at suse.cz>
To: Andrew Morton <akpm at linux-foundation.org>
To: David Hildenbrand <david at kernel.org>
To: Lorenzo Stoakes <ljs at kernel.org>
To: "Liam R. Howlett" <liam at infradead.org>
To: Vlastimil Babka <vbabka at kernel.org>
To: Mike Rapoport <rppt at kernel.org>
To: Suren Baghdasaryan <surenb at google.com>
To: Michal Hocko <mhocko at suse.com>
To: Ingo Molnar <mingo at redhat.com>
To: Peter Zijlstra <peterz at infradead.org>
To: Juri Lelli <juri.lelli at redhat.com>
To: Vincent Guittot <vincent.guittot at linaro.org>
To: Dietmar Eggemann <dietmar.eggemann at arm.com>
To: Steven Rostedt <rostedt at goodmis.org>
To: Ben Segall <bsegall at google.com>
To: Mel Gorman <mgorman at suse.de>
To: Valentin Schneider <vschneid at redhat.com>
To: K Prateek Nayak <kprateek.nayak at amd.com>
To: Kees Cook <kees at kernel.org>
To: John Johansen <john.johansen at canonical.com>
To: Georgia Garcia <georgia.garcia at canonical.com>
To: Paul Moore <paul at paul-moore.com>
To: James Morris <jmorris at namei.org>
To: "Serge E. Hallyn" <serge at hallyn.com>
Cc: linux-fsdevel at vger.kernel.org
Cc: linux-kernel at vger.kernel.org
Cc: linux-mm at kvack.org
Cc: apparmor at lists.ubuntu.com
Cc: linux-security-module at vger.kernel.org
---
Chen Linxuan (3):
fs: Introduce task path helpers
pidfd: Use scoped cleanup for task access
pidfd: Add task path ioctls
fs/fs_struct.c | 44 +++++++++++++
fs/internal.h | 1 +
fs/open.c | 30 +++++++++
fs/pidfs.c | 157 ++++++++++++++++++++++++++++++++-------------
fs/proc/base.c | 34 +---------
include/linux/fs_struct.h | 3 +
include/linux/mm.h | 1 +
include/uapi/linux/pidfd.h | 7 ++
kernel/fork.c | 22 +++++++
security/apparmor/task.c | 12 +---
10 files changed, 224 insertions(+), 87 deletions(-)
---
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
change-id: 20260819-pidfd-get-paths-59640d8cd1ee
prerequisite-change-id: 20261027-pidfd-task-access-b797ecb260a4:v1
prerequisite-patch-id: 021f6b0840ced7fe967a849b99c366257160c005
Best regards,
--
Chen Linxuan <me at black-desk.cn>
More information about the Linux-security-module-archive
mailing list