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

Move the cgroups v2 hybrid check from init() #3432

Closed

Conversation

mrunalp
Copy link
Contributor

@mrunalp mrunalp commented Mar 25, 2022

Other code that imports the libcontainer cgroups library
may be vulnerable to panic in the function due to insufficient
permissions.

Signed-off-by: Mrunal Patel [email protected]

Other code that imports the libcontainer cgroups library
may be vulnerable to panic in the function due to insufficient
permissions.

Signed-off-by: Mrunal Patel <[email protected]>
@mrunalp
Copy link
Contributor Author

mrunalp commented Mar 25, 2022

We could also save the error from the function and propagate it up. IsCgroup2UnifiedMode also has a similar panic but isn't called from any init functions.

@mrunalp
Copy link
Contributor Author

mrunalp commented Mar 25, 2022

@kolyshkin @thaJeztah @AkihiroSuda ptal

@liggitt
Copy link
Contributor

liggitt commented Mar 25, 2022

is a panic on a permissions error on that path really the correct response for all callers? returning a bool, error and letting the caller decide if it should be a fatal error would have been what I expected.

@mrunalp
Copy link
Contributor Author

mrunalp commented Mar 26, 2022

is a panic on a permissions error on that path really the correct response for all callers? returning a bool, error and letting the caller decide if it should be a fatal error would have been what I expected.

Yes, that's what I posed in my comment above to the other maintainers. This particular function is a relative easy fix with 2 callers. We also have the existing IsCgroup2UnifiedMode with many more callers. I think the risk of hitting this is very low based on the permissions of these directories unless there is some misconfiguration of cgroups setup on a distro.

Our options are:

  1. We could get this in and it will be a similar risk to what's vendored right now with the existing calls of IsCgroup2UnifiedMode.
  2. Fix up the callers of IsCgroup2HybridMode only in this PR and fix the remaining later.
  3. Fix both of them. Maybe refactor so we detect the failure in a different call early and all callers don't have to be modified for IsCgroup2UnifiedMode. This could lead to API changes, so needs more time and thought.

AkihiroSuda
AkihiroSuda previously approved these changes Mar 26, 2022
// If using cgroups-hybrid mode then add a "" controller indicating
// it should join the cgroups v2.
if cgroups.IsCgroup2HybridMode() {
subsystems = append(subsystems, &NameGroup{GroupName: "", Join: true})
Copy link
Contributor

Choose a reason for hiding this comment

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

This is mutating a package var in a constructor. Can that race with other readers of subsystems? If the constructor is called multiple times, this will append multiple times, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, yeah, from a quick look, we could move the subsystems under the manager instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a commit to test that out (will check later).

mu sync.Mutex
cgroups *configs.Cgroup
paths map[string]string
subsystems []subsystem
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not make sense to have a per-manager subsystem list.

Instead, I think, we should keep subsystems global, and wrap their initialization into once.Do.

@kolyshkin
Copy link
Contributor

I took a look at it seems it's better to just avoid panicking in IsCgroup2HybridMode. This is what #3433 does; PTAL.

@mrunalp
Copy link
Contributor Author

mrunalp commented Mar 27, 2022

Closing in favor of #3433

@mrunalp mrunalp closed this Mar 27, 2022
@mrunalp
Copy link
Contributor Author

mrunalp commented Oct 11, 2022 via email

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