Skip to content

Commit

Permalink
Merge pull request #1572 from tych0/fix-readonly-userns
Browse files Browse the repository at this point in the history
fix --read-only containers under --userns-remap
  • Loading branch information
hqhq authored Aug 26, 2017
2 parents 4d6e672 + 66eb2a3 commit 1c81e2a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,14 @@ func remountReadonly(m *configs.Mount) error {
flags = m.Flags
)
for i := 0; i < 5; i++ {
if err := unix.Mount("", dest, "", uintptr(flags|unix.MS_REMOUNT|unix.MS_RDONLY), ""); err != nil {
// There is a special case in the kernel for
// MS_REMOUNT | MS_BIND, which allows us to change only the
// flags even as an unprivileged user (i.e. user namespace)
// assuming we don't drop any security related flags (nodev,
// nosuid, etc.). So, let's use that case so that we can do
// this re-mount without failing in a userns.
flags |= unix.MS_REMOUNT | unix.MS_BIND | unix.MS_RDONLY
if err := unix.Mount("", dest, "", uintptr(flags), ""); err != nil {
switch err {
case unix.EBUSY:
time.Sleep(100 * time.Millisecond)
Expand Down

0 comments on commit 1c81e2a

Please sign in to comment.