From 8cd550a2327e921ddc202e960df6db8bfe4ef222 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 5 Sep 2024 14:14:59 -0700 Subject: [PATCH] internal/syscall/unix: Eaccess: return ENOSYS on Android On Android, faccessat2 syscall (which supports flags like AT_EACCESS) is not allowed, so syscall.Faccessat tries to emulate AT_EACCESS check in userspace using os.Stat, os.Geteuid etc. Also, according to [1], > Android doesn't have setuid programs, and never runs code with euid!=uid. This means on Android the proper AT_EACCESS check is neither possible nor really needed. Let's skip the syscall.Faccessat userspace emulation of AT_EACCESS check and return ENOSYS, so the callers can use a fallback. This should speed up exec.LookPath on Android. [1]: https://android.googlesource.com/platform/bionic/+/508b2f6e5cba4bdadf1e47a4ff27e25ce66c40e3/libc/bionic/faccessat.cpp#50 Change-Id: If7b529fa314480b70e9ae9cdd8c7ce82cd55d233 Reviewed-on: https://go-review.googlesource.com/c/go/+/611298 Reviewed-by: Ian Lance Taylor Reviewed-by: Tobias Klauser Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- src/internal/syscall/unix/eaccess.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/internal/syscall/unix/eaccess.go b/src/internal/syscall/unix/eaccess.go index 531fd2f106..3c12314a9c 100644 --- a/src/internal/syscall/unix/eaccess.go +++ b/src/internal/syscall/unix/eaccess.go @@ -6,6 +6,19 @@ package unix +import ( + "runtime" + "syscall" +) + func Eaccess(path string, mode uint32) error { + if runtime.GOOS == "android" { + // syscall.Faccessat for Android implements AT_EACCESS check in + // userspace. Since Android doesn't have setuid programs and + // never runs code with euid!=uid, AT_EACCESS check is not + // really required. Return ENOSYS so the callers can fall back + // to permission bits check. + return syscall.ENOSYS + } return faccessat(AT_FDCWD, path, mode, AT_EACCESS) } -- 2.48.1