Skip to content

Commit

Permalink
libcontainer: skip chown of /dev/null caused by fd redirection
Browse files Browse the repository at this point in the history
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 <dzejrou@gmail.com>
  • Loading branch information
Dzejrou committed Feb 3, 2023
1 parent 32d7413 commit 7e5e017
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7e5e017

Please sign in to comment.