diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index b184caa99b..378a9d6520 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -1910,13 +1910,30 @@ static int doLoad(char** argv, char * const envp[]) { return 2; } - int key = 1; - int value = 123; - unique_fd map( - createMap(BPF_MAP_TYPE_ARRAY, sizeof(key), sizeof(value), 2, 0)); - if (writeToMapEntry(map, &key, &value, BPF_ANY)) { - ALOGE("Critical kernel bug - failure to write into index 1 of 2 element bpf map array."); - if (isAtLeastT) return 1; + { + // Create a trivial bpf map: a two element array [int->int] + unique_fd map(createMap(BPF_MAP_TYPE_ARRAY, sizeof(int), sizeof(int), 2, 0)); + + int zero = 0; + int kernel_bugs = bpfCmdFixupIsNeeded; + if (writeToMapEntry(map, &zero, &kernel_bugs, BPF_ANY)) { + ALOGE("Failure to write into index 0 of kernel bugs array."); + return 1; + } + + int one = 1; + int value = 123; + if (writeToMapEntry(map, &one, &value, BPF_ANY)) { + ALOGE("Critical kernel bug - failure to write into index 1 of 2 element bpf map array."); + if (isAtLeastT) return 1; + } + + int ret = bpfFdPin(map, "/sys/fs/bpf/tethering/map_kernel_bugs"); + if (ret) { + const int err = errno; + ALOGE("pin -> %d [%d:%s]", ret, err, strerror(err)); + return -err; + } } // leave a flag that we're done diff --git a/bpf/tests/mts/bpf_existence_test.cpp b/bpf/tests/mts/bpf_existence_test.cpp index a6c774f83a..3a2d962bb2 100644 --- a/bpf/tests/mts/bpf_existence_test.cpp +++ b/bpf/tests/mts/bpf_existence_test.cpp @@ -60,6 +60,7 @@ static const set PLATFORM_ONLY_IN_R = { // Provided by *current* mainline module for S+ devices static const set MAINLINE_FOR_S_PLUS = { + TETHERING "map_kernel_bugs", TETHERING "map_offload_tether_dev_map", TETHERING "map_offload_tether_downstream4_map", TETHERING "map_offload_tether_downstream64_map",