* [PATCH] pidfd: restrict task access ioctls to the caller's pid namespace
@ 2026-10-27 8:22 Chen Linxuan via B4 Relay
2026-11-05 17:19 ` Christian Brauner
0 siblings, 1 reply; 2+ messages in thread
From: Chen Linxuan via B4 Relay @ 2026-10-27 8:22 UTC (permalink / raw)
To: Christian Brauner, Jann Horn
Cc: Alexander Viro, Jan Kara, linux-fsdevel, linux-kernel, linux-api,
Chen Linxuan
From: Chen Linxuan <me@black-desk.cn>
pidfds can cross pid namespace boundaries: a task may obtain one for a
process outside of its own pid namespace hierarchy through SO_PASSPIDFD
or SO_PEERPIDFD, via SCM_RIGHTS, or through file descriptor inheritance.
The namespace ioctls gate access with a ptrace check against the
target's credentials only. That check does not account for the pid
namespace relationship between the caller and the target, so a task
inside a pid namespace can use a pidfd obtained across that boundary to
acquire namespace file descriptors of a task outside of its hierarchy.
procfs exposes the equivalent information only for tasks visible in the
reader's pid namespace, and PIDFD_GET_INFO already answers with -EREMOTE
for targets outside the caller's hierarchy. Extend that policy to the
namespace ioctls: fail with -EREMOTE unless the target is visible in the
caller's active pid namespace. Callers in ancestor pid namespaces are
unaffected.
Unlike PIDFD_GET_INFO, the visibility check is performed after the task
lookup here, so reaped targets outside of the caller's pid namespace
hierarchy answer -ESRCH instead of -EREMOTE.
Link: https://lore.kernel.org/all/CAG48ez1T5-tUHVK_iHsgUtWa-inVdrZxA3E-ZCW0iENJvasKfg@mail.gmail.com
Link: https://lore.kernel.org/all/20260925-gewischt-auftrag-tierzucht-c153cb3f9f74@brauner
Suggested-by: Jann Horn <jannh@google.com>
Suggested-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Chen Linxuan <me@black-desk.cn>
---
This patch was previously submitted as patch 1/4 of the task path ioctl
series v3. It is now submitted independently because it changes access
to existing namespace ioctls and does not depend on the new path ioctls.
The code and commit message are unchanged from v3 1/4. The patch has
been rebased onto current mainline. A revised task path ioctl series
will follow separately and depend on this patch.
Previous submission:
https://lore.kernel.org/all/20261010-pidfd-get-paths-v3-1-f245440b2b30@black-desk.cn/
---
fs/pidfs.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/pidfs.c b/fs/pidfs.c
index 7f8c323ce6cb..cfb93c4ccf23 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -556,6 +556,14 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (arg)
return -EINVAL;
+ /*
+ * Require the target to be visible in the caller's pid namespace
+ * for operations that grant access to its resources, mirroring
+ * procfs and PIDFD_GET_INFO.
+ */
+ if (!pid_in_current_pidns(pidfd_pid(file)))
+ return -EREMOTE;
+
/*
* We're trying to open a file descriptor to the namespace so perform a
* filesystem cred ptrace check. Hold @task's exec_update_lock for the
---
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
change-id: 20261027-pidfd-task-access-b797ecb260a4
Best regards,
--
Chen Linxuan <me@black-desk.cn>
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] pidfd: restrict task access ioctls to the caller's pid namespace
2026-10-27 8:22 [PATCH] pidfd: restrict task access ioctls to the caller's pid namespace Chen Linxuan via B4 Relay
@ 2026-11-05 17:19 ` Christian Brauner
0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2026-11-05 17:19 UTC (permalink / raw)
To: Jann Horn, Chen Linxuan via B4 Relay
Cc: Christian Brauner, Alexander Viro, Jan Kara, linux-fsdevel,
linux-kernel, linux-api, Chen Linxuan, stable
On Tue, 27 Oct 2026 16:22:15 +0800, Chen Linxuan via B4 Relay wrote:
> pidfds can cross pid namespace boundaries: a task may obtain one for a
> process outside of its own pid namespace hierarchy through SO_PASSPIDFD
> or SO_PEERPIDFD, via SCM_RIGHTS, or through file descriptor inheritance.
>
> The namespace ioctls gate access with a ptrace check against the
> target's credentials only. That check does not account for the pid
> namespace relationship between the caller and the target, so a task
> inside a pid namespace can use a pidfd obtained across that boundary to
> acquire namespace file descriptors of a task outside of its hierarchy.
>
> [...]
I think this needs to be backported. I added:
Fixes: 5b08bd408534 ("pidfs: allow retrieval of namespace file descriptors")
Cc: stable@vger.kernel.org
---
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] pidfd: restrict task access ioctls to the caller's pid namespace
https://git.kernel.org/vfs/vfs/c/3c40d51327f2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-05 17:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27 8:22 [PATCH] pidfd: restrict task access ioctls to the caller's pid namespace Chen Linxuan via B4 Relay
2026-11-05 17:19 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®