ebpftracer: report missing BPF tracing program types clearly - #367
Conversation
0129a76 to
3f9d9d5
Compare
|
Self-review before marking ready. The agent now probes the tracing program types it needs before loading and fails with a message naming the likely kernel option instead of a bare EINVAL; only a conclusive not-supported result short-circuits, so lockdown and permission errors still take the existing path. Unit test pins the exact message; vet, tests and build pass in a golang:1.24 container with libsystemd-dev. |
|
Round 1 self-review. Checked |
|
@KR-Ravindra, in general, I like the idea of logging something more meaningful than the current fatal error. But can we keep the code changes to a minimum and just inline something like this directly into the .ebpf method? for _, pt := range []ebpf.ProgramType{ebpf.TracePoint, ebpf.Kprobe} {
if err := features.HaveProgramType(pt); errors.Is(err, ebpf.ErrNotSupported) {
return fmt.Errorf("kernel does not support BPF %s programs (CONFIG_BPF_EVENTS is not set?): %w", pt, ebpf.ErrNotSupported)
}
}I also don't think we need additional code comments or tests for this. |
On kernels built without CONFIG_BPF_EVENTS (e.g. NVIDIA JetPack 5 / L4T 5.10 with CONFIG_KPROBES=n), BPF_PROG_TYPE_TRACEPOINT and BPF_PROG_TYPE_KPROBE are compiled out and bpf(BPF_PROG_LOAD) fails with a bare EINVAL. The agent then exits with failed to load collection: program sched_process_exit: load program: invalid argument where the program name is whichever program happened to load first, and nothing points at the kernel configuration. Probe TracePoint and Kprobe support with cilium/ebpf/features before loading the collection and fail with an error naming the missing kernel option. Only a conclusive ebpf.ErrNotSupported is reported; any other probe result falls through to the real collection load so existing error paths are unchanged. Document the CONFIG_BPF_EVENTS requirement in the README.
3f9d9d5 to
f76895d
Compare
|
@def done in f76895d: the check is now the six-line loop inlined in Drafted with AI assistance and checked against the code before posting. |
Problem
On kernels built without
CONFIG_BPF_EVENTS(for example NVIDIA JetPack 5 / L4T5.10.120-tegra, whereCONFIG_KPROBES=nandCONFIG_UPROBE_EVENTS=n), the agent passes every pre-flight check (tracefs present, kernel version >= 5.1, collection spec loads) and then exits with:Nothing in the message points at the kernel configuration, the program name varies between runs (it is whichever program cilium/ebpf loaded first), and the
*ebpf.VerifierErrorbranch prints nothing because this is not a verifier error.Root cause
ebpf.NewCollectionWithOptionsinebpftracer/tracer.goreceives a bareEINVALfrombpf(BPF_PROG_LOAD). WithCONFIG_BPF_EVENTSoff,BPF_PROG_TYPE_TRACEPOINTandBPF_PROG_TYPE_KPROBEare compiled out of the kernel andfind_prog_type()returns-EINVAL. Every program in the agent's collection is atracepoint/,kprobe/oruprobe/program (uprobes areBPF_PROG_TYPE_KPROBE), so nothing can load, but the agent has no check that names this condition.Fix
ebpftracer/tracer.go: in(*Tracer).ebpf, right before loading the collection, probeebpf.TracePointandebpf.Kprobewithfeatures.HaveProgramTypefrom the already-requiredgithub.com/cilium/ebpfmodule. On a conclusiveebpf.ErrNotSupportedthe agent fails with:Any other probe result (for example
EPERMunder kernel lockdown) is ignored so the real collection load surfaces the same error it does today. Six added lines, inlined as suggested in review; no helper, no extra comments, no tests.README.md: one line stating that the kernel must be built withCONFIG_BPF_EVENTS=y.No new dependencies;
go.mod/go.sumare unchanged.How tested
Cross-compiled for
linux/amd64:gofmt -l .clean,go vet ./ebpftracer,go build ./ebpftracerandgo test -c ./ebpftracerall OK. I have not been able to run the changed binary on the affected Tegra kernel from this environment, so the end-to-end message on real hardware is worth a check by anyone who has one.Links
failed to load collection: program <name>: load program: invalid argument#366invalid argument(different root cause): coroot-node not working with secureboot #205features.HaveProgramType: https://pkg.go.dev/github.com/cilium/ebpf/features#HaveProgramTypeThis change was prepared with an AI agent operated by KR-Ravindra, who reviewed and tested it.