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

server, runtimeVM: Don't mount /sys and /sys/fs/cgroup using "rslave" #4896

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions server/container_create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
oci "github.com/cri-o/cri-o/internal/oci"
"github.com/cri-o/cri-o/internal/storage"
crioann "github.com/cri-o/cri-o/pkg/annotations"
libconfig "github.com/cri-o/cri-o/pkg/config"
ctrIface "github.com/cri-o/cri-o/pkg/container"
"github.com/cri-o/cri-o/server/cri/types"
securejoin "github.com/cyphar/filepath-securejoin"
Expand Down Expand Up @@ -452,17 +453,39 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrIface.Contai
}

if ctr.Privileged() {
sysMountOptions := []string{"nosuid", "noexec", "nodev", "rw"}
sysFsCgroupMountOptions := []string{"nosuid", "noexec", "nodev", "rw", "relatime"}

runtimeHandler := sb.RuntimeHandler()
runtimeType, err := s.Runtime().RuntimeType(runtimeHandler)
if err != nil {
return nil, err
}

// A container is kernel separated if we're using shimv2, or we're using a kata v1 binary
podIsKernelSeparated := runtimeType == libconfig.RuntimeTypeVM ||
strings.Contains(strings.ToLower(runtimeHandler), "kata") ||
(runtimeHandler == "" && strings.Contains(strings.ToLower(s.config.DefaultRuntime), "kata"))
Comment on lines +465 to +468
Copy link
Member

Choose a reason for hiding this comment

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

can we add a method to the runtime class s.Runtime().IsKernelSeparated() instead of duplicating this check between here and sandbox_run_linux?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing!


if !podIsKernelSeparated {
// Setting "rslave" as a mount option caused regressions on kata-containers side,
// where privileged pods can't be created, resulting on ContainerCreate returning
// EINVAL.
sysMountOptions = append(sysMountOptions, "rslave")
sysFsCgroupMountOptions = append(sysFsCgroupMountOptions, "rslave")
}

ctr.SpecAddMount(rspec.Mount{
Destination: "/sys",
Type: "sysfs",
Source: "sysfs",
Options: []string{"nosuid", "noexec", "nodev", "rw", "rslave"},
Options: sysMountOptions,
})
ctr.SpecAddMount(rspec.Mount{
Destination: "/sys/fs/cgroup",
Type: "cgroup",
Source: "cgroup",
Options: []string{"nosuid", "noexec", "nodev", "rw", "relatime", "rslave"},
Options: sysFsCgroupMountOptions,
})
}

Expand Down