From 2d52f8c1392e993758f8ddb595257e1bb37e5aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 25 Sep 2024 22:14:04 +0000 Subject: [PATCH] NetBpfLoad: don't allow prog-less bpf .o's targetting platform bpfloader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I0360c8bb7486b3ed125c0fd0d40b4b8d97bfb3e3 --- bpf/loader/NetBpfLoad.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index f36945891b..9a049c7bd9 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -59,6 +59,9 @@ #include "bpf/BpfUtils.h" #include "bpf_map_def.h" +// The following matches bpf_helpers.h, which is only for inclusion in bpf code +#define BPFLOADER_MAINLINE_VERSION 42u + using android::base::EndsWith; using android::base::GetIntProperty; using android::base::GetProperty; @@ -1154,7 +1157,10 @@ int loadProg(const char* const elfPath, const unsigned int bpfloader_ver, ALOGV("map_fd found at %d is %d in %s", i, mapFds[i].get(), elfPath); ret = readCodeSections(elfFile, cs); - if (ret == -ENOENT) return 0; // no programs defined in this .o + // BPF .o's with no programs are only supported by mainline netbpfload, + // make sure .o's targeting non-mainline (ie. S) bpfloader don't show up. + if (ret == -ENOENT && bpfLoaderMinVer >= BPFLOADER_MAINLINE_VERSION) + return 0; if (ret) { ALOGE("Couldn't read all code sections in %s", elfPath); return ret; @@ -1419,7 +1425,7 @@ static int doLoad(char** argv, char * const envp[]) { const bool has_platform_netbpfload_rc = exists("/system/etc/init/netbpfload.rc"); // Version of Network BpfLoader depends on the Android OS version - unsigned int bpfloader_ver = 42u; // [42] BPFLOADER_MAINLINE_VERSION + unsigned int bpfloader_ver = BPFLOADER_MAINLINE_VERSION; // [42u] if (isAtLeastT) ++bpfloader_ver; // [43] BPFLOADER_MAINLINE_T_VERSION if (isAtLeastU) ++bpfloader_ver; // [44] BPFLOADER_MAINLINE_U_VERSION if (runningAsRoot) ++bpfloader_ver; // [45] BPFLOADER_MAINLINE_U_QPR3_VERSION