commit | 65075bb8f8290125fbd0ce8ffc5aaab6bdb3284e | [log] [tgz] |
---|---|---|
author | Maciej Żenczykowski <maze@google.com> | Thu Jun 01 23:09:14 2023 +0000 |
committer | Maciej Żenczykowski <maze@google.com> | Fri Jun 02 03:44:11 2023 +0000 |
tree | 1a31435c777501185f05c770d3d4c3c18241dfa7 | |
parent | 5e76b409739ef593ad537cfc067e5860e67490e1 [diff] [blame] |
BpfHandler: abort on U+ if unexpected cgroup mount path This is defined here: http://cs/h/android/platform/superproject/+/master:system/core/libprocessgroup/profiles/cgroups.json?l=27 and has been a constant since https://android-review.googlesource.com/c/platform/system/core/+/1324649 was merged back on August 21, 2020 (ie. Android S) But currently there's no easy way to get at this constant from mainline code... which means it's very difficult to do any bpf cgroup attach/detach from mainline. btw. this appears to also be already hardcoded in: http://cs/h/android/platform/superproject/+/master:packages/modules/Connectivity/service/src/com/android/server/connectivity/ConnectivityNativeService.java?l=48 as well Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I99f4a5a26dd10f6ea70bf73114af0d18098de630
diff --git a/netd/BpfHandler.cpp b/netd/BpfHandler.cpp index 8081d12..6409374 100644 --- a/netd/BpfHandler.cpp +++ b/netd/BpfHandler.cpp
@@ -21,6 +21,7 @@ #include <linux/bpf.h> #include <android-base/unique_fd.h> +#include <android-modules-utils/sdk_level.h> #include <bpf/WaitForProgsLoaded.h> #include <log/log.h> #include <netdutils/UidConstants.h> @@ -74,9 +75,11 @@ } static Status initPrograms(const char* cg2_path) { + if (modules::sdklevel::IsAtLeastU() && !!strcmp(cg2_path, "/sys/fs/cgroup")) abort(); + unique_fd cg_fd(open(cg2_path, O_DIRECTORY | O_RDONLY | O_CLOEXEC)); if (cg_fd == -1) { - int ret = errno; + const int ret = errno; ALOGE("Failed to open the cgroup directory: %s", strerror(ret)); return statusFromErrno(ret, "Open the cgroup directory failed"); }