From c9b0a8396ac528c27515476619a4c0602f303011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 22 Jul 2025 12:30:32 -0700 Subject: [PATCH] NetBpfLoad: rename 'writeProcSysFile()' to 'writeFile()' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function doesn't enforce anything specific to /proc/sys. The name should reflect that. (prep work for reusing this for other purposes - incl. selinux booleans) Test: TreeHugger Flag: EXEMPT mainline/no-op Signed-off-by: Maciej Żenczykowski Change-Id: Ia206c19043e63e274c7370739750e1a8236e4127 --- bpf/loader/NetBpfLoad.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 9bc0efb94c..0b78ca2e14 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -1494,7 +1494,7 @@ static int createDir(const char* const dir) { // Technically 'value' doesn't need to be newline terminated, but it's best // to include a newline to match 'echo "value" > /proc/sys/...foo' behaviour, // which is usually how kernel devs test the actual sysctl interfaces. -static int writeProcSysFile(const char *filename, const char *value) { +static int writeFile(const char *filename, const char *value) { unique_fd fd(open(filename, O_WRONLY | O_CLOEXEC)); if (fd < 0) { const int err = errno; @@ -1509,7 +1509,6 @@ static int writeProcSysFile(const char *filename, const char *value) { return -err; } if (v != len) { - // In practice, due to us only using this for /proc/sys/... files, this can't happen. ALOGE("write('%s', '%s', %d) -> short write [%d]", filename, value, len, v); return -EINVAL; } @@ -1859,7 +1858,7 @@ static int doLoad(char** argv, char * const envp[]) { // but we need 0 (enabled) // (this writeFile is known to fail on at least 4.19, but always defaults to 0 on // pre-5.13, on 5.13+ it depends on CONFIG_BPF_UNPRIV_DEFAULT_OFF) - if (writeProcSysFile("/proc/sys/kernel/unprivileged_bpf_disabled", "0\n") && + if (writeFile("/proc/sys/kernel/unprivileged_bpf_disabled", "0\n") && isAtLeastKernelVersion(5, 13, 0)) return 1; } @@ -1875,12 +1874,12 @@ static int doLoad(char** argv, char * const envp[]) { // kernel does not have CONFIG_BPF_JIT=y) // BPF_JIT is required by R VINTF (which means 4.14/4.19/5.4 kernels), // but 4.14/4.19 were released with P & Q, and only 5.4 is new in R+. - if (writeProcSysFile("/proc/sys/net/core/bpf_jit_enable", "1\n")) return 1; + if (writeFile("/proc/sys/net/core/bpf_jit_enable", "1\n")) return 1; // Enable JIT kallsyms export for privileged users only // (Note: this (open) will fail with ENOENT 'No such file or directory' if // kernel does not have CONFIG_HAVE_EBPF_JIT=y) - if (writeProcSysFile("/proc/sys/net/core/bpf_jit_kallsyms", "1\n")) return 1; + if (writeFile("/proc/sys/net/core/bpf_jit_kallsyms", "1\n")) return 1; } if (runningAsRoot) { // implies U QPR3+ and kernel 4.14+