BPFix: making eBPF verifier errors more friendly
BPFix makes eBPF verifier errors feel closer to Rust compiler errors.
The Linux eBPF verifier is powerful, but its failure logs are hard to read.
BPFix is a userspace diagnostic tool for that problem. It reads verifier logs
from your existing workflow and turns them into source-level explanations that
point to where the verifier lost the required proof.
Quick Start
Install bpfix and load the prebuilt verifier failure:
cargo install bpfix
sudo bpftool -d prog load examples/bpftool/quick-start.bpf.o /sys/fs/bpf/bpfix-demo 2>&1 | tee verifier.log
The command loads a real verifier failure from bpfix-empirical
(stackoverflow-53136145). The source parses either IPv4 or IPv6, derives a
UDP header pointer on each branch, checks the UDP header against data_end, and
then reads the destination port:
if (ethertype == ETH_P_IP) {
ipv4_hdr = (void *)eth + ETH_HLEN;
if ((void *)(ipv4_hdr + 1) > data_end)
return 1;
} else if (ethertype == ETH_P_IPV6) {
ipv6_hdr = (void *)eth + ETH_HLEN;
if ((void *)(ipv6_hdr + 1) > data_end)
return 1;
} else {
return 2;
}
if (ipv4_hdr)
udph = (void *)ipv4_hdr + sizeof(*ipv4_hdr);
else
udph = (void *)ipv6_hdr + sizeof(*ipv6_hdr);
if (udph + sizeof(struct udphdr) > data_end)
return 1;
dst_port = __constant_ntohs(((struct udphdr *)udph)->dest);
That source shape is normal BPF C: the developer made the packet proof explicit.
The failure is in the verifier-visible proof lifecycle. One replay path reaches
the shared udph->dest load with r5 as a scalar instead of a packet pointer:
from 31 to 34: ... R5_w=40 ...
; if (udph + sizeof(struct udphdr) > data_end) @ prog.c:267
34: (bf) r3 = r5 ; R3_w=40 R5_w=40
35: (07) r3 += 8 ; R3=48
36: (2d) if r3 > r2 goto pc+4 ; R2=pkt_end() R3=48
; dst_port = __constant_ntohs(((struct udphdr *)udph)->dest); @ prog.c:270
37: (69) r2 = *(u16 *)(r5 +2)
R5 invalid mem access 'scalar'
bpfix verifier.log
The raw log says where the verifier stopped, but not the source-level proof
story. BPFix turns the trace into a Rust-style multi-span diagnostic:
error[BPFIX-E006]: verifier-visible compiler lowering hides the required proof
= class: lowering_artifact
= confidence: medium
= diagnostic: supported, help: repair_hint, span: exact_pc
= next action: provenance
--> prog.c:270
|
263 | if (ipv4_hdr)
| ------------- nearby source context for pointer provenance
267 | if (udph + sizeof(struct udphdr) > data_end)
| -------------------------------------------- verifier state changes from pkt to scalar before the rejected access
270 | dst_port = __constant_ntohs(((struct udphdr *)udph)->dest);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rejected here: verifier sees a scalar where a pointer is required
|
= verifier[229]: R5 invalid mem access 'scalar'
= note: nearest BPF instruction pc 37
= note: parsed 60 verifier state snapshots
= note[lowering]: compiler-lowered control flow hides an established packet-pointer proof
= required proof: preserve a verifier-recognized pointer type at the operation that requires a pointer
help: Reacquire a verifier-tracked pointer before the rejected dereference.
help: Use the packet pointer that received the data_end proof, or rederive and recheck it before the load.
help: Keep the final access on a verifier-tracked pointer; rederive it from a checked base after scalar work.
This is the kind of failure that motivates the project: the program is not
missing a generic "add a bounds check" hint. The useful answer is the proof
lifecycle: where a verifier-recognized pointer proof exists, where branch-local
provenance can be merged away, and where the rejected instruction finally needs
that proof.

The example object is copied from
bpfix-empirical/cases/stackoverflow-53136145/prog.o; replace it with the
object you are debugging in your own project.
Stable CLI Contract
The 0.1.x CLI contract is intentionally small:
bpfix [OPTIONS] [LOG]
LOG can be a verifier, build, bpftool, libbpf, Aya, or BCC log. When LOG
is omitted or -, BPFix reads stdin. Positional input and stdin are always log
text. Supported public options are --object <OBJECT>, --doctor,
--fail-on-unsupported, --help, and --version. The output is plain text;
there is no stable JSON output mode in 0.1.x.
BPFix does not execute loader commands in the default path, and there is no
default command-execution workflow. Empirical corpus YAML and Docker-based
execution are explicit non-default modes; if Docker support is added, it should
be selected with an option such as --docker, not inferred from LOG.
Best Workflow