openSUSE / libpathrs

C-friendly API to make path resolution safer on Linux.
GNU Lesser General Public License v3.0
83 stars 6 forks source link

procfs: allow for ProcfsBase::Root to access non-pid information #62

Closed cyphar closed 1 month ago

cyphar commented 2 months ago

While it is fairly trivial to just add a ProcfsBase::Root enum variant that maps to /proc/., there are a few minor issues to consider:

We need this for #58 to check the value of /proc/sys/fs/privileged_symlinks (unless we do the lookup on PROCFS_HANDLE directly without using the official ProcfsHandle API).

cyphar commented 2 months ago

After speaking to @brauner, I think that just returning errors in the case of overmounts is what all users would practically expect. If you want to support lxcfs then you would need to resolve things through /proc anyway and you don't care about doing safe procfs operations anyway.

And yeah, the fact we need this internally kind of indicates what kinds of things people will need this for.

cyphar commented 2 months ago

A workaround I have for the second issue is that we only cache the subset=pid handle, and if an operation fails on it we create a temporary handle that doesn't have subset=pid which is closed after the operation finishes. This is more expensive than a regular open but avoids us leaking unmasked procfs mounts into containers. Of course, the open("/proc") handle is just as unsafe as before for this.