Definition
A reference monitor is the part of a system that checks every access by a subject to an object against a security policy, and permits or refuses the access. A subject is an active party, such as a process; an object is a protected resource, such as a file or a memory region. A mechanism counts as a reference monitor only if it is always invoked, tamperproof, and small and simple enough to be verified. James P. Anderson’s 1972 report for the United States Air Force set out the concept [411].
The idea
A program runs untrusted code in a sandbox §2.30, a confined environment, and calls a guard function before every write that the untrusted code requests. The guard checks that the write stays inside the memory the code was given. Three things can still go wrong. The untrusted code may reach the write by a route that does not pass the guard, for example by jumping to the instruction just after the guard. It may overwrite the guard’s own data, such as the stored size of its memory region, so that the guard approves what it should refuse. Or the guard may be so large and tangled that nobody can tell whether its checks are right. In each case the guard exists, but nothing is reliably enforced.
A guard at the entrance of a secure building is a fair picture. The guard counts for something only if the entrance is the only way in, if visitors cannot replace the guard or the guard’s list of permitted visitors, and if the list is short enough to check. The picture stops at the walls. A building’s walls are physical. In software the walls are made by the processor’s protection features and by how the code is built, and a single jump instruction or memory write goes through any wall that was assumed but never built.
How it works
Systems meet the three requirements as follows.
Always invoked, also called non-bypassable. No subject can reach a protected object except through the monitor. This is a property of the system’s architecture, not of the monitor’s code. In an operating system, user programs run at a lower privilege level §6.10 of the processor, a memory management unit §6.9 (MMU) maps only their own memory, and system calls are the only way for a program to ask the kernel to act, so the kernel’s checks see every request. In an interpreter §2.13, a program that runs another program one instruction at a time, the guest’s instructions never run directly on the processor, so the interpreter can check each memory access before performing it. Software fault isolation §2.41 rewrites native machine code so that every memory access is confined to the sandbox, and verifies that no jump can land between a check and the access it guards.
Tamperproof. The subjects that the monitor constrains cannot change its code, its policy data or its decision state, such as cached decisions, counters and on-off settings. The usual means is memory that those subjects cannot write, enforced by hardware such as the MMU or, on a microcontroller §6.1, a memory protection unit §6.8 (MPU). Changes to the policy go through the monitor itself, which checks that the requester may make them.
Verifiable, also called evaluable. The monitor is small, simple and clearly specified, so that analysis and testing can show that its checks are right and that the first two requirements hold. Everything whose failure would break the protection belongs to the trusted computing base §1.4 (TCB), and a reference monitor aims to keep that base small.
Some textbooks summarize the requirements with the letters NEAT: non-bypassable, evaluable, always invoked and tamperproof.
A hook, a call to a check placed in code just before a protected operation, is the usual way to add the first requirement to existing software. Linux Security Modules §21.14 is a framework of such hooks inside the Linux kernel: the kernel calls a hook before operations such as opening a file, and a security module such as SELinux (Security-Enhanced Linux) makes the decision. A hook is part of a reference monitor only if every route to the operation passes a hook, the hooks and their data are protected, and the hook code can be analyzed. A function named monitor or validate meets none of these requirements by its name.
When guest code can ask the host to act for it, through a helper function §2.19 that the host provides, each such function performs accesses on the guest’s behalf. Each helper is then part of the monitor. It must apply the same checks, or it gives the guest a route around them.
Worked example
A guest program owns a memory region of 16 bytes, at offsets 0 to 15, and asks to write 4 bytes starting at offset 14. The monitor allows a write when . Here , which is greater than 16, so the write is refused; only bytes remain in the region. Now break each requirement in turn.
Bypass. A just-in-time compiler §2.14 (JIT), which translates the guest program into native processor instructions to run it faster, emits the store without the check. The store writes offsets 14 to 17, and offsets 16 and 17 lie outside the region. The policy is unchanged, but this route does not pass the monitor.
Tampering. The guest can write to the place where the monitor stores the region’s length, and changes 16 to 255. The check computes and allows the write, which lands 2 bytes outside the real region. The check ran, on data the guest chose.
An unverified check. The monitor computes in 32-bit unsigned arithmetic, which keeps only the remainder after division by . The guest asks for offset . The sum becomes , and allows a write far outside the region.
The correct check avoids the overflow by never adding: allow the write when and . For the last request, holds and fails, so the write is refused. For the first request, fails, and the write is refused as well. A check this small can be shown correct for every possible input, which is the point of the third requirement. Each of the three failures defeats the monitor on its own, and repairing one leaves the other two open.
Stated precisely
Let a policy decide, for each subject , operation and object , whether may perform on . A mechanism is a reference monitor for that policy when three conditions hold.
Always invoked. In every run of the system, every access by with to that takes effect is preceded by a decision of the monitor that allowed exactly , and , and nothing that changes , , or the policy happens between that decision and the access.
Tamperproof. No subject that the monitor governs can change the monitor’s code, policy data or decision state, except through operations that the monitor itself checks and the policy allows.
Verifiable. The monitor is small and structured enough that conditions 1 and 2, and the correctness of each decision, can be established completely by analysis and testing.
The claim rests on the layers below the monitor. The processor and its memory protection must behave as documented, and the monitor that runs must be the one that was analyzed, which secure boot §6.31 or a similar check of the loaded code establishes. If either assumption fails, the three conditions describe a different system from the one that runs.
Limits and common mistakes
A reference monitor enforces the policy it is given. It does not show that the policy expresses what its owners intend, that the keys behind authentication §1.6 are uncompromised, or that the subject’s identity was established correctly.
A reference monitor covers only the accesses that its policy names. Information that leaks through timing or power use, which is a side channel §1.29, the exhaustion of memory or processor time, and a subject that runs too long are outside an access-control §1.7 monitor unless the policy and the mechanism address them.
A hook in the same address space as untrusted native code is neither always invoked nor tamperproof by itself, because native code can jump past the hook and write the hook’s data. Isolation must come from hardware protection, from an interpreter or from software fault isolation.
Every helper function, native extension and fast path that performs accesses for the guest is part of the monitor. One helper that writes memory without the check extends the guest’s reach past the monitor.
A remembered decision is part of the monitor’s state. A cached allow that outlives the object, the subject’s authority or the policy is a bypass in time, which complete mediation §1.16 rules out.
A reference monitor says nothing about availability §1.10 or timing. It can refuse correctly and still let a subject keep the system busy, and a permitted operation can still miss its deadline.
Questions answered
What makes an enforcement hook bypassable or tamperable?
An enforcement hook, a check placed in code just before a protected operation, is bypassable when some route reaches the protected operation without passing through the hook, and tamperable when the party it constrains can change the hook’s code, its policy data, its decision state or the inputs it checked. Typical bypass routes are:
another function or interface that performs the same operation without the hook;
native code that jumps directly to the instruction after the check;
code generated by a just-in-time compiler that omits the check;
a helper function that performs the access on the caller’s behalf without checking;
error paths, interrupt handlers §6.12, hardware that writes memory directly, and queued work that runs later;
a cached decision that outlives the facts it was based on.
Typical tampering routes are: the constrained code shares writable memory with the hook, so it can overwrite the policy table, a stored length, a cached allow or an on-off setting; it can change the checked data between the check and its use; or it can load a new policy through a path that does not check its authority. Both kinds of weakness come from missing isolation and missing coverage, not from the logic of the check. Architecture rules them out: a lower processor privilege level and memory protection keep the hook’s code and data out of the constrained code’s reach; an interpreter or software fault isolation prevents jumps past checks; and an argument shows that every route to the operation passes the hook. With those measures in place, a hook small enough to verify meets all three requirements of a reference monitor: always invoked, tamperproof and verifiable.
Related entries: Trusted computing base (TCB) (§1.4), Complete mediation (§1.16), Software fault isolation (SFI) (§2.41), Sandbox (§2.30), Memory protection unit (MPU) (§6.8), Privilege level (§6.10). Further reading: [217, 411].