Rex kernel extensions
Working on Rex, a framework that runs safe Rust programs inside the Linux kernel in place of eBPF.
made for the course advanced operating systems
eBPF lets you run small programs inside the kernel, but every program has to pass the in-kernel verifier, which limits how complex they can be and gives cryptic errors. Rex takes another route: extensions are written in safe Rust, the Rust compiler does the safety checks, and they compile straight to native code. It supports kprobes, perf events, tracepoints, XDP and tc programs, eBPF helpers and maps.
My course project, in a team of four, extended it in two directions.
Dynamic memory. We implemented Rust’s GlobalAlloc on top of the kernel’s BPF object allocator (which meant a small kernel patch to export the functions), so extensions can use plain Vec, Box and BTreeMap. On top of that came Persistent<T>, heap data that survives between two runs of a program, behind a lock that writes it back when released. We benchmarked the result against Rex’s own fixed-size maps and arrays.
Static checks. Rex catches panics and stops programs that run too long at runtime. The goal was to prove those properties ahead of time instead, and drop the runtime checks. Verus turned out not to fit (it needs the standard library and a stable compiler, Rex needs neither and nightly), so we wrote a script that swaps Rex’s API for stubs Verus can check, then moved to Kani, which now runs as a build step: if the proof fails, the build stops.