aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/syscall_linux.go
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2020-06-19 10:41:44 +0200
committerTobias Klauser <tobias.klauser@gmail.com>2020-06-20 08:40:13 +0000
commit60f78765022a59725121d3b800268adffe78bde3 (patch)
treebb7eba4835da9d19e9912889c095f21dfd8cfe7f /src/syscall/syscall_linux.go
parentf2bba30e4068695fcb08ddf5006e776c1fd38eca (diff)
downloadgo-60f78765022a59725121d3b800268adffe78bde3.tar.xz
syscall: check secondary group membership for Faccessat(..., AT_EACCESS) on Linux
Follow glibc's implementation and check secondary group memberships using Getgroups. No test since we cannot easily change file permissions when not running as root and the test is meaningless if running as root. Same as CL 238722 did for x/sys/unix Updates #39660 Change-Id: I6af50e27b255e33405558947a0ab3dfbc33b2d50 Reviewed-on: https://go-review.googlesource.com/c/go/+/238937 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/syscall/syscall_linux.go')
-rw-r--r--src/syscall/syscall_linux.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go
index 2eba033d7c..07fe6a6c2b 100644
--- a/src/syscall/syscall_linux.go
+++ b/src/syscall/syscall_linux.go
@@ -35,6 +35,20 @@ func Creat(path string, mode uint32) (fd int, err error) {
return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
}
+func isGroupMember(gid int) bool {
+ groups, err := Getgroups()
+ if err != nil {
+ return false
+ }
+
+ for _, g := range groups {
+ if g == gid {
+ return true
+ }
+ }
+ return false
+}
+
//sys faccessat(dirfd int, path string, mode uint32) (err error)
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
@@ -92,7 +106,7 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
gid = Getgid()
}
- if uint32(gid) == st.Gid {
+ if uint32(gid) == st.Gid || isGroupMember(gid) {
fmode = (st.Mode >> 3) & 7
} else {
fmode = st.Mode & 7