Skip to content

Commit e3283ab

Browse files
Merge pull request #3614 from giuseppe/rootless-fresh-sys-mount-if-possible
rootless: do not bind mount /sys if not needed
2 parents 96e1871 + b798e6a commit e3283ab

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

run_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,13 @@ func setupRootlessSpecChanges(spec *specs.Spec, bundleDir string, shmSize string
21642164
return err
21652165
}
21662166

2167+
// If the container has a network namespace, we can create a fresh /sys mount
2168+
for _, ns := range spec.Linux.Namespaces {
2169+
if ns.Type == specs.NetworkNamespace {
2170+
return nil
2171+
}
2172+
}
2173+
21672174
// Replace /sys with a read-only bind mount.
21682175
mounts := []specs.Mount{
21692176
{

tests/namespaces.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ load helpers
5050
run_buildah run $RUNOPTS --net=host "$ctr" readlink /proc/self/ns/net
5151
expect_output "$mynetns"
5252

53+
# Check that we are not bind mounting /sys from the host with --net=container
54+
host_sys=$(grep "/sys " /proc/self/mountinfo | cut -d ' ' -f 3)
55+
run_buildah run $RUNOPTS --net=container "$ctr" sh -c 'grep "/sys " /proc/self/mountinfo | cut -d " " -f 3'
56+
assert "$output" != "$host_sys"
57+
5358
# Create a container that doesn't use that mapping.
5459
run_buildah from --signature-policy ${TESTSDIR}/policy.json --quiet alpine
5560
ctr="$output"

0 commit comments

Comments
 (0)