Question
Does a correct DENY return value prove that an attack was prevented?
Short answer
No, a correct DENY return value proves only that the policy check decided correctly about the request it was shown. Stopping the forbidden effect needs four further facts: the check runs before the effect; the code that would cause the effect obeys the verdict and treats a missing verdict as a refusal; every route to the effect passes through the check; and the facts the check judged still hold when the effect happens. A late verdict, or a route that skips the check, leaves the attack successful.
Terms in the question
Policy check: a function that receives a description of a requested action, such as “set the power limit to 50”, and returns a verdict, meaning a decision whether the action is permitted. The rules it applies form the security policy.
DENYreturn value: the verdict that says the action is not permitted;ALLOWsays that it is. The capital letters follow the custom of writing constants in program code in capitals; DENY is the English word, not an abbreviation.Correct: the verdict is the one that the policy prescribes for this request. Correctness is a property of the decision.
Attack prevented: the forbidden effect did not happen and cannot happen later as a result of this attempt. An effect is a change to protected state, a disclosure of a secret, or a physical action such as switching on a motor. Prevention is a property of the system’s state, not of a returned value.
Complete mediation §1.16: the security design principle that every access to every protected object must be checked for authority each time the access happens, with no route that skips the check. Saltzer and Schroeder stated it in 1975 [233]. The component that makes these checks is called a reference monitor §1.17.
Full answer
Step 1: a verdict is not an effect. A policy check maps a request, together with the state it consults, to a verdict. A test that calls the check and compares the returned value with the expected one tests that mapping and nothing else. Prevention is a claim about a different thing: the protected state after the attempt. The verdict reaches the protected state only through the code that would perform the action, the code that writes the setting, sends the packet or switches on the motor. That code must call the check, wait for the verdict, and act only on ALLOW. A component whose verdict is obeyed in this way enforces; a component whose verdict is only recorded observes. The difference between observation and enforcement §1.20 is control over the effect, and a correct verdict can come from either kind of component.
Step 2: the check must come before the effect. A hook point §14.26, the place in the code where the system calls the check, can sit before or after the operation it guards. A check placed after a write, or a monitor that reads a record of operations that have already completed, can only report the write. Undoing the write afterwards is recovery, not prevention: other code may have used the forbidden value in the meantime, and many effects cannot be undone at all, such as a radio packet already sent, a secret already disclosed or a valve already opened.
Step 3: the verdict must be obeyed, and a missing verdict counts as a refusal. A check whose return value the caller ignores prevents nothing. A subtler mistake is to test for the refusal: code that refuses only when the verdict equals DENY lets every other value through, including an error code. The safe form acts only when the verdict equals ALLOW. The same rule covers a check that cannot answer, because the policy is not yet loaded, the check has run out of time, or the check itself has failed. Treating the missing answer as a refusal is called fail closed §1.13. Letting the action proceed is called fail open §1.14, and under fail open an attacker who can cause the error bypasses the check.
Step 4: every route to the effect must pass through the check. Complete mediation requires the check on every route to the protected object, not only on the route that was tested. Routes that commonly skip a check are: a second function that writes the same variable; an interrupt handler §6.12, the code that the processor runs when a hardware event occurs; a callback §14.22, a function that the program hands to a library so that the library calls it directly later; a peripheral that writes memory by direct memory access §4.36 (DMA), without the processor; a debug interface; and start-up code that runs before the policy is loaded. A test that receives DENY on one route says nothing about the others. To show coverage, list every place in the system that can cause the effect, and show for each one that it calls the check or that the attacker cannot reach it. Hardware can shorten the list. A memory protection unit §6.8 (MPU), hardware that enforces access rights on regions of memory, can refuse writes to the protected region from all code that runs in the processor’s unprivileged mode, so that such code has to go through the reference monitor, which runs in privileged mode. The MPU checks only accesses made by the processor, so DMA needs its own control. When hooks only measure, the same question, which routes pass a hook, is called instrumentation coverage §14.35.
Step 5: the facts the check judged must still hold at the effect. A verdict is computed from facts: who asked, which value was requested, what the current settings are. If those facts can change between the check and the effect, the effect can act on facts that the check never saw. A caller can rewrite the request in shared memory after the check has read it, or the requester’s permission can be withdrawn between the check and the action. This is a time-of-check to time-of-use §9.26 (TOCTOU) error. The repair is to copy the request once into memory that the caller cannot change, to check and use that one copy, and to make check and action atomic, so that nothing can change the facts between them, for example by holding one lock across both. A lock lets only one part of the program at a time run the code it protects. The alternative is to check again at the moment of use.
Step 6: what does show prevention. Evidence of prevention is evidence about the protected state. In a test, read the protected state after each attempt, confirm that it is unchanged, and repeat the attempt on every route found in Step 4. In an argument, show the four conditions of Steps 2 to 5: the check precedes the effect; the code obeys the verdict and treats a missing verdict as a refusal; every route is checked; and the facts cannot change between check and effect. A log entry that says DENY shows only that a decision was made and recorded.
Worked example
The values are invented for illustration. A device keeps a setting power_limit, currently 8. The policy allows values from 0 to 10. An attacker requests 50, so the correct verdict is DENY, because .
Check after the write. The function
set_power(v)first writesvintopower_limit, then callscheck(v), then records the verdict in a log and returns an error code if the verdict isDENY. With : the write setspower_limitto 50; the check returnsDENY; the log saysDENY; the caller receives an error. The final value is 50. The verdict was correct, and the attack succeeded.Check first. Reorder the function: compute the verdict, return an error unless the verdict is
ALLOW, and only then write. With the check returnsDENY, the write never runs, andpower_limitstays 8.A second route. The device also accepts settings over a serial port, and the interrupt handler for that port writes
power_limitdirectly. The attacker sends 50 over the port. No check runs, and the value becomes 50. A test suite that sent 50, 11 and 1000 toset_powerreports 3 correct refusals out of 3, yet only 1 of the 2 routes that writepower_limitis checked.A missing verdict. During start-up the policy table is not yet loaded, and
checkreturnsERROR. A caller written as “refuse if the verdict equalsDENY” treatsERRORas permission, so a request of 50 sent during start-up succeeds. Written as “refuse unless the verdict equalsALLOW”, the same caller refuses it.
Follow-up questions and limits
Can the system undo the write after a late DENY? Only when the effect can be reversed and nothing has used the forbidden value in between. Restoring power_limit from 50 to 8 still leaves an interval in which a control loop may have driven the motor at 50. A late verdict followed by an undo is detection and recovery, not prevention.
If every verdict in the tests is correct, is the policy check correct? Only for the requests tested. The values on each side of a limit, here 10 and 11, are the ones to test, a method called boundary-value testing §10.31. A correct check is necessary for prevention but, as Steps 2 to 5 show, not sufficient.
Does a refusal stop the attacker? It stops this request. The attacker can retry, use another route, or reach the same effect through several requests that are each allowed. Suppose the device also accepts “raise the limit by 2” and the check judges only the size of the step. Three such requests take the limit from 8 to , above 10. A rule about the state must be checked against the state that would result: is allowed, and is refused.
What else must the checking component satisfy? James P. Anderson’s 1972 report [411] requires a reference monitor to be always invoked, which is the route coverage of Step 4; tamperproof, so that the attacker cannot change the policy, the check or the place where the check is called; and small and simple enough to be verified.
This answer does not cover whether the policy itself is the right policy, or the cost of a flood of requests that are all refused, which is a denial-of-service §1.28 concern.
Fullest treatment: Complete mediation (§1.16).
Related entries: Observation versus enforcement (§1.20), Instrumentation coverage (§14.35), Reference monitor (§1.17). Further reading: [233, 411].