Skip to content

Commit

Permalink
cgroup2: allow mounting /sys/fs/cgroup in UserNS without unsharing Cg…
Browse files Browse the repository at this point in the history
…roupNS

Bind-mount /sys/fs/cgroup when we are in UserNS but CgroupNS is not unshared,
because we cannot mount cgroup2.

This behavior correspond to crun v0.10.2.

Fix #2158

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Oct 27, 2019
1 parent c4d8e16 commit 9c81440
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,14 @@ func mountCgroupV2(m *configs.Mount, rootfs, mountLabel string, enableCgroupns b
if err := os.MkdirAll(cgroupPath, 0755); err != nil {
return err
}

return unix.Mount(m.Source, cgroupPath, "cgroup2", uintptr(m.Flags), m.Data)
if err := unix.Mount(m.Source, cgroupPath, "cgroup2", uintptr(m.Flags), m.Data); err != nil {
// 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 {
Expand Down

0 comments on commit 9c81440

Please sign in to comment.