[PATCH v2 0/3] pidfd: add task path ioctls
Chen Linxuan via B4 Relay
devnull+me.black-desk.cn at kernel.org
Mon Aug 31 02:59:05 UTC 2026
Obtaining a target task's executable, working directory, or root
currently requires walking procfs symlinks such as /proc/<pid>/exe,
/proc/<pid>/cwd, and /proc/<pid>/root. That makes the operation depend
on procfs being mounted and visible to the caller, even when it already
holds a pidfd for the target.
This series adds PIDFD_GET_EXE, PIDFD_GET_CWD, and PIDFD_GET_ROOT. Each
ioctl takes no argument and returns a close-on-exec O_PATH file
descriptor referencing the corresponding task path. The new ioctls use
the same ptrace permission check and nonzero-argument rejection as the
existing pidfd namespace ioctls.
The target task is sampled while holding its exec_update_lock. This
keeps the access decision and the task-state read in the same exec
critical section, preventing a concurrent execve() from changing the
credentials or target state between the check and the use.
The first patch factors out helpers for acquiring referenced task paths
and reuses them in procfs and AppArmor. The second patch introduces
scoped cleanup for privileged pidfd task access and separates namespace
lookup from namespace fd creation. The final patch uses these pieces to
implement the three new ioctls.
Signed-off-by: Chen Linxuan <me at black-desk.cn>
---
Changes in v2:
- Make pidfd_get_task_locked() own the task reference until it is
transferred to the pidfd_task_locked cleanup class.
- Link to v1: https://patch.msgid.link/20260820-pidfd-get-paths-v1-0-ac3eee4003d5@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/pidfs.c | 153 ++++++++++++++++++++++++++++++++-------------
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 | 21 +++++++
security/apparmor/task.c | 12 +---
8 files changed, 190 insertions(+), 85 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260819-pidfd-get-paths-59640d8cd1ee
Best regards,
--
Chen Linxuan <me at black-desk.cn>
More information about the Linux-security-module-archive
mailing list