freenode
Kernel & Low-Level

BPF tail calls still read past raw tracepoint context

A fix that padded syscall test-run context left raw tracepoint paths open; the proposed follow-up is already under fire for being incomplete.

Linux BPF programs that tail-call into another program can still read past the context buffer on raw tracepoint paths, triggering kernel address sanitizer reports of out-of-bounds reads. Pragyansh Chaturvedi showed the hole on bpf-next and posted a partial fix that automated reviewers say does not close it.

The verifier records how far into its context a program may read, and the raw tracepoint test-run, raw tracepoint attach, and tracepoint attach paths each reject a program that would read past the buffer they actually provide. Those checks look only at the program being run or attached. A program that never touches its context passes, then tail-calls a target that reads far past the real buffer. An earlier change padded the syscall test-run path so a tail-call target always got the largest context the verifier allows. The raw tracepoint and tracepoint paths were left alone.

Chaturvedi reproduced the miss on a KASAN-enabled x86-64 build. On the test-run path, an 8-byte user context was copied and a tail-call target read 96 bytes, producing a slab out-of-bounds report. Attaching a similarly innocent caller to sched_switch and tail-calling a 96-byte reader produced a stack out-of-bounds report inside the scheduler.

The posted change pads the test-run copy with zeros out to the maximum context size whenever the program being run can reach a tail call, and adds a selftest that expects the extra bytes to read as zero. Kernel CI and an automated review objected on several grounds. The padding runs only if the program under test is itself marked tail-call reachable, so an extension attached later can still inject a tail call into a program that was loaded without one. The same class of extension was blocked for syscall programs in the earlier fix, and there is no equivalent check for raw tracepoints. Reviewers also called a full 64KB pad excessive for a 96-byte read, questioned the Fixes tag, and noted that a Clang-only unroll pragma in the new selftest will fail the bpf-gcc selftest build.

The attach-path cases in the original report are not covered by the patches as posted.