Skip to content

Commit

Permalink
Merge pull request #216 from giuseppe/userns-restore-setuid-setgid
Browse files Browse the repository at this point in the history
chown: restore SUID and SGID bits
  • Loading branch information
nalind authored Sep 25, 2018
2 parents 1d49427 + 2df72f3 commit 68332c0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/chown_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ func platformLChown(path string, info os.FileInfo, toHost, toContainer *idtools.
uid, gid = mappedPair.UID, mappedPair.GID
}
if uid != int(st.Uid) || gid != int(st.Gid) {
stat, err := os.Lstat(path)
if err != nil {
return fmt.Errorf("%s: lstat(%q): %v", os.Args[0], path, err)
}
// Make the change.
if err := syscall.Lchown(path, uid, gid); err != nil {
return fmt.Errorf("%s: chown(%q): %v", os.Args[0], path, err)
}
// Restore the SUID and SGID bits if they were originally set.
if (stat.Mode()&os.ModeSymlink == 0) && stat.Mode()&(os.ModeSetuid|os.ModeSetgid) != 0 {
if err := os.Chmod(path, stat.Mode()); err != nil {
return fmt.Errorf("%s: chmod(%q): %v", os.Args[0], path, err)
}
}
}
}
return nil
Expand Down

0 comments on commit 68332c0

Please sign in to comment.