Section 16.12

PREVAIL

Full name: Polynomial-Runtime EBPF Verifier using an Abstract Interpretation Layer, where EBPF, usually written eBPF, stands for extended Berkeley Packet Filter.

Definition

PREVAIL is a verifier for eBPF §2.1 (extended Berkeley Packet Filter) programs: a checker that analyzes a program’s bytecode §2.4, the instructions of eBPF’s small virtual machine §2.3, before the program runs. It accepts the program only if it can prove that no execution breaks fixed safety rules, chiefly that every memory access stays inside memory the program may use. It reasons by abstract interpretation §3.4, computing at each instruction a summary of every value the registers can hold. Published in 2019 [463], it is the verifier of Microsoft’s eBPF for Windows.

The idea

A host such as an operating system kernel runs small programs that users supply, for example to filter network packets. A wrong memory access in such a program would corrupt the host, so the host checks each program before loading it. The Linux kernel’s eBPF verifier §3.3 walks a program’s paths, which multiply with every branch, and for years it rejected loops. The PREVAIL authors instead merge what all paths reaching an instruction know into one summary, so the work grows polynomially with program size. They handle loops with a widening operator §3.23, a step that generalizes a summary until it stops changing.

The second idea is precision about relations. A packet filter tests if (data + 14 > data_end) return; before it reads 14 bytes, where data is the address of the packet’s first byte and data_end the address just past its last. Neither is known before the program runs. Interval analysis §3.9, which keeps a range of possible values for each register, cannot record the relation that the test establishes. The authors chose the Zone abstract domain §3.6, which records facts of the form x−y≤cx - y \le c between pairs of variables, and showed that it verifies real programs that intervals cannot.

The third point matters to everyone who uses PREVAIL: it proves facts about a model, made of its built-in meaning of each instruction and a description of the host, called the platform. An engineer who checks a design against the catalog strength of steel is right about the design, yet the building fails if the delivered steel is weaker. A helper function §2.19 that writes more memory than its declared signature allows, breaking its helper contract §2.21, is that weaker steel.

How it works

PREVAIL takes the program’s bytecode and a platform description from the integration, the host software that embeds PREVAIL. The description states three things. For each program type, it gives the size and layout of the context, a read-only memory region through which the host passes the program its inputs, such as where the packet’s start and end addresses are stored. For each helper function, a host function the program may call, it gives a signature: which arguments are pointers, how many bytes the helper may read or write through each, and what it returns. For each map, a memory region that persists between runs, it gives the key and value sizes.

The analysis runs in four steps:

  1. Build the CFG §3.13 (control-flow graph), the graph of which instruction can follow which.

  2. Attach to each instruction an abstract state: for each register and stack slot, its type (a number, or a pointer into the context, the stack, the packet or a map value) and its offset within that region, together with numeric facts in the Zone domain.

  3. Apply each instruction’s transfer rule, which computes the state after the instruction from the state before it. Where paths meet, keep only the facts true on every incoming path; at the start of a loop, apply widening so that the analysis ends.

  4. At every memory access, check that the region allows the access and that every possible offset plus the access width stays inside the region. At every helper call, check each argument against the signature. If any check cannot be proved, reject the program and name the instruction.

The 2019 paper names the properties its verifier establishes: memory safety, meaning accesses only within the program’s regions, and no reads of uninitialized registers or stack locations, which could reveal kernel data. Its prototype did not check termination: for programs with loops it proved safety, not that the program finishes.

Worked example

A map value is 16 bytes long, and a 4-byte store writes at offset oo from its start. If the analysis has proved 0≤o≤120 \le o \le 12, the highest store covers bytes 12, 13, 14 and 15, all inside, and the store is accepted. If it has proved only 0≤o≤130 \le o \le 13, a store at offset 13 would cover bytes 13 to 16, and byte 16 lies outside, so the program is rejected, even if offset 13 never occurs in practice.

