Skip to content

Commit 32ed7f4

Browse files
committed
Fallback to bind mount for sysfs in user namespaces
1 parent 59a5ff1 commit 32ed7f4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

libcontainer/rootfs_linux.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)