diff options
author | Maciej Żenczykowski <maze@google.com> | 2022-12-05 13:33:43 +0000 |
---|---|---|
committer | Maciej Żenczykowski <maze@google.com> | 2022-12-05 15:57:00 +0000 |
commit | ebfacde967d8ec31bcd484ee8a4d63e0d0cc35ba (patch) | |
tree | e3cd8fab02510aa6ad087a8f89daf4db0ec392f0 /bpfloader/BpfLoader.cpp | |
parent | 9a2093d38c2f9e1f8f2f5341cc8b6fd9ad8b2dec (diff) | |
download | bpf-ebfacde967d8ec31bcd484ee8a4d63e0d0cc35ba.tar.gz |
BpfLoader - create /sys/fs/bpf/loader
we also take this opportunity to enforce that all the
directory creations actually succeed (there really
is no reason why that could fail though)
Test: TreeHugger, manually inspected /sys/fs/bpf contents on cuttlefish
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icd7c1e6eba5736a58cf81476ddafc70df2807dd4
Diffstat (limited to 'bpfloader/BpfLoader.cpp')
-rw-r--r-- | bpfloader/BpfLoader.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/bpfloader/BpfLoader.cpp b/bpfloader/BpfLoader.cpp index fd261b5..c29c97e 100644 --- a/bpfloader/BpfLoader.cpp +++ b/bpfloader/BpfLoader.cpp @@ -218,7 +218,7 @@ int loadAllElfObjects(const Location& location) { return retVal; } -void createSysFsBpfSubDir(const char* const prefix) { +int createSysFsBpfSubDir(const char* const prefix) { if (*prefix) { mode_t prevUmask = umask(0); @@ -228,11 +228,14 @@ void createSysFsBpfSubDir(const char* const prefix) { errno = 0; int ret = mkdir(s.c_str(), S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO); if (ret && errno != EEXIST) { - ALOGE("Failed to create directory: %s, ret: %s", s.c_str(), std::strerror(errno)); + const int err = errno; + ALOGE("Failed to create directory: %s, ret: %s", s.c_str(), std::strerror(err)); + return -err; } umask(prevUmask); } + return 0; } int main(int argc, char** argv) { @@ -244,8 +247,8 @@ int main(int argc, char** argv) { // (due to genfscon rules) have fs_bpf_tethering selinux context, which is restricted // to the network_stack process only (which is where out of process tethering runs) if (isInProcessTethering() && !exists("/sys/fs/bpf/tethering")) { - createSysFsBpfSubDir(/* /sys/fs/bpf/ */ "net_shared"); - createSysFsBpfSubDir(/* /sys/fs/bpf/ */ "net_shared/tethering"); + if (createSysFsBpfSubDir(/* /sys/fs/bpf/ */ "net_shared")) return 1; + if (createSysFsBpfSubDir(/* /sys/fs/bpf/ */ "net_shared/tethering")) return 1; /* /sys/fs/bpf/tethering -> net_shared/tethering */ if (symlink("net_shared/tethering", "/sys/fs/bpf/tethering")) { @@ -259,9 +262,16 @@ int main(int argc, char** argv) { // which could otherwise fail with ENOENT during object pinning or renaming, // due to ordering issues) for (const auto& location : locations) { - createSysFsBpfSubDir(location.prefix); + if (createSysFsBpfSubDir(location.prefix)) return 1; } + // Note: there's no actual src dir for fs_bpf_loader .o's, + // so it is not listed in 'locations[].prefix'. + // This is because this is primarily meant for triggering genfscon rules, + // and as such this will likely always be the case. + // Thus we need to manually create the /sys/fs/bpf/loader subdirectory. + if (createSysFsBpfSubDir("loader")) return 1; + // Load all ELF objects, create programs and maps, and pin them for (const auto& location : locations) { if (loadAllElfObjects(location) != 0) { |