Skip to content

Commit

Permalink
Merge pull request #2897 from kolyshkin/fix-ro-paths
Browse files Browse the repository at this point in the history
runc run: fix readonly path error for rootless + host pidns
  • Loading branch information
Mrunal Patel authored Apr 19, 2021
2 parents fce58ab + 31dd1e4 commit 3a20ccb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,9 +931,20 @@ func readonlyPath(path string) error {
if os.IsNotExist(err) {
return nil
}
return err
return &os.PathError{Op: "bind-mount", Path: path, Err: err}
}

var s unix.Statfs_t
if err := unix.Statfs(path, &s); err != nil {
return &os.PathError{Op: "statfs", Path: path, Err: err}
}
return unix.Mount(path, path, "", unix.MS_BIND|unix.MS_REMOUNT|unix.MS_RDONLY|unix.MS_REC, "")
flags := uintptr(s.Flags) & (unix.MS_NOSUID | unix.MS_NODEV | unix.MS_NOEXEC)

if err := unix.Mount(path, path, "", flags|unix.MS_BIND|unix.MS_REMOUNT|unix.MS_RDONLY, ""); err != nil {
return &os.PathError{Op: "bind-mount-ro", Path: path, Err: err}
}

return nil
}

// remountReadonly will remount an existing mount point and ensure that it is read-only.
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/start_hello.bats
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,20 @@ function teardown() {

[[ "$(cat pid.txt)" =~ [0-9]+ ]]
}

# https://github.com/opencontainers/runc/pull/2897
@test "runc run [rootless with host pidns]" {
requires rootless_no_features

# Remove pid namespace, and replace /proc mount
# with a bind mount from the host.
update_config ' .linux.namespaces -= [{"type": "pid"}]
| .mounts |= map((select(.type == "proc")
| .type = "none"
| .source = "/proc"
| .options = ["rbind", "nosuid", "nodev", "noexec"]
) // .)'

runc run test_hello
[ "$status" -eq 0 ]
}

0 comments on commit 3a20ccb

Please sign in to comment.