Skip to content

Commit 9d4c02c

Browse files
authored
Merge pull request #2570 from EduardoVega/2246-fix-chmod-ro-tmpfs-mount
Fix mount error when chmod RO tmpfs
2 parents 6a28ca3 + fb4c27c commit 9d4c02c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libcontainer/rootfs_linux.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string, enableCgroupns b
383383
return err
384384
}
385385
}
386+
// Initially mounted rw in mountPropagate, remount to ro if flag set.
387+
if m.Flags&unix.MS_RDONLY != 0 {
388+
if err := remount(m, rootfs); err != nil {
389+
return err
390+
}
391+
}
386392
return nil
387393
case "bind":
388394
if err := prepareBindMount(m, rootfs); err != nil {
@@ -981,6 +987,12 @@ func mountPropagate(m *configs.Mount, rootfs string, mountLabel string) error {
981987
flags &= ^unix.MS_RDONLY
982988
}
983989

990+
// Mount it rw to allow chmod operation. A remount will be performed
991+
// later to make it ro if set.
992+
if m.Device == "tmpfs" {
993+
flags &= ^unix.MS_RDONLY
994+
}
995+
984996
copyUp := m.Extensions&configs.EXT_COPYUP == configs.EXT_COPYUP
985997
if !(copyUp || strings.HasPrefix(dest, rootfs)) {
986998
dest = filepath.Join(rootfs, dest)

tests/integration/mounts.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ function teardown() {
2020
[ "$status" -eq 0 ]
2121
[[ "${lines[0]}" == *'/tmp/bind/config.json'* ]]
2222
}
23+
24+
@test "runc run [ro tmpfs mount]" {
25+
update_config ' .mounts += [{"source": "tmpfs", "destination": "/mnt", "type": "tmpfs", "options": ["ro", "nodev", "nosuid", "mode=755"]}]
26+
| .process.args |= ["grep", "^tmpfs /mnt", "/proc/mounts"]'
27+
28+
runc run test_ro_tmpfs_mount
29+
[ "$status" -eq 0 ]
30+
[[ "${lines[0]}" == *'ro,'* ]]
31+
}

0 commit comments

Comments
 (0)