Merge "Add fuse prog types to allowed prog types from system" am: 73d8f14525

Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2164582

Change-Id: Ife1e285822ea70b62717755743e2d4abc55a5bd1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/bpfloader/BpfLoader.cpp b/bpfloader/BpfLoader.cpp
index b8dd504..f0ff413 100644
--- a/bpfloader/BpfLoader.cpp
+++ b/bpfloader/BpfLoader.cpp
@@ -107,6 +107,7 @@
         BPF_PROG_TYPE_PERF_EVENT,
         BPF_PROG_TYPE_SOCKET_FILTER,
         BPF_PROG_TYPE_TRACEPOINT,
+        BPF_PROG_TYPE_UNSPEC,  // Will be replaced with fuse bpf program type
 };
 
 // see b/162057235. For arbitrary program types, the concern is that due to the lack of
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index 9032aa3..d987f2e 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -358,16 +358,18 @@
     return 0;
 }
 
+static enum bpf_prog_type getFuseProgType() {
+    int result = BPF_PROG_TYPE_UNSPEC;
+    ifstream("/sys/fs/fuse/bpf_prog_type_fuse") >> result;
+    return static_cast<bpf_prog_type>(result);
+}
+
 static enum bpf_prog_type getSectionType(string& name) {
     for (auto& snt : sectionNameTypes)
         if (StartsWith(name, snt.name)) return snt.type;
 
     // TODO Remove this code when fuse-bpf is upstream and this BPF_PROG_TYPE_FUSE is fixed
-    if (StartsWith(name, "fuse/")) {
-        int result = BPF_PROG_TYPE_UNSPEC;
-        ifstream("/sys/fs/fuse/bpf_prog_type_fuse") >> result;
-        return static_cast<bpf_prog_type>(result);
-    }
+    if (StartsWith(name, "fuse/")) return getFuseProgType();
 
     return BPF_PROG_TYPE_UNSPEC;
 }
@@ -469,7 +471,10 @@
     if (allowed == nullptr) return true;
 
     for (size_t i = 0; i < numAllowed; i++) {
-        if (type == allowed[i]) return true;
+        if (allowed[i] == BPF_PROG_TYPE_UNSPEC) {
+            if (type == getFuseProgType()) return true;
+        } else if (type == allowed[i])
+            return true;
     }
 
     return false;