For a packet, register r2 holds the start address and r3 the end address. On the path where the test r2 + 14 <= r3 succeeded, the Zone domain records r2−r3≤−14r_2 - r_3 \le -14. A 4-byte read at r2 + 10 ends with the byte at r2+13r_2 + 13 and needs r2+14≤r3r_2 + 14 \le r_3, which is proved. A 4-byte read at r2 + 12 ends with the byte at r2+15r_2 + 15 and needs r2+16≤r3r_2 + 16 \le r_3, which the recorded fact does not imply, so it is rejected.

A helper’s signature states that it writes exactly nn bytes through the pointer it receives, where nn is its second argument. The program passes a pointer to offset 12 of the 16-byte value and n=4n = 4. PREVAIL checks 12+4=16≤1612 + 4 = 16 \le 16 and accepts. If the helper’s code in fact writes 8 bytes, it writes bytes 12 to 19, and bytes 16 to 19 lie outside the value. The analysis was correct for its model; the helper broke the model. The repair belongs in the helper or its signature, not in the verifier.

Stated precisely

For one access, let the region be LL bytes long, let the analysis have proved omin≤o≤omaxo_{\min} \le o \le o_{\max} for the offset oo, and let the access be ww bytes wide. The access is safe for every possible offset if omin≥0o_{\min} \ge 0 and omax+w≤Lo_{\max} + w \le L, computed in exact integer arithmetic with no wraparound. In the first example, omax+w=12+4=16≤16=Lo_{\max} + w = 12 + 4 = 16 \le 16 = L.

Soundness §3.7 claim: if PREVAIL accepts a program PP under a platform description DD, then every execution of PP satisfies the checked properties, provided four assumptions hold.

  1. Same instruction semantics: the interpreter §2.13 or JIT §2.14 (just-in-time) compiler that runs PP gives every instruction the meaning that the PREVAIL version assumes.

  2. Honest helpers: every helper reads, writes and returns only what its signature in DD states.

  3. Faithful host: the context, packet, stack and map regions supplied at run time have the sizes and layout that DD states.

  4. Same bytes and a correct verifier: the bytes that run are the bytes that were verified, and the PREVAIL version used has no soundness bug that affects PP.

Limits and common mistakes

Rejected does not mean unsafe. PREVAIL is designed to be sound but is not complete: it rejects some safe programs whose safety its abstract domain cannot express, so the analysis lacks completeness. Rewriting the program, for example with an explicit bound test before an access, often lets it pass.

Different verifiers accept different programs. A program that the Linux verifier accepts may be rejected by PREVAIL, and the reverse; acceptance by one says nothing about the other.

PREVAIL does not examine helper code, map implementations, the interpreter or the JIT compiler. Their correctness is assumed, as the assumptions above state.

Safety is not termination or a time bound. A program that stays within its regions can still run for a long time, so a host needs a separate limit, such as an instruction budget §2.32.

The version matters. Instruction support, platform descriptions and bug fixes change between versions, and published security advisories have described PREVAIL versions that accepted unsafe programs. Record the version and the platform description with every verdict.

Questions answered

Which instruction and helper semantics does a particular integration model?

A PREVAIL integration models the instruction semantics built into the PREVAIL version it ships, and it models helper semantics only as far as the helper signatures in its own platform description state them. To find out exactly what a particular integration models:

  1. identify the PREVAIL version, which fixes the instructions it understands and the meaning it gives each one, such as operand widths and signedness;

  2. read the integration’s platform description: for each program type, the size and layout of the context region; for each helper function, the signature that lists which arguments are pointers, how many bytes the helper may read or write through each, and what it returns; and the sizes of map keys and values;

  3. compare that model with what actually runs: the interpreter or JIT compiler must give each instruction the same meaning, each helper’s code must stay within its signature, and the host must supply regions of the stated sizes.

Whatever the platform description leaves out, PREVAIL does not model. In particular, it does not model what a helper does inside its own code; it relies on the signature. A verdict therefore covers the program only under that version, that platform description and those assumptions.

Related entries: eBPF verifier (§3.3), Abstract interpretation (§3.4), Soundness (§3.7), Completeness (§3.8), Helper contract (§2.21), Overflow-safe range check (§4.17), Interval analysis (§3.9), Relational abstract domain (§15.12), Helper function (§2.19), Widening and narrowing (§3.23). Further reading: [61, 463].