From 2a2ee0af443dbd8d924c26706445f1660d423ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 29 Jul 2025 14:22:22 -0700 Subject: [PATCH 1/2] Tweak: Throw exception for oversized BpfMap keys/values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Throw an IllegalArgumentException if the key or value sizes exceed the limits supported by the BpfMap implementation. This prevents potential file descriptor cache collisions and makes errors explicit. Test: TreeHugger Flag: EXEMPT mainline/noop Signed-off-by: Maciej Żenczykowski Change-Id: I3b2b533e4217ee2ab8bfcd71e93b02ffcf9feba9 --- staticlibs/device/com/android/net/module/util/BpfMap.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/staticlibs/device/com/android/net/module/util/BpfMap.java b/staticlibs/device/com/android/net/module/util/BpfMap.java index 0fbc25de7b..7dbe2c494c 100644 --- a/staticlibs/device/com/android/net/module/util/BpfMap.java +++ b/staticlibs/device/com/android/net/module/util/BpfMap.java @@ -84,8 +84,12 @@ public class BpfMap implements IBpfMap throws ErrnoException, NullPointerException { // Supports up to 1023 byte key and 65535 byte values // Creating a BpfMap with larger keys/values seems like a bad idea any way... - keySize &= 1023; // 10-bits - valueSize &= 65535; // 16-bits + if (keySize > 1023) { + throw new IllegalArgumentException("Key size " + keySize + " exceeds 1023"); + } + if (valueSize > 65535) { + throw new IllegalArgumentException("Value size " + valueSize + " exceeds 65535"); + } var key = Pair.create(path, (mode << 26) ^ (keySize << 16) ^ valueSize); // unlocked fetch is safe: map is concurrent read capable, and only inserted into ParcelFileDescriptor fd = sFdCache.get(key); From 08ad51519af44c3a5812207bd1396d4acdd862fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 29 Jul 2025 16:38:57 -0700 Subject: [PATCH 2/2] NetBpfLoad: remove foo@1.o support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No longer needed now that we have a single loader which can support everything. Test: TreeHugger Flag: EXEMPT mainline/noop Signed-off-by: Maciej Żenczykowski Change-Id: I74c24016265a2b41d818d55c98cbabde04687dd8 --- bpf/loader/NetBpfLoad.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 6dae1b5b62..fa0b6f1fec 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -127,13 +127,10 @@ void validatePinDir(const char s[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]) { } static string pathToObjName(const string& path) { - // extract everything after the final slash, ie. this is the filename 'foo@1.o' or 'bar.o' + // extract everything after the final slash, ie. this is the filename 'foo.o' string filename = Split(path, "/").back(); - // strip off everything from the final period onwards (strip '.o' suffix), ie. 'foo@1' or 'bar' - string name = filename.substr(0, filename.find_last_of('.')); - // strip any potential @1 suffix, this will leave us with just 'foo' or 'bar' - // this can be used to provide duplicate programs (mux based on the bpfloader version) - return name.substr(0, name.find_last_of('@')); + // strip off everything from the final period onwards (strip '.o' suffix), ie. 'foo' + return filename.substr(0, filename.find_last_of('.')); } typedef struct {