libpathrs icon indicating copy to clipboard operation
libpathrs copied to clipboard

procfs: add ioctl to get the pidns associated with the procfs

Open cyphar opened this issue 5 months ago • 3 comments

This would be very useful for us, as it would allow us to work around the kinds of issues we had with /proc/thread-self when joining PID namespaces -- if you have a PID value you want to operate on but /proc is from a different pidns, at the moment you will get nonsense results (either an error or -- even worse -- operate on the the wrong process's /proc/$pid).

The idea would be to be able to get a pidns handle from the /proc root, which then could be used with NS_GET_PID_IN_PIDNS to convert the PID from task_active_pid_ns(current) to the pidns of /proc. This could then be automatically translated when you use ProcfsBase::Pid. For fsopen(2) users, this would be a no-op, but this could be incredibly useful for container runtimes or other systems that mess around with namespaces.

In theory you could do this today with pidfds (since /proc/self/fdinfo/$fd will convert the PID to the PID of the pidns, but it would be nice to avoid the need for that).

cyphar avatar Jul 16 '25 17:07 cyphar