Add fuse prog types to allowed prog types from system

Until fuse-bpf is upstreamed, the value BPF_PROG_TYPE_FUSE is
dynamically defined, so use BPF_PROG_TYPE_UNSPEC as a placeholder and read
the actual value from sys/fs/fuse

Bug: 202785178
Test: fuse bpf can be enabled successfully
Change-Id: I67d3ff45768b581a6b239e235edaa6e46a2f6fe0
This commit is contained in:
Paul Lawrence 2022-07-19 16:13:49 -07:00
parent 15f1bf8928
commit 7fb8b546e3
2 changed files with 12 additions and 6 deletions

View file

@ -107,6 +107,7 @@ constexpr bpf_prog_type kPlatformAllowedProgTypes[] = {
BPF_PROG_TYPE_PERF_EVENT, BPF_PROG_TYPE_PERF_EVENT,
BPF_PROG_TYPE_SOCKET_FILTER, BPF_PROG_TYPE_SOCKET_FILTER,
BPF_PROG_TYPE_TRACEPOINT, 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 // see b/162057235. For arbitrary program types, the concern is that due to the lack of

View file

@ -354,16 +354,18 @@ static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) {
return 0; 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) { static enum bpf_prog_type getSectionType(string& name) {
for (auto& snt : sectionNameTypes) for (auto& snt : sectionNameTypes)
if (StartsWith(name, snt.name)) return snt.type; 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 // TODO Remove this code when fuse-bpf is upstream and this BPF_PROG_TYPE_FUSE is fixed
if (StartsWith(name, "fuse/")) { if (StartsWith(name, "fuse/")) return getFuseProgType();
int result = BPF_PROG_TYPE_UNSPEC;
ifstream("/sys/fs/fuse/bpf_prog_type_fuse") >> result;
return static_cast<bpf_prog_type>(result);
}
return BPF_PROG_TYPE_UNSPEC; return BPF_PROG_TYPE_UNSPEC;
} }
@ -465,7 +467,10 @@ static bool IsAllowed(bpf_prog_type type, const bpf_prog_type* allowed, size_t n
if (allowed == nullptr) return true; if (allowed == nullptr) return true;
for (size_t i = 0; i < numAllowed; i++) { 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; return false;