]> Cypherpunks repositories - gostls13.git/commitdiff
internal/syscall/unix: Eaccess: return ENOSYS on Android
authorKir Kolyshkin <kolyshkin@gmail.com>
Thu, 5 Sep 2024 21:14:59 +0000 (14:14 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 6 Sep 2024 13:49:31 +0000 (13:49 +0000)
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 <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/internal/syscall/unix/eaccess.go

index 531fd2f1067b24d75bab5e26047cd9ef35d53242..3c12314a9c7d4495458e922f5838b8ec99d5756b 100644 (file)
@@ -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)
 }