From a9deb044d54315498f3fbde1e14cd53eb7658722 Mon Sep 17 00:00:00 2001 From: Chen Linxuan Date: Fri, 6 Nov 2026 15:12:23 +0800 Subject: pidfd: Add task path ioctls Add PIDFD_GET_EXE, PIDFD_GET_CWD, and PIDFD_GET_ROOT so callers holding a pidfd can obtain close-on-exec O_PATH file descriptors for the target's executable, working directory, and root without requiring procfs. Use the task acquisition helper shared with the namespace ioctls to check PID namespace visibility and ptrace access. Hold exec_update_lock across the access check and path acquisition to prevent a concurrent execve() from changing the target's credentials between them. Add task_path_open() to perform weak revalidation before opening the selected path. This gives the filesystem the opportunity to reject a path handed out directly by a task, as it can when following a procfs magic link. Pass flags zero because no pathname lookup is performed, propagate negative errors, and return ESTALE for a zero result. Release exec_update_lock before calling task_path_open() so filesystem revalidation runs outside the target's exec critical section. Suggested-by: Christian Brauner Link: https://lore.kernel.org/all/20261105-gefolge-rosten-neueinstellung-6223a18aae90@brauner/ Signed-off-by: Chen Linxuan Link: https://patch.msgid.link/20261106-pidfd-get-paths-v5-3-3147ce6571cb@black-desk.cn Signed-off-by: Christian Brauner (Amutable) --- include/uapi/linux/pidfd.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/uapi/linux') diff --git a/include/uapi/linux/pidfd.h b/include/uapi/linux/pidfd.h index 0919246a1611..95ce1819f423 100644 --- a/include/uapi/linux/pidfd.h +++ b/include/uapi/linux/pidfd.h @@ -121,4 +121,11 @@ struct pidfd_info { #define PIDFD_GET_UTS_NAMESPACE _IO(PIDFS_IOCTL_MAGIC, 10) #define PIDFD_GET_INFO _IOWR(PIDFS_IOCTL_MAGIC, 11, struct pidfd_info) +/* Return an O_PATH file descriptor for the target task's executable. */ +#define PIDFD_GET_EXE _IO(PIDFS_IOCTL_MAGIC, 12) +/* Return an O_PATH file descriptor for the target task's working directory. */ +#define PIDFD_GET_CWD _IO(PIDFS_IOCTL_MAGIC, 13) +/* Return an O_PATH file descriptor for the target task's root directory. */ +#define PIDFD_GET_ROOT _IO(PIDFS_IOCTL_MAGIC, 14) + #endif /* _UAPI_LINUX_PIDFD_H */ -- cgit v1.2.3