Skip to content

Commit 60f7876

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f2bba30 commit 60f7876

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/syscall/syscall_linux.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ func Creat(path string, mode uint32) (fd int, err error) {
3535
return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
3636
}
3737

38+
func isGroupMember(gid int) bool {
39+
groups, err := Getgroups()
40+
if err != nil {
41+
return false
42+
}
43+
44+
for _, g := range groups {
45+
if g == gid {
46+
return true
47+
}
48+
}
49+
return false
50+
}
51+
3852
//sys faccessat(dirfd int, path string, mode uint32) (err error)
3953

4054
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) {
92106
gid = Getgid()
93107
}
94108

95-
if uint32(gid) == st.Gid {
109+
if uint32(gid) == st.Gid || isGroupMember(gid) {
96110
fmode = (st.Mode >> 3) & 7
97111
} else {
98112
fmode = st.Mode & 7

0 commit comments

Comments
 (0)