From 1758f413a2bf3193170ef2a082d7747489eba64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Mon, 13 Jan 2025 12:18:47 -0800 Subject: [PATCH] Check supported kernel version in V and 25Q2+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V requires 4.19+ and 25Q2+ requires 5.4+ (while 25Q4 will presumably further bump to 5.10+) On aosp/main we currently have: ro.build.version.sdk=35 - which is returned by android_get_device_api_level() ro.build.version.codename=Baklava - which is looked at by IsAtLeastPreReleaseCodename/GetCodename This is because we're already past the aosp/main automerge into 25Q1 cutoff. Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I909d63406151fbafc15fa248133b9d1a5dc37bdb --- bpf/netd/BpfHandler.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bpf/netd/BpfHandler.cpp b/bpf/netd/BpfHandler.cpp index 340acda0ad..bcd0cbac46 100644 --- a/bpf/netd/BpfHandler.cpp +++ b/bpf/netd/BpfHandler.cpp @@ -70,6 +70,13 @@ static Status checkProgramAccessible(const char* programPath) { return netdutils::status::ok; } +// Checks if the device is running on release version of Android 25Q2 or newer. +static bool isAtLeast25Q2() { + return android_get_device_api_level() >= 36 || + (android_get_device_api_level() == 35 && + modules::sdklevel::detail::IsAtLeastPreReleaseCodename("Baklava")); +} + static Status initPrograms(const char* cg2_path) { if (!cg2_path) return Status("cg2_path is NULL"); @@ -91,6 +98,16 @@ static Status initPrograms(const char* cg2_path) { return Status("U+ platform with cg2_path != /sys/fs/cgroup is unsupported"); } + // V bumps the kernel requirement up to 4.19 + if (modules::sdklevel::IsAtLeastV() && !bpf::isAtLeastKernelVersion(4, 19, 0)) { + return Status("V+ platform with kernel version < 4.19.0 is unsupported"); + } + + // 25Q2 bumps the kernel requirement up to 5.4 + if (isAtLeast25Q2() && !bpf::isAtLeastKernelVersion(5, 4, 0)) { + return Status("25Q2+ platform with kernel version < 5.4.0 is unsupported"); + } + unique_fd cg_fd(open(cg2_path, O_DIRECTORY | O_RDONLY | O_CLOEXEC)); if (!cg_fd.ok()) { const int err = errno;