Merge pull request #2159 from AkihiroSuda/cgroup2-mount-in-userns

cgroup2: allow mounting /sys/fs/cgroup in UserNS without unsharing CgroupNS
This commit is contained in:
Mrunal Patel 2019-10-28 19:19:09 -07:00 committed by GitHub
commit 03cf145f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -279,8 +279,14 @@ func mountCgroupV2(m *configs.Mount, rootfs, mountLabel string, enableCgroupns b
if err := os.MkdirAll(cgroupPath, 0755); err != nil { if err := os.MkdirAll(cgroupPath, 0755); err != nil {
return err return err
} }
if err := unix.Mount(m.Source, cgroupPath, "cgroup2", uintptr(m.Flags), m.Data); err != nil {
return unix.Mount(m.Source, cgroupPath, "cgroup2", uintptr(m.Flags), m.Data) // when we are in UserNS but CgroupNS is not unshared, we cannot mount cgroup2 (#2158)
if err == unix.EPERM || err == unix.EBUSY {
return unix.Mount("/sys/fs/cgroup", cgroupPath, "", uintptr(m.Flags)|unix.MS_BIND, "")
}
return err
}
return nil
} }
func mountToRootfs(m *configs.Mount, rootfs, mountLabel string, enableCgroupns bool) error { func mountToRootfs(m *configs.Mount, rootfs, mountLabel string, enableCgroupns bool) error {