Repository navigation
pidfd: add task path ioctls - #2820
Open
vfsci-bot[bot] wants to merge 4 commits into
Open
vfsci-bot[bot] wants to merge 4 commits into
vfsci-bot[bot] wants to merge 4 commits into
Conversation
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> Assisted-by: LLM Signed-off-by: Chen Linxuan <me@black-desk.cn>
Introduce helpers that acquire a referenced struct path for a task's executable, root, and working directory. Reuse them for procfs task links and AppArmor executable-path handling instead of duplicating file and path reference handling at each call site. Assisted-by: LLM Signed-off-by: Chen Linxuan <me@black-desk.cn>
Split namespace acquisition from namespace fd creation and represent a privileged target task as a scoped class that owns both the task reference and exec_update_lock. Use the class for namespace lookups so ptrace access checks and task state reads remain tied to the same exec critical section, while open_namespace() stays outside the lock. Carry the pid namespace visibility check into the helper so that all users of the class enforce it. Assisted-by: LLM Signed-off-by: Chen Linxuan <me@black-desk.cn>
Add PIDFD_GET_EXE, PIDFD_GET_CWD, and PIDFD_GET_ROOT to return close-on-exec O_PATH file descriptors referencing the target task's executable, working directory, and root directory. The ioctls acquire the target through the shared task acquisition helper and are thus subject to the same checks as the namespace ioctls. The target is sampled while holding exec_update_lock so that the access check and the path read cannot race with execve(). This allows userspace to obtain stable path references from a pidfd without requiring procfs. Assisted-by: LLM Signed-off-by: Chen Linxuan <me@black-desk.cn>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Series: https://patchwork.kernel.org/project/linux-fsdevel/list/?series=1182922
Submitter: Chen Linxuan
Version: 3
Patches: 4/4
Message-ID:
<20261010-pidfd-get-paths-v3-0-f245440b2b30@black-desk.cn>Base: vfs.base.ci
Lore: https://lore.kernel.org/linux-fsdevel/20261010-pidfd-get-paths-v3-0-f245440b2b30@black-desk.cn
Automated by ml2pr