diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 4c2df43d8c..d4dc38d62e 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -880,13 +880,6 @@ static enum bpf_map_type sanitizeMapType(enum bpf_map_type type) { return type; } -static string buildMapPinLoc(const char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE], - const string& objName, const string& mapName) { - // Format of pin location is /sys/fs/bpf/map__ - // Note: refers to the extension-less basename of the .o file (without @ suffix). - return string(BPF_FS_PATH) + pin_subdir + "map_" + objName + "_" + mapName; -} - static int createMaps(const char* elfPath, ifstream& elfFile, vector& mapFds, const unsigned int bpfloader_ver) { int ret; @@ -967,7 +960,7 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector& if (max_entries < page_size) max_entries = page_size; } - string mapPinLoc = buildMapPinLoc(md[i].pin_subdir, objName, mapNames[i]); + string mapPinLoc = string(md[i].pin_prefix) + mapNames[i]; unique_fd fd; int saved_errno; @@ -1368,7 +1361,7 @@ static int pinMaps(const char* const elfPath, const struct bpf_object* obj, // This map was skipped if (!bpf_map__autocreate(m)) continue; - string mapPinLoc = buildMapPinLoc(md[i].pin_subdir, objName, mapNames[i]); + string mapPinLoc = string(md[i].pin_prefix) + mapNames[i]; if (access(mapPinLoc.c_str(), F_OK) == 0) { ALOGE("Reusing map is not supported: %s", mapNames[i].c_str()); return -1; diff --git a/bpf/progs/include/bpf_helpers.h b/bpf/progs/include/bpf_helpers.h index 53daa7470e..abf0994db3 100644 --- a/bpf/progs/include/bpf_helpers.h +++ b/bpf/progs/include/bpf_helpers.h @@ -260,7 +260,7 @@ static int (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, .min_kver = (minkver).kver, \ .max_kver = (maxkver).kver, \ .create_location = CREATE_LOCATION(selinux), \ - .pin_subdir = pindir "/", \ + .pin_prefix = "/sys/fs/bpf/" pindir "/map_" BPF_OBJ_NAME "_", \ }; #define __uint(name, val) int (*name)[val] diff --git a/bpf/progs/include/bpf_map_def.h b/bpf/progs/include/bpf_map_def.h index 8b998f9bbc..3034e496da 100644 --- a/bpf/progs/include/bpf_map_def.h +++ b/bpf/progs/include/bpf_map_def.h @@ -141,13 +141,9 @@ struct bpf_map_def { unsigned int min_kver; unsigned int max_kver; - // These are fixed length strings, padded with null bytes - // - // overrides default selinux context (which is based on pin subdir) + // These are fixed length ASCIIZ strings, padded with null bytes char create_location[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; - // - // overrides default prefix (which is based on .o location) - char pin_subdir[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; + char pin_prefix[BPF_PIN_SUBDIR_CHAR_ARRAY_SIZE]; }; // This needs to be updated whenever the above structure definition is expanded.