Skip to content

Commit fa722c1

Browse files
Dzejroukolyshkin
authored andcommitted
libcontainer: skip chown of /dev/null caused by fd redirection
In 18c4760 (libct: fixStdioPermissions: skip chown if not needed) the check whether the STDIO file descriptors point to /dev/null was removed which can cause /dev/null to change ownership e.g. when using docker exec on a running container: $ ls -l /dev/null crw-rw-rw- 1 root root 1, 3 Aug 1 14:12 /dev/null $ docker exec -u test 0ad6d3064e9d ls $ ls -l /dev/null crw-rw-rw- 1 test root 1, 3 Aug 1 14:12 /dev/null Signed-off-by: Jaroslav Jindrak <[email protected]> (cherry picked from commit 7e5e017) Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent bec9736 commit fa722c1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libcontainer/init_linux.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ func fixStdioPermissions(u *user.ExecUser) error {
411411
return &os.PathError{Op: "fstat", Path: file.Name(), Err: err}
412412
}
413413

414-
// Skip chown if uid is already the one we want.
415-
if int(s.Uid) == u.Uid {
414+
// Skip chown if uid is already the one we want or any of the STDIO descriptors
415+
// were redirected to /dev/null.
416+
if int(s.Uid) == u.Uid || s.Rdev == null.Rdev {
416417
continue
417418
}
418419

0 commit comments

Comments
 (0)