libbpf: fix faccessat() usage on Android
Andrii Nakryiko
maintainerPATCH 1/1 libbpf: fix faccessat() usage on Android
Android implementation of libc errors out with -EINVAL in faccessat() if passed AT_EACCESS ([0]), this leads to ridiculous issue with libbpf refusing to load /sys/kernel/btf/vmlinux on Androids ([1]). Fix by detecting Android and redefining AT_EACCESS to 0, it's equivalent on Android.
[0] https://android.googlesource.com/platform/bionic/+/refs/heads/android13-release/libc/bionic/faccessat.cpp#50
[1] https://github.com/libbpf/libbpf-bootstrap/issues/250#issuecomment-1911324250
--- tools/lib/bpf/libbpf_internal.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/lib/bpf/libbpf_internal.h +14 -0
@@ -19,6 +19,20 @@#include <libelf.h> #include "relo_core.h" +/* Android's libc doesn't support AT_EACCESS in faccessat() implementation +* ([0]), and just returns -EINVAL even if file exists and is accessible. +* See [1] for issues caused by this. +* +* So just redefine it to 0 on Android. +* +* [0] https://android.googlesource.com/platform/bionic/+/refs/heads/android13-release/libc/bionic/faccessat.cpp#50 +* [1] https://github.com/libbpf/libbpf-bootstrap/issues/250#issuecomment-1911324250 +*/ +#ifdef __ANDROID__ +#undef AT_EACCESS +#define AT_EACCESS 0 +#endif +/* make sure libbpf doesn't use kernel-only integer typedefs */ #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
Signature · 1 line
2.34.1
Quoted 11 lines · Andrii Nakryiko
Android implementation of libc errors out with
-EINVALinfaccessat()if passedAT_EACCESS([0]), this leads to ridiculous issue with libbpf refusing to load/sys/kernel/btf/vmlinuxon Androids ([1]). Fix by detecting Android and redefiningAT_EACCESSto 0, it's equivalent on Android.[0] https://android.googlesource.com/platform/bionic/+/refs/heads/android13-release/libc/bionic/faccessat.cpp#50
[1] https://github.com/libbpf/libbpf-bootstrap/issues/250#issuecomment-1911324250Fixes 6a4ab8869d0b ("libbpf: Fix the case of running as non-root with capabilities")Signed-off-by Andrii Nakryiko <[email protected]>
jirka
Quoted 33 lines
--- tools/lib/bpf/libbpf_internal.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)tools/lib/bpf/libbpf_internal.h +14
-0@@ -19,6 +19,20 @@#include <libelf.h> #include "relo_core.h" +/* Android's libc doesn't support AT_EACCESS in faccessat() implementation +* ([0]), and just returns -EINVAL even if file exists and is accessible. +* See [1] for issues caused by this. +* +* So just redefine it to 0 on Android. +* +* [0] https://android.googlesource.com/platform/bionic/+/refs/heads/android13-release/libc/bionic/faccessat.cpp#50 +* [1] https://github.com/libbpf/libbpf-bootstrap/issues/250#issuecomment-1911324250 +*/ +#ifdef __ANDROID__ +#undef AT_EACCESS +#define AT_EACCESS 0 +#endif +/* make sure libbpf doesn't use kernel-only integer typedefs */ #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64Signature · 1 line
2.34.1
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 10 lines · On Fri, 26 Jan 2024 14:09:44 -0800 you wrote:
Android implementation of libc errors out with
-EINVALinfaccessat()if passedAT_EACCESS([0]), this leads to ridiculous issue with libbpf refusing to load/sys/kernel/btf/vmlinuxon Androids ([1]). Fix by detecting Android and redefiningAT_EACCESSto 0, it's equivalent on Android.[0] https://android.googlesource.com/platform/bionic/+/refs/heads/android13-release/libc/bionic/faccessat.cpp#50
[1] https://github.com/libbpf/libbpf-bootstrap/issues/250#issuecomment-1911324250[...]
Here is the summary with links:
- [bpf-next] libbpf: fix faccessat() usage on Android
https://git.kernel.org/bpf/bpf-next/c/ad5765405380
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html