Section 20.1

Tree 1: “Does eBPF guarantee that a device cannot crash?”

Setting

A sensor gateway is a small device that collects readings from sensors and passes them on. The gateway in this invented example also accepts a small decision program, delivered through a phone that only carries the bytes. The program comes from a publisher, the one party authorized to change the gateway’s policy, meaning its rules for deciding requests. Each time someone asks the gateway to change a setting, which is called a management request, the gateway runs the program, and the program answers with a verdict, ALLOW or DENY.

The program is eBPF §2.1 bytecode §2.4: instructions for a processor that exists only as a definition, not as hardware. The name eBPF began as an abbreviation of extended Berkeley Packet Filter. RFC 9669, the IETF specification of the instruction set, says that the name is no longer an acronym for anything. Part of the gateway’s own software, called a virtual machine §2.3 (VM), carries out the instructions one at a time. The decision program is the guest. The gateway’s own software, which contains the VM, is the host. The guest can call helper functions §2.19, which are host routines that the host has chosen to offer to it.

Two things happen on one day. First, a faulty decision program tries to read 4 bytes starting at the last byte of an 8-byte buffer, a region of memory that holds its input. The VM refuses the read, stops the guest and reports an error to the host, which treats the error as DENY and keeps running. Second, the phone sends a request and gets no reply within 5 seconds, because the gateway’s radio was busy with other traffic. The question is whether either event was a crash, and whether eBPF guarantees that the gateway cannot crash.

Short answer

No: the specification of eBPF, RFC 9669, defines only an instruction set and leaves safety to the software that runs the instructions. By checking the program before the run, or each memory access during it, that software can guarantee something narrower: the downloaded program never reads or writes memory outside the regions it was given. That holds only if the checked program is the one that runs and the device’s own code, including its helper functions, behaves as documented. Hangs, missed deadlines, power loss and useless verdicts are not covered.

Follow-up questions

First answer

No: the specification of eBPF defines an instruction set, and an instruction set cannot guarantee that a device never crashes. Any guarantee that the software executing the instructions can give is narrower and has conditions. A good first answer makes three points.

  1. The instruction set promises no safety. In RFC 9669, the IETF specification of the eBPF instruction set, a load instruction reads memory at whatever address the program has computed. Nothing in the instruction limits that address. The security section of RFC 9669 says that programs could use the instructions “to do malicious things with memory, CPU, networking, or other system resources”, and that the environment that executes them should run only programs that are “trusted and verified”.

  2. A narrower guarantee is possible. The software that executes the program can test every memory access just before performing it, which is called a runtime bounds check §2.27. Take an 8-byte region, whose bytes are numbered 0 to 7, and a request to read 4 bytes starting at byte 7. Only 8−7=18 - 7 = 1 byte remains from byte 7 onwards, and 1<41 < 4, so the read is refused. The program stays inside its memory, provided that the test runs on every access, that the region really is 8 bytes long and still belongs to the program, and that the testing code is correct. A verifier, a checker that examines the whole program before it runs, is another route to the same guarantee. It depends in the same way on true facts about the regions and on correct checking code.

  3. Three questions stay open. Does the device’s own software handle a refusal safely? Are its helper functions correct? These are routines of the device’s own software that the program may call, and they run directly on the processor, outside the bounds checks. Does the device keep doing useful work? A program can stay inside its memory and still deny every request, or call a helper that never returns.

What does crash mean?

Crash has no single technical meaning. A claim that a device cannot crash says nothing until it names the event it rules out and says how an observer would recognize that event. At least six different events are called a crash. Below, the guest is a downloaded program, and the host is the device’s own software, which runs the guest inside a virtual machine (VM), the part of the host that carries out the guest’s instructions and can refuse one.

Apply the list to two events. A VM refuses a guest’s attempt to read 4 bytes starting at the last byte of an 8-byte buffer, and the host carries on: this is a contained guest fault, not a crash of the device. A phone gets no reply from the device for 5 seconds: this cannot be classified from the phone’s side, because a busy radio, a hang, a reset in progress and a phone out of range all look the same. Telling them apart needs evidence from the device, such as a count of restarts that it reports when contact returns.

State a conditional theorem

