Section 14.26

Probe and hook

Definition

A hook is a point in a program where the program calls extra code registered or attached there. A probe is extra code that runs at a chosen point of a running program to record what happens or to act on it; many tools also use the word for the point together with its code. The difference that matters: a hook is offered by the program and fixes where attached code runs and which data it receives, which bounds what a probe attached there can see or stop.

Where it fits

Main entry: Runtime instrumentation (§14.24).

The Runtime instrumentation entry explains how probes are inserted, what state they must preserve, and how their records get lost. Two facts are specific to hooks. First, the position of a hook decides its power. A hook called before an operation, whose result the program checks before going on, can stop the operation; the Linux Security Modules §21.14 framework lets a security module refuse an operation in this way. A hook called after the operation can only record it. Second, a hook sees only the operations whose route passes it.

A program performs 100 transmissions. 80 go through the function that calls the transmission hook; 20 are made by a driver that calls the radio’s lower-level send function directly. A probe at the hook that records every call perfectly still records 80/100=0.880 / 100 = 0.8, or 80%, of the transmissions. More reliable records cannot change that; only a hook on a route that all 100 transmissions share can. Complete mediation §1.16, the requirement that every access pass the check, is a claim about routes, not about how often a hook runs in a test.

Where hooks are compiled into a program, the program file fixes the set of hooks. Femto-Containers §21.4, a system by Zandberg and coauthors (2022), runs small programs on microcontrollers §6.1 that use RIOT, an open-source operating system for small networked devices. Each small program runs inside a virtual machine §2.3, an interpreter §2.13 that keeps the program isolated from the firmware, the software built into the device. Femto-Containers calls its compiled-in hooks launch pads. A small program attached to a launch pad runs each time execution reaches it, and where the launch pad provides for it, the program’s result can change what the firmware does next. Attaching, replacing or removing a small program changes no firmware. Adding, moving or removing a launch pad changes the firmware’s own code and needs a firmware update, as does a change to any other set of hooks compiled into firmware.

Questions answered

Which relevant paths bypass this hook entirely?

Every route that reaches the operation without passing through the code that calls the hook bypasses the hook. Typical bypasses are another function that performs the same operation; a direct call to the lower-level function below the hook; a copy of the operation that the compiler inlined, that is, placed directly inside a caller; work started by an interrupt service routine §6.12 or done by a device through direct memory access §4.36 (DMA), without the processor; and effects completed before the hook runs, such as a message already sent when a hook placed after sending is called. To find them, start at the operation and follow every route that reaches it backwards, marking which routes pass the hook. A hook that runs in every test proves only that the tested routes pass it.

Related entries: Runtime instrumentation (§14.24), Complete mediation (§1.16), Observation versus enforcement (§1.20), Function wrapper (§14.27), Reference monitor (§1.17). Further reading: [206].