Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cyphar opened this issue Sep 11, 2024 · 2 comments · Fixed by #72
Closed

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

cyphar opened this issue Sep 11, 2024 · 2 comments · Fixed by #72
Labels
api/cffi Related to the C-FFI API. api/rust Related to the Rust API. resolver/procfs Related to the procfs-specific resolver. target/runc Requirement to port runc to libpathrs.
Milestone

Comments

@cyphar
Copy link
Member

cyphar commented Sep 11, 2024

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:

  • While it is generally considered invalid to mount on top of stuff in /proc/$pid/... (see kernel hardening: block magic-link mounts #45), tools like https://github.com/lxc/lxcfs intentionally mount fake files on top of stuff in the /proc root (such as /proc/cpuinfo and /proc/meminfo). RESOLVE_NO_XDEV will block this, which is what we want from a security perspective but this could lead to errors that confuse users when running programs inside containers.

  • We can no longer use subset=pid for our internal procfs mount created with fsopen. In principle this isn't necessary, but it seems like a bad idea to have a copy of files that might be masked inside a container (using PR_SET_DUMPABLE you can block most of the ways a container process could access the file descriptor but it's not a given that every program would know to do that, and if the file descriptor gets leaked for some reason then there is no protection). We could work around this by reconfiguring the mount if it was made by us with fsopen to avoid enabling this by default, but we could never reconfigure it back to subset=pid because of possible races (we could add locking but it'd be nice to not have to).

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 cyphar added this to the 0.2.0 milestone Sep 11, 2024
@cyphar cyphar added api/cffi Related to the C-FFI API. api/rust Related to the Rust API. resolver/procfs Related to the procfs-specific resolver. target/runc Requirement to port runc to libpathrs. labels Sep 11, 2024
@cyphar
Copy link
Member Author

cyphar commented Sep 19, 2024

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
Copy link
Member Author

cyphar commented Sep 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/cffi Related to the C-FFI API. api/rust Related to the Rust API. resolver/procfs Related to the procfs-specific resolver. target/runc Requirement to port runc to libpathrs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant