Skip to content

Commit 4c22153

Browse files
authored
Merge pull request #4679 from rata/misc
libct: Use chown(uid, -1) to not change the gid
2 parents fde0842 + 9c5e687 commit 4c22153

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libcontainer/init_linux.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,17 @@ func fixStdioPermissions(uid int) error {
524524
// that users expect to be able to actually use their console. Without
525525
// this code, you couldn't effectively run as a non-root user inside a
526526
// container and also have a console set up.
527-
if err := file.Chown(uid, int(s.Gid)); err != nil {
528-
// If we've hit an EINVAL then s.Gid isn't mapped in the user
529-
// namespace. If we've hit an EPERM then the inode's current owner
527+
if err := file.Chown(uid, -1); err != nil {
528+
// If we've hit an EPERM then the inode's current owner
530529
// is not mapped in our user namespace (in particular,
531530
// privileged_wrt_inode_uidgid() has failed). Read-only
532531
// /dev can result in EROFS error. In any case, it's
533532
// better for us to just not touch the stdio rather
534533
// than bail at this point.
535-
536-
if errors.Is(err, unix.EINVAL) || errors.Is(err, unix.EPERM) || errors.Is(err, unix.EROFS) {
534+
// EINVAL should never happen, as it would mean the uid
535+
// is not mapped, we expect this function to be called
536+
// with a mapped uid.
537+
if errors.Is(err, unix.EPERM) || errors.Is(err, unix.EROFS) {
537538
continue
538539
}
539540
return err

0 commit comments

Comments
 (0)