NetBpfLoad: create/populate/pin kernel bugs bpf array
This is an array of two ints: - index 0 should have value 0 (a value of 1 implies a kernel uapi bug) - index 1 should have value 123 (a value of 0 implies bpf array writes at non-zero index fail) Note that these bugs can only be present on Android S & Sv2, as these kernel bugs are considered fatal on Android T+. (btw. we need to do this write manually as we cannot write into maps we pin and then reopen - due to sepolicy) Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I9b2ada7f3e299014d39461a8d0718396daf0c91a
This commit is contained in:
parent
798e2f5f87
commit
83d5ad1d85
2 changed files with 25 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ static const set<string> PLATFORM_ONLY_IN_R = {
|
|||
|
||||
// Provided by *current* mainline module for S+ devices
|
||||
static const set<string> 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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue