Skip to content

Commit

Permalink
specgen, rootless: fix mount of cgroup without a netns
Browse files Browse the repository at this point in the history
commit cf36470 changed the way
/sys/fs/cgroup is mounted when there is not a netns and it now honors
the ro flag.  The mount was created using a bind mount that is a
problem when using a cgroup namespace, fix that by mounting a fresh
cgroup file system.

Closes: containers#20073

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Sep 21, 2023
1 parent e209c40 commit 8d3010d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/specgen/generate/oci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
}
g.AddMount(sysMnt)
g.RemoveMount("/sys/fs/cgroup")

sysFsCgroupMnt := spec.Mount{
Destination: "/sys/fs/cgroup",
Type: define.TypeBind,
Type: "cgroup",
Source: "/sys/fs/cgroup",
Options: []string{"rprivate", "nosuid", "noexec", "nodev", r, "rbind"},
Options: []string{"rprivate", "nosuid", "noexec", "nodev", r},
}
g.AddMount(sysFsCgroupMnt)
if !s.Privileged && isRootless {
Expand Down
4 changes: 4 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,10 @@ EOF
# verify that the last /sys/fs/cgroup mount is read-only
run_podman run --net=host --cgroupns=host --rm $IMAGE sh -c "grep ' / /sys/fs/cgroup ' /proc/self/mountinfo | tail -n 1"
assert "$output" =~ "/sys/fs/cgroup ro"

# verify that it works also with a cgroupns
run_podman run --net=host --cgroupns=private --rm $IMAGE sh -c "grep ' / /sys/fs/cgroup ' /proc/self/mountinfo | tail -n 1"
assert "$output" =~ "/sys/fs/cgroup ro"
fi
}

Expand Down

0 comments on commit 8d3010d

Please sign in to comment.