Files
linux/Documentation/filesystems
Aleksa Sarai fe49652e36 procfs: add "pidns" mount option
Since the introduction of pid namespaces, their interaction with procfs
has been entirely implicit in ways that require a lot of dancing around
by programs that need to construct sandboxes with different PID
namespaces.

Being able to explicitly specify the pid namespace to use when
constructing a procfs super block will allow programs to no longer need
to fork off a process which does then does unshare(2) / setns(2) and
forks again in order to construct a procfs in a pidns.

So, provide a "pidns" mount option which allows such users to just
explicitly state which pid namespace they want that procfs instance to
use. This interface can be used with fsconfig(2) either with a file
descriptor or a path:

  fsconfig(procfd, FSCONFIG_SET_FD, "pidns", NULL, nsfd);
  fsconfig(procfd, FSCONFIG_SET_STRING, "pidns", "/proc/self/ns/pid", 0);

or with classic mount(2) / mount(8):

  // mount -t proc -o pidns=/proc/self/ns/pid proc /tmp/proc
  mount("proc", "/tmp/proc", "proc", MS_..., "pidns=/proc/self/ns/pid");

As this new API is effectively shorthand for setns(2) followed by
mount(2), the permission model for this mirrors pidns_install() to avoid
opening up new attack surfaces by loosening the existing permission
model.

In order to avoid having to RCU-protect all users of proc_pid_ns() (to
avoid UAFs), attempting to reconfigure an existing procfs instance's pid
namespace will error out with -EBUSY. Creating new procfs instances is
quite cheap, so this should not be an impediment to most users, and lets
us avoid a lot of churn in fs/proc/* for a feature that it seems
unlikely userspace would use.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Link: https://lore.kernel.org/20250805-procfs-pidns-api-v4-2-705f984940e7@cyphar.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-09-02 11:37:24 +02:00
..
2023-08-18 11:29:03 -06:00
2023-08-18 11:29:03 -06:00
2023-08-18 11:29:03 -06:00
2024-05-02 10:02:29 -06:00
2022-08-02 12:34:04 -04:00
2024-02-09 10:37:20 +01:00
2023-08-18 11:29:03 -06:00
2023-08-18 11:29:03 -06:00
2023-08-18 11:29:03 -06:00
2025-07-15 13:53:46 -06:00
2025-09-02 11:37:24 +02:00
2023-08-18 11:29:03 -06:00
2020-07-09 08:14:01 +02:00
2023-08-18 11:29:03 -06:00
2024-10-28 13:36:55 +01:00
2023-08-18 11:29:03 -06:00
2023-08-18 11:29:03 -06:00