Skip to content

Commit 981b614

Browse files
committed
unix: 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. Fixes golang/go#39660 Change-Id: Idb841242cbd1d8859f4e3c2c26b64a5e9523f9a4 Reviewed-on: https://go-review.googlesource.com/c/sys/+/238722 Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f1bc736 commit 981b614

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

unix/syscall_linux.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,20 @@ func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
19501950
return int(n), nil
19511951
}
19521952

1953+
func isGroupMember(gid int) bool {
1954+
groups, err := Getgroups()
1955+
if err != nil {
1956+
return false
1957+
}
1958+
1959+
for _, g := range groups {
1960+
if g == gid {
1961+
return true
1962+
}
1963+
}
1964+
return false
1965+
}
1966+
19531967
//sys faccessat(dirfd int, path string, mode uint32) (err error)
19541968

19551969
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
@@ -2007,7 +2021,7 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
20072021
gid = Getgid()
20082022
}
20092023

2010-
if uint32(gid) == st.Gid {
2024+
if uint32(gid) == st.Gid || isGroupMember(gid) {
20112025
fmode = (st.Mode >> 3) & 7
20122026
} else {
20132027
fmode = st.Mode & 7

0 commit comments

Comments
 (0)