bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: fix faccessat() usage on Android
@ 2024-01-26 22:09 Andrii Nakryiko
  2024-01-28 18:56 ` Jiri Olsa
  2024-01-29 15:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2024-01-26 22:09 UTC (permalink / raw)
  To: bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team

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

Fixes: 6a4ab8869d0b ("libbpf: Fix the case of running as non-root with capabilities")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf_internal.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 930cc9616527..5b30f3b67a02 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -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
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: fix faccessat() usage on Android
  2024-01-26 22:09 [PATCH bpf-next] libbpf: fix faccessat() usage on Android Andrii Nakryiko
@ 2024-01-28 18:56 ` Jiri Olsa
  2024-01-29 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2024-01-28 18:56 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, martin.lau, kernel-team

On Fri, Jan 26, 2024 at 02:09:44PM -0800, Andrii Nakryiko wrote:
> 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
> 
> Fixes: 6a4ab8869d0b ("libbpf: Fix the case of running as non-root with capabilities")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> ---
>  tools/lib/bpf/libbpf_internal.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 930cc9616527..5b30f3b67a02 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -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
>  
> -- 
> 2.34.1
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: fix faccessat() usage on Android
  2024-01-26 22:09 [PATCH bpf-next] libbpf: fix faccessat() usage on Android Andrii Nakryiko
  2024-01-28 18:56 ` Jiri Olsa
@ 2024-01-29 15:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-29 15:30 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, martin.lau, kernel-team

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Fri, 26 Jan 2024 14:09:44 -0800 you wrote:
> 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
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-29 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-26 22:09 [PATCH bpf-next] libbpf: fix faccessat() usage on Android Andrii Nakryiko
2024-01-28 18:56 ` Jiri Olsa
2024-01-29 15:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).