Skip to content

Commit 1c81e2a

Browse files
authored
Merge pull request opencontainers#1572 from tych0/fix-readonly-userns
fix --read-only containers under --userns-remap
2 parents 4d6e672 + 66eb2a3 commit 1c81e2a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libcontainer/rootfs_linux.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,14 @@ func remountReadonly(m *configs.Mount) error {
733733
flags = m.Flags
734734
)
735735
for i := 0; i < 5; i++ {
736-
if err := unix.Mount("", dest, "", uintptr(flags|unix.MS_REMOUNT|unix.MS_RDONLY), ""); err != nil {
736+
// There is a special case in the kernel for
737+
// MS_REMOUNT | MS_BIND, which allows us to change only the
738+
// flags even as an unprivileged user (i.e. user namespace)
739+
// assuming we don't drop any security related flags (nodev,
740+
// nosuid, etc.). So, let's use that case so that we can do
741+
// this re-mount without failing in a userns.
742+
flags |= unix.MS_REMOUNT | unix.MS_BIND | unix.MS_RDONLY
743+
if err := unix.Mount("", dest, "", uintptr(flags), ""); err != nil {
737744
switch err {
738745
case unix.EBUSY:
739746
time.Sleep(100 * time.Millisecond)

0 commit comments

Comments
 (0)