BPF tracing programs may get CO-RE for function arguments
Alan Maguire's series lets programs name the parameters they need instead of reading them by fixed slot, so signature changes stop silently returning the wrong value.
BPF tracing and LSM programs that read a target's arguments by position can silently pick up the wrong value when a kernel adds, drops, or reorders those parameters. A patch series from Alan Maguire aims to give those programs the same Compile Once, Run Everywhere treatment libbpf already applies to kernel data structures.
The BPF_PROG family of macros maps named arguments onto a context that is really an array of 64-bit slots. The mapping is positional. A program has no way to ask whether a given argument exists on the kernel it is running on, so a signature change either fails verification or, worse, succeeds while reading the wrong slot.
Maguire's approach lets a program declare the parameters it actually uses in a flavor struct, in any order, and mark that declaration so libbpf (or the kernel, for light skeletons) relocates each access against the attach target's type information. A field missing on some kernels can be guarded with the existing existence check. Both the old and new names of a renamed parameter can sit in the same struct. A pointer whose type changes can be distinguished with a type match. A special member covers the return value for programs that can see it, including fexit and LSM hooks. An unguarded access to an argument that is not there is poisoned, so the program fails to load rather than reading garbage.
The series also changes how the verifier treats partial loads of a context slot on big-endian machines. Arguments smaller than 8 bytes live in the low-order bytes of their slot. The verifier has only allowed loads at the start of a slot, which on big-endian reads the high-order bytes instead. Loads that end at the end of a slot would now be accepted, so the same low-order bytes are readable, while loads at other offsets stay rejected. Little-endian behavior is unchanged. Iterators are left out because their context is a real struct, not a slot array.
Alexei Starovoitov, who suggested the work, wants the name kept as bpf_func_args so it matches the existing helper that reads the same slots, rather than a more generic context name that might imply support for every program type. Andrii Nakryiko has asked whether a broader name would age better, and whether relocations can be applied after subprograms are appended to their main program, a limitation the series currently leaves in place. Nakryiko also wants the new context structs to work with an attribute that preserves static offsets. Starovoitov asked whether recent LLVM already supports combining that with preserve_access_index, and whether a feature guard is needed.
Automated review also flagged a possible 32-bit host bug: the split type information used to build the candidate struct may report pointers as 4 bytes, which could shrink 8-byte context loads before the verifier sees them.