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.
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”.
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 byte remains from byte 7 onwards, and , 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.
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.
Contained guest fault. The VM refuses an illegal operation, stops the guest and returns an error to the host, which keeps running. This is the protection working.
Host memory fault. The host’s own code reads or writes memory it must not touch. Either the processor detects the illegal access and raises an exception, its signal that an instruction attempted something forbidden, after which the device usually halts or restarts, or nothing detects the access, and the host uses wrong data or overwrites data that belongs to something else.
Hang. The software stops making progress, for example in a deadlock §9.14, where two or more activities each wait for something that another one holds.
Watchdog §6.16 reset. A watchdog timer is a hardware counter that restarts the device unless the software resets the counter regularly, so a hang that keeps the software from resetting the counter ends in a restart.
Missed deadline. The device answers too late for the answer to be useful.
Power loss. The supply fails, or its voltage sags below what the device needs, which is called a brownout §6.17.
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 , and , in the order just given, and the conclusion . In symbols, where means “and” and 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.
, the conclusion, is confinement: every byte the guest reads or writes lies inside a memory region that the host granted for that run and has not taken back.
, admission: the bytes that execute are exactly the bytes that passed the checks the host makes before it lets a program run. This premise matters whenever the VM relies on such a check without repeating it, for example a check that every jump lands on an instruction of the program.
, contracts: the host starts every run as its documentation says, at the guest’s first instruction and with the stated starting values. Each region the host hands over has the stated start and length and stays valid for the whole run. Each helper function, a host routine that the guest may call, touches only the memory its documentation allows and does not free, that is, give back for reuse, a region the guest can still reach.
, trusted implementation: the code that makes the checks, before the run and during it, is correct, and no memory access of the guest escapes it. This code belongs to the trusted computing base §1.4, the part of a system whose correctness the conclusion depends on.
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: bytes remain from byte 4 onwards, and . If a helper freed the region just before the read, the numbers would still pass, but would be false, and the theorem would promise nothing about that run.
The theorem is also silent about everything outside . 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 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.
Deny everything. The guest returns
DENY, one of its permitted answers, for every request to change a setting of the device. It uses a fixed amount of memory, stays inside its regions and always finishes. The owner can no longer manage the device.A helper that never returns. The guest calls a permitted helper function, a host routine offered to guests, that waits for a radio reply which never comes. No invalid address is touched, but the guest never finishes, and a host that waits for the guest hangs.
An endless loop. An eBPF jump adds a signed number to the program counter §2.9, the position of the next instruction, so a program can jump backwards and repeat without end. RFC 9669, the IETF specification of the instruction set, leaves it to a verifier, a checker that examines a program before it runs, to ensure that programs “will terminate within a reasonable time”. If the host has no such checker and sets no instruction budget §2.32, meaning a limit on the number of instructions a guest may execute in one run, a guest with such a loop never returns.
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.
The checked bytes are the executed bytes. Evidence that nothing can change the program between the check and the run.
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.
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.
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.
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.
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].