From 5765db482cd722f1909f85db9ebef65a6f50ca11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 29 Jul 2025 17:27:11 -0700 Subject: [PATCH] bpf_map_def: increase BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE from 32 to 66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit will allow us to store full pin location, longest we currently have is 64 + NULL: $ adb shell find /sys/fs/bpf | egrep net | egrep '.{64}' /sys/fs/bpf/netd_shared/prog_netd_cgroupsockrelease_inet_release $ adb shell find /sys/fs/bpf | egrep net | egrep '.{65}' Choose small value so we don't needlessly bloat the .o's. This can be trivially increased on demand. Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski Change-Id: I62015d2703fdee004fb7279d8f9ca83f7462a4df --- bpf/loader/NetBpfLoad.cpp | 2 +- bpf/progs/include/bpf_map_def.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 490e07071b..6cf7239476 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -120,7 +120,7 @@ void validatePinDir(const char s[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]) { if (!strncmp(s, "netd_shared/", BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE)) return; if (!strncmp(s, "loader/", BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE)) return; } - ALOGE("unrecognized pin_subdir '%-32s'", s); + ALOGE("unrecognized pin_subdir '%-*s'", BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE, s); // Note: we *can* just abort() here as we only load bpf .o files shipped // in the same mainline module / apex as NetBpfLoad itself. abort(); diff --git a/bpf/progs/include/bpf_map_def.h b/bpf/progs/include/bpf_map_def.h index 635dee5f92..9185478308 100644 --- a/bpf/progs/include/bpf_map_def.h +++ b/bpf/progs/include/bpf_map_def.h @@ -105,7 +105,7 @@ struct optional_bool { bool optional; }; // Length of strings (incl. selinux_context and pin_subdir) // in the bpf_map_def and bpf_prog_def structs. -#define BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE 32 +#define BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE 66 // must be even for alignment sanity /* * Map structure to be used by Android eBPF C programs. The Android eBPF loader @@ -152,7 +152,7 @@ struct bpf_map_def { // This needs to be updated whenever the above structure definition is expanded. // These asserts are here to make sure we have cross-6-arch consistency. -_Static_assert(sizeof(struct bpf_map_def) == 112, "sizeof struct bpf_map_def != 112"); +_Static_assert(sizeof(struct bpf_map_def) == 48 + 2 * BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE, "wrong sizeof struct bpf_map_def"); _Static_assert(__alignof__(struct bpf_map_def) == 4, "__alignof__ struct bpf_map_def != 4"); _Static_assert(_Alignof(struct bpf_map_def) == 4, "_Alignof struct bpf_map_def != 4"); @@ -177,6 +177,6 @@ struct bpf_prog_def { // This needs to be updated whenever the above structure definition is expanded. // These asserts are here to make sure we have cross-6-arch consistency. -_Static_assert(sizeof(struct bpf_prog_def) == 92, "sizeof struct bpf_prog_def != 92"); +_Static_assert(sizeof(struct bpf_prog_def) == 28 + 2 * BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE, "wrong sizeof struct bpf_prog_def"); _Static_assert(__alignof__(struct bpf_prog_def) == 4, "__alignof__ struct bpf_prog_def != 4"); _Static_assert(_Alignof(struct bpf_prog_def) == 4, "_Alignof struct bpf_prog_def != 4");