diff --git a/libcontainer/init_linux.go b/libcontainer/init_linux.go index 1e5c394c3e0..2e4c59353c8 100644 --- a/libcontainer/init_linux.go +++ b/libcontainer/init_linux.go @@ -411,8 +411,9 @@ func fixStdioPermissions(u *user.ExecUser) error { return &os.PathError{Op: "fstat", Path: file.Name(), Err: err} } - // Skip chown if uid is already the one we want. - if int(s.Uid) == u.Uid { + // Skip chown if uid is already the one we want or any of the STDIO descriptors + // were redirected to /dev/null. + if int(s.Uid) == u.Uid || s.Rdev == null.Rdev { continue } diff --git a/tests/integration/exec.bats b/tests/integration/exec.bats index 140cd181011..47c047bd638 100644 --- a/tests/integration/exec.bats +++ b/tests/integration/exec.bats @@ -125,10 +125,25 @@ function teardown() { runc exec --user 1000:1000 test_busybox id [ "$status" -eq 0 ] - [[ "${output}" == "uid=1000 gid=1000"* ]] } +# https://github.com/opencontainers/runc/issues/3674. +@test "runc exec --user vs /dev/null ownership" { + requires root + + runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox + [ "$status" -eq 0 ] + + ls -l /dev/null + __runc exec -d --user 1000:1000 test_busybox id