If the program that was checked is the program that runs, the device’s own software keeps its contracts, and the checking code is correct, then the downloaded program never touches memory outside the regions it was given. This is a conditional theorem: it promises its conclusion only when every premise holds. Name the three premises AA, CC and TT, in the order just given, and the conclusion QQ. In symbols, A∧C∧T⇒Q,A \land C \land T \Rightarrow Q, where ∧\land means “and” and ⇒\Rightarrow means “implies”. Call the device’s own software the host and the downloaded program the guest. The host runs the guest inside a virtual machine (VM), which carries out the guest’s instructions and tests its memory accesses.

Numbers alone do not make a premise true. In an 8-byte region, whose bytes are numbered 0 to 7, a 4-byte read starting at byte 4 passes the bounds test: 8−4=48 - 4 = 4 bytes remain from byte 4 onwards, and 4≤44 \le 4. If a helper freed the region just before the read, the numbers would still pass, but CC would be false, and the theorem would promise nothing about that run.

The theorem is also silent about everything outside QQ. QQ does not say that the device stays powered, that the guest’s answer is correct or that the answer arrives in time. The premises describe software only. They take for granted a processor that executes the code as written. During a brownout, a sag of the supply voltage below what the device needs, the processor is no longer guaranteed to do that, so the theorem promises nothing about such a run. Stating the theorem does not prove it. For a particular device, each premise must be established, and the step from the premises to QQ must be argued from the design of its VM.

Give a counterexample to the universal claim

A downloaded program that answers DENY to every request is a counterexample: it breaks no memory rule, and the device stops being useful. The universal claim is that a device which runs its downloaded programs as eBPF bytecode, meaning instructions for a defined, not physical, processor, keeps working whatever program it is given: it can neither crash nor stop serving. One run that keeps every memory rule and still ends the service disproves the claim. Three such runs follow, for a device whose own software, the host, runs a downloaded decision program, the guest.

None of the three runs reads or writes outside the guest’s memory, so none contradicts a correctly stated guarantee of memory confinement. They defeat only the wider claim. The first run is a loss of service without any crash. The second and third are hangs. Cutting the power supply also defeats the wider claim, and it needs no program at all. Confinement is a safety property §1.11: a statement that a named bad event never happens. That every run of the guest ends is a liveness property §1.12: a statement that a named good event eventually happens. Continued service is a matter of availability §1.10, meaning that the device keeps doing its job for its legitimate users. A proof of confinement establishes neither of the last two. Each needs its own argument.

What evidence would you require?

Require one piece of evidence for each thing the claim depends on, and an argument that covers every run, not only the runs that were tested. Suppose the claim is that a downloaded program, the guest, cannot read or write memory outside the regions given to it by the device’s own software, the host. Six things are needed.

  1. The checked bytes are the executed bytes. Evidence that nothing can change the program between the check and the run.

  2. The meaning of every instruction and helper. A written description of what the host does for each instruction and for each helper function, a host routine the guest may call, with evidence that the code matches the description.

  3. The state and lifetime of every region. For each memory region handed to the guest: its start, its length, whether its bytes have been set, and why it stays valid until the run ends.

  4. Complete mediation §1.16. Every route by which the guest can reach memory passes through a check: reads, writes, the guest’s own working memory, and addresses that the guest passes to helpers.

  5. A fault model §1.30. A written list of the failures the claim covers and those it excludes, such as power loss, a reset in the middle of a run, or corrupted storage.

  6. The refusal path. A trace of one refused access, from the error that the refusing code reports to the action the host finally takes. The host’s rule for turning each way a run can end into a decision is its fault-to-verdict mapping §2.34. The trace must show that the host does not perform the protected action and does not read a leftover value as the guest’s answer.

Tests alone are not enough. A test shows what happened in the runs that were tried. A claim about every program and every input needs an argument that reaches the untried runs: a proof, an analysis known to overlook no case, or exhaustive enumeration §10.33 when the cases are few enough to try them all. Anything on the list that has not been established is written beside the claim as an assumption.

Related entries: eBPF verifier (§3.3), Fault-to-verdict mapping (§2.34), Fault model (§1.30), Mechanism versus evidence (§1.37), Assumption versus guarantee (§1.36), Security claim scope (§1.45), Termination versus time bound (§2.33), Tree 10: “If memory is safe, can malicious code still deny service?” (§20.10). Further reading: [160].