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

Treat EROFS in cgroups setup as skippable error #1657

Closed

Conversation

rutsky
Copy link

@rutsky rutsky commented Nov 20, 2017

Currently cgroup setup ignores permissions errors.
AFAIK this helps with rootless containers: if user have permissions to
change cgroups, it will have them setup, otherwise rootless container
will use parent process cgroups (as it was with rootless containers
before cgroups cgroups support was introduced).
If cgroup is mounted in read-only mode (e.g. inside Docker container),
operations will return not permission error, but EROFS - this patch
treats EROFS as skippable error in cgroups setup.

Signed-off-by: Vladimir Rutsky [email protected]

@rutsky
Copy link
Author

rutsky commented Nov 21, 2017

Since it changes your code, @williammartin, can you take a look at this PR?

@williammartin
Copy link

@rutsky Your summary of why we do the permission check for rootless containers is correct and it doesn't look like this PR will break that. I'm not super sure about the EROFS check logic and the expected behaviour though because I'm not familiar with Docker. If the whole cgroup tree is mounted read-only inside a docker container, how do non-rootless containers work?

The only thing I'd note is that isPermissionError should maybe be something like isIgnorableError, because the read-only nature is no longer related to permissions imo.

@cyphar
Copy link
Member

cyphar commented Nov 21, 2017

@williammartin

If the whole cgroup tree is mounted read-only inside a docker container, how do non-rootless containers work?

This PR is about inside a container, where cgroupfs is mounted as ro -- it's rw on the host.

@williammartin
Copy link

Yeh I got that, but I think I answered my own question which is that the referenced issue #1658 is dealing with unprivileged docker containers, so rootless containers inside are the only thing that would ever work anyways.

@@ -144,8 +145,24 @@ func (m *Manager) Apply(pid int) (err error) {
}
m.Paths[sys.Name()] = p

isPermissionError := func(err error) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define this as an actual function (preferably called isIgnorableError) rather than using the a := func(...) {...} form.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. PTAL.

Currently cgroup setup ignores permissions errors.
AFAIK this helps with rootless containers: if user have permissions to
change cgroups, it will have them setup, otherwise rootless container
will use parent process cgroups (as it was with rootless containers
before cgroups support was introduced).
If cgroup is mounted in read-only mode (e.g. inside Docker container),
operations will return not permission error, but EROFS - this patch
treats EROFS as skippable error in cgroups setup.

Signed-off-by: Vladimir Rutsky <[email protected]>
@rutsky rutsky force-pushed the treat-EROFS-as-skippable-error branch from 7c8b8ec to 05d4d1d Compare November 21, 2017 18:47
@rutsky
Copy link
Author

rutsky commented Nov 21, 2017

@williammartin thanks for the review!

Relatively offtopic to this PR question: what if cgroups setup will fail due to permission error on non-rootless container? E.g. if runc will be run as root and due to some reasons cgroup setup will return permission error (not sure if this is possible, but also I don't see why this is impossible), wouldn't this lead to security issues or unconstrained (in terms of resources) processes inside container?

@williammartin
Copy link

@rutsky We had a brief chat in #1540 about that in one of the libcontainer/cgroups/fs/apply_raw.go reviews on Aug 14th. We couldn't really figure out a way that as root, with CAP_DAC_OVERRIDE, we could ever get permission denied but let's definitely think it through again.

@cyphar
Copy link
Member

cyphar commented Nov 21, 2017

@rutsky That is something that (I think?) I brought up in #1540 as a point of concern, but the only places where (currently) you'll get an EPERM in cgroupfs are places that don't affect a process that has CAP_DAC_OVERRIDE (the errors are all related to permission checks done in addition to the VFS checks). All other errors are usally EINVAL or similar.

However, I do agree we should only use isIgnorableError if we're running as rootless -- though I believe the problem at the time was that the libcontainer/cgroup API didn't pass down the top-level *configs.Config so getting config.Rootless was non-trivial. If you can fix this, that'd be greatly appreciated.

@AkihiroSuda
Copy link
Member

ping @rutsky

This PR seems the good alternative for #1691 , and +1 for honoring config.Rootless.

@AkihiroSuda
Copy link
Member

@cyphar Could you set rootless-containers label to this one as well?

@cyphar
Copy link
Member

cyphar commented Jan 25, 2018

Done. I will go through a proper review of all the rootless-containers PRs next week (I'm at a conference this week).

@cyphar
Copy link
Member

cyphar commented Feb 2, 2018

This change looks okay in principle, but I think that (harrowing back to my comments in #1540) we should be only applying the isIgnorable check if we are running in rootless mode -- due to the security concerns that both @rutsky and I have brought up (EROFS can be hit as a root user). So I reckon that the Manager should have a field that says whether we are rootless.

@rutsky I can carry this PR for you and do it, if you are no longer interested in updating this.

@cyphar cyphar self-assigned this Feb 4, 2018
@cyphar cyphar assigned cyphar and unassigned cyphar Feb 23, 2018
@cyphar
Copy link
Member

cyphar commented Mar 16, 2018

Closing in favour of #1759 which carries this.

@cyphar cyphar closed this Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants