eBPF-based security platform
bpm: search command directory for BTF headers
John Fastabenddc0bd916acb8
diff --git a/Documentation/upatch.rst b/Documentation/upatch.rstindex 1f87908e..7614f7d4 100644--- a/Documentation/upatch.rst+++ b/Documentation/upatch.rst@@ -353,6 +353,10 @@ rebuilt package gets a new version.``--vmlinux`` selects the BTF header used to compile BPF C entries. Itspath is resolved before the builder changes to the package directory.+Without it, ``bpm build`` checks ``./vmlinux.h`` and+``./vendor/linux/vmlinux.h`` from the command's working directory first,+then checks those paths from the package directory and the installed+shared header path.6) Publishing-------------diff --git a/tools/shirudo-build/README.md b/tools/shirudo-build/README.mdindex ef129b11..aa750bb9 100644--- a/tools/shirudo-build/README.md+++ b/tools/shirudo-build/README.md@@ -55,8 +55,9 @@ target boundary) and `AGENTS.md` (the no-subprocess invariant).`make install-operator` installs it alongside `shirudo` at this path.The operator package includes both binaries and depends on `clang` and`llvm` to compile `.bpf.c` inputs. Building from source also needs a-`vmlinux.h` for the target kernel; pass `--vmlinux` when it is not in-the default search paths.+`vmlinux.h` for the target kernel. BPM builds search from the command's+working directory before the package directory; pass `--vmlinux` to+select a different header explicitly.For checkout/developer use, build both binaries and put their directoriesfirst on `PATH`:diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.cindex aa8f7ee1..63173a46 100644--- a/tools/shirudo-build/bpm-build.c+++ b/tools/shirudo-build/bpm-build.c@@ -32,6 +32,7 @@#include "log.h"#include "hex.h"#include "malloc.h"+#include "macros.h"#include "timefmt.h"#include "package.h"#include "paths.h"@@ -757,6 +758,19 @@ static int build_stage_open(struct bpm_build_spec *spec)return 0;}+static const char *build_vmlinux_from_cwd(char *out, size_t cap)+{+ static const char *const paths[] = {+ "./vmlinux.h", "./vendor/linux/vmlinux.h",+ };+ size_t i;++ for (i = 0; i < ARRAY_SIZE(paths); i++)+ if (realpath(paths[i], out))+ return out;+ return NULL;+}+static void build_stage_close(struct bpm_build_spec *spec){char object[PATH_MAX + 8];@@ -1120,6 +1134,7 @@ static int shirudo_build_bpm_build(int argc, char **argv){const char *context = ".", *file_arg = NULL, *version = NULL;const char *keys_arg = NULL, *vmlinux_arg = NULL;+ const char *vmlinux_override = NULL;char build_file[PATH_MAX], resolved_file[PATH_MAX];char keys_dir[PATH_MAX], vmlinux_abs[PATH_MAX];char keys_abs[PATH_MAX], pkey[PATH_MAX], cert_path[PATH_MAX];@@ -1188,6 +1203,11 @@ static int shirudo_build_bpm_build(int argc, char **argv)vmlinux_arg, strerror(errno));return -errno;}+ if (vmlinux_arg)+ vmlinux_override = vmlinux_abs;+ else+ vmlinux_override = build_vmlinux_from_cwd(vmlinux_abs,+ sizeof(vmlinux_abs));if (!getcwd(out_dir, sizeof(out_dir)))return -errno;if (file_arg) {@@ -1241,8 +1261,7 @@ static int shirudo_build_bpm_build(int argc, char **argv)rc = build_stage_open(spec);if (rc)goto out_cert;- rc = build_upatches(spec, pkey, cert_path,- vmlinux_arg ? vmlinux_abs : NULL);+ rc = build_upatches(spec, pkey, cert_path, vmlinux_override);if (!rc)rc = build_archive(spec, version, cert_path, fingerprint, out_dir);build_stage_close(spec);