File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -622,7 +622,19 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
622622 // "proc" and "sys" mounts need special handling (without resolving the
623623 // destination) to avoid attacks.
624624 m .dstFile = dstFile
625- return m .mountPropagate (rootfs , "" )
625+ err = m .mountPropagate (rootfs , "" )
626+ if err != nil && m .Device == "sysfs" && errors .Is (err , unix .EPERM ) {
627+ logrus .Debugf ("cannot mount sysfs with properties, fallback to bind mount: %v" , err )
628+ bindM := & configs.Mount {
629+ Device : "bind" ,
630+ Source : "/sys" ,
631+ Destination : m .Destination ,
632+ Flags : unix .MS_BIND | unix .MS_REC | m .Flags ,
633+ PropagationFlags : m .PropagationFlags ,
634+ }
635+ return mountToRootfs (c , mountEntry {Mount : bindM })
636+ }
637+ return err
626638 }
627639
628640 mountLabel := c .label
Original file line number Diff line number Diff line change @@ -280,3 +280,17 @@ function teardown() {
280280 # is deleted during the namespace cleanup.
281281 run ! ip link del dummy0
282282}
283+
284+ @test " userns with host network: sysfs mount should fall back to bind mount" {
285+ # Remove network namespace to use host network.
286+ update_config ' .linux.namespaces |= map(select(.type != "network"))'
287+
288+ # We check if /sys/class/net exists to verify that /sys is mounted
289+ # correctly after the fallback.
290+ update_config ' .process.args = ["ls", "/sys/class/net"]'
291+
292+ runc run test_userns_sysfs_fallback
293+ [ " $status " -eq 0 ]
294+ # Check for loopback interface, which should always be present on the host.
295+ [[ " $output " == * " lo" * ]]
296+ }
You can’t perform that action at this time.
0 commit comments