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

/proc hardening #7

Closed
1 of 5 tasks
cyphar opened this issue Dec 23, 2019 · 3 comments · Fixed by #42
Closed
1 of 5 tasks

/proc hardening #7

cyphar opened this issue Dec 23, 2019 · 3 comments · Fixed by #42
Labels
security A security issue or hardening problem.

Comments

@cyphar
Copy link
Member

cyphar commented Dec 23, 2019

Right now, we do a few security checks when operating on /proc, namely:

  • That /proc has an fs_type of PROC_SUPER_MAGIC (which can't be faked by FUSE), to make sure we're dealing with a real procfs.

  • That /proc has an inode number of 1 to indicate that it is the root of a procfs mount -- which is part of the API of Linux and will always be the case.

Unfortunately, this method is still vulnerable to potential attacks if we're in a situation where /proc (usually thanks to a confused deputy) has been set up in such a way to trick us into thinking (for instance) that we are writing an AppArmor label when in fact we aren't.

Effectively we need to use the resolution capabilities of libpathrs for /proc (which leads to some fun re-entrancy issues since libpathrs depends on using /proc during resolution). So that will need some attention.

Note that checking that a given Handle has PROC_SUPER_MAGIC is not sufficient at all because you can always bind-mount another process's procfs file to your own -- and for write-related requests you can just bind-mount a file which no-ops on write like /proc/self/sched.

The set of underlying features currently required are:

@the8472
Copy link

the8472 commented Jan 9, 2021

A way, at least for sufficiently privileged processes, to avoid bind-mount attacks is to create a private procfs instance with new mount API and then operate on the detached, untainted tree.

Edit: Nevermind, I see that's already mentioned in one of the linked issues.

@cyphar
Copy link
Member Author

cyphar commented Jan 14, 2021

Yeah that is one of the options. Ideally that will be the long-term solution (with subset=pids,hidepid=4 we should be able to make creating a private procfs instance safe for unprivileged users). But for now we can only do that for privileged users.

@cyphar
Copy link
Member Author

cyphar commented Jul 5, 2024

cyphar/filepath-securejoin#13 has an implementation of most of this, though it only works for privileged users and on a new enough kernel (Linux 5.8-ish).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security A security issue or hardening problem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants