Section 1.21

Detection versus prevention

Definition

Detection and prevention are two different security outcomes. Detection means recognizing that a forbidden or suspicious event is happening or has happened, and reporting it. Prevention means that the forbidden effect does not happen at all. A detection claim is about knowledge: the system knows about the event. A prevention claim is about the state of the world: the protected data, device or secret is unchanged. The difference that matters is that after detection the damage may already be done, and after prevention it is not.

The idea

A log line reads “unsafe write blocked”. The text alone cannot say which of two things happened. Either the write was stopped before it changed anything, or the write happened and a monitor noticed the changed value afterwards and reported it. Both designs can print the same words. The difference matters to anyone who relies on the protected value: a stopped write leaves it intact, while a detected write leaves a damaged value together with an accurate report of the damage.

Security practice classifies controls, the measures that protect a system, by what they achieve. A preventive control stops an event: a lock, an access-control §1.7 check, a firewall rule that drops a packet. A detective control notices an event: an alarm, an audit log, a monitor that compares behavior with a rule. A corrective control restores the system after an event: restoring a backup, reinstalling an earlier software version. In a shop, the locked door prevents, the camera detects and the insurance claim corrects. The picture stops where software differs: one component can both detect and prevent, if it sits on the path of the action and the action waits for its verdict.

How it works

Intrusion detection and prevention systems are the standard illustration. An intrusion detection system (IDS) watches network traffic or the activity on a computer, compares what it sees with signatures, which are patterns of known attacks, or with a model of normal behavior, and raises an alert when it finds a match or a deviation. A network IDS usually receives a copy of the traffic, from a switch port that mirrors the traffic or from a network tap, a device that copies the signals on a cable. The original packets travel on unaffected, so such an IDS can only detect. An intrusion prevention system (IPS) sits inline: every packet passes through it, and it can drop a packet it judges malicious before the packet reaches its destination. NIST Special Publication 800-94 covers both under the name intrusion detection and prevention systems (IDPS) [412].

Some IDS products respond to an alert, for example by resetting the connection or adding a firewall rule. Such a response blocks later packets of the attack. The packet that caused the alert has already reached its destination, so the response prevents what follows, not what was detected.

The same split applies to software hooks, the places where a program calls extra code at a chosen event. A monitor that receives a record of an event and can only report it is a detective control. A hook whose deny result the program must obey before it performs the action is a preventive control, provided that every path to the action passes through the hook. The entry on observation versus enforcement §1.20 gives the full conditions under which a hook controls an action.

A claim that a deny decision prevented an effect is a causal claim: the effect would have happened, and the deny is the reason it did not. The evidence follows the parts of that claim.

  1. Name the effect and where it shows. State the protected state or output, for example the byte at a given address in flash memory §6.6 or a frame sent by the radio, and how an observer outside the deciding component will read it.

  2. Show that the request reaches the effect. Run the same request with the rule set to allow, or with the check switched off. The effect must occur. This run is a positive control §10.30. Without it, an unchanged byte may only mean that the request never reached the code that writes the byte.

  3. Run the denied request and observe the effect directly. Read the protected state from outside the deciding component, for example with a debugger, a logic analyzer or a radio receiver, not from that component’s own log. Watch for the whole interval in which the effect could occur, including writes queued for later.

  4. Exclude passing effects. A final value equal to the starting value does not exclude a write followed by a restore. A count of writes, a hardware watchpoint §14.29 (a debugger feature that halts the processor when a chosen address is written) or a trace of the memory bus records every write, not just the final value.

  5. Connect the deny to the gate in the code. Show that the code that performs the effect runs only after an allow decision for this exact request, that the deny branch returns before the effect, and that no other path reaches the effect. A test covers the paths it ran; this inspection, or a proof, covers the others.

Worked example

A device keeps a protected byte with the value 9. A test sends a request that would change it to 0. A debugger, connected to the device separately from the software under test, records every write to the byte’s address. Four runs are made.

  1. Positive control, rule set to allow. The debugger records 1 write, and the byte ends at 0. The request does reach the code that writes the byte.

  2. Prevention design, rule set to deny. The decision is deny, and the write function returns an error. The debugger records 0 writes, and the byte stays 9.

  3. Detection design, rule set to deny. The byte becomes 0 at time 0. A monitor notices the change at 4 ms, logs “denied” and writes 9 back at 5 ms. The debugger records 2 writes, first 0 and then 9, and the byte ends at 9. The byte held the forbidden value for 5−0=55 - 0 = 5 ms. A test that compared only the final value with 9 would have scored this run as prevention.

  4. Malformed request, rule set to deny. The request has a damaged header, and the parser rejects it before any decision is made. The debugger records 0 writes and the byte stays 9, but the deny decision played no part.

Runs 2 and 4 look the same at the byte. Run 1, made with the same well-formed request as run 2, shows that run 2’s unchanged byte is due to the deny and not to the request missing the write. Only the write count separates run 3 from run 2.

Repetition bounds a rate for the tested conditions. Suppose run 2 is repeated 200 times with 0 writes recorded, and run 1 is repeated 200 times with 200 writes. If the 200 denied attempts are independent, the rule of three §18.5.8 gives 3/200=0.0153 / 200 = 0.015 as the approximate upper end of a one-sided 95% confidence interval §11.18 for the rate at which a denied attempt still writes. The data allow a rate of up to about 1.5%; they do not prove a rate of 0. Repetition helps only when something varies between attempts, such as timing. A code path that does not depend on timing either writes every time or never does.

Stated precisely

Let E(r)E(r) be the protected effect that request rr would cause, and let XX be the set of executions that a claim covers: the inputs, paths, timings and faults that the threat model §1.2 allows. A prevention claim states: in every execution in XX in which the decision for rr is deny, E(r)E(r) does not occur at any instant, not even temporarily. A detection claim states: in every execution in XX in which E(r)E(r) occurs or is attempted, an alert is raised within a stated delay Δ\Delta. In practice a detector is also judged by two rates measured on labeled cases: the fraction of real events that raise an alert, and the fraction of harmless events that raise one.

A prevention claim is a safety property §1.11, a property saying that something bad never happens, so one execution in XX in which the decision is deny and the effect still occurs refutes it. Evidence for it has three parts, each for the same request under the same conditions: the effect occurs when the request is allowed (reachability §3.21); the effect is absent, including passing occurrences, when the request is denied, as seen by an observer independent of the deciding component (outcome); and the gate obeys the deny on every path in XX (mechanism). Tests supply the first two for the cases they run. Only the mechanism argument extends the claim to every path in XX.

Limits and common mistakes

A deny return value is not evidence of prevention. The caller may ignore it, the effect may already have happened, or the effect may be carried out later by a queued operation that the deny did not cancel.

No observed damage is not proof of prevention. The attempt may never have reached the vulnerable code; the positive control rules this out.

The deciding component’s own log is not independent evidence. A bug that defeats the gate can also write a wrong log line.

One test establishes prevention for one request on the path that the test ran. A general claim needs the mechanism argument for every path.

Prevention is not always possible at a given layer. An insider who uses legitimate access, or a secret that leaks through timing, may be detectable there but not preventable. Detection then backs up prevention as part of defense in depth §1.18: several independent layers, so that one failure does not decide the outcome.

Each kind of control has its own cost of error. A wrong verdict by a preventive control, a false positive §1.22, blocks legitimate work. False alarms from a detective control cost attention and can bury real alerts. An inline prevention system is itself on the path: if it fails open when overloaded, traffic passes unchecked, and if it fails closed, traffic stops.

Questions answered

What evidence establishes that a deny decision prevented the side effect?

Three pieces of evidence together establish that a deny decision prevented a side effect: proof that the request would have caused the effect if it had been allowed, direct observation that the effect did not occur when the request was denied, and a code-level argument that the deny is what stopped it. The side effect is the change the request would make outside the decision itself, such as a write to protected memory or a transmitted message.

  1. Reachability. The same request with the rule set to allow, a run called a positive control, does produce the effect. Otherwise an unchanged state may only mean that the request never reached the code that performs the effect.

  2. Outcome. With the rule set to deny, an observer independent of the deciding component, such as a debugger, a bus trace, a radio receiver or a read-back of storage, shows that the effect never occurred, not even temporarily, over the whole time the effect could occur, including operations queued for later. A final value equal to the starting value is not enough, because a write followed by a restore ends the same way.

  3. Mechanism. The code that performs the effect runs only after an allow decision for exactly the same request, the deny branch returns before the effect, a missing or failed decision also blocks the effect, and no other path reaches the effect.

The scope of the evidence must be stated. One run covers one request on one path. Repeated runs bound a rate for the tested conditions. Only the mechanism argument covers every path. A deny entry in a log, or an unchanged final value, is not enough on its own.

Related entries: Observation versus enforcement (§1.20), Mechanism versus evidence (§1.37), Fault-to-verdict mapping (§2.34), False positive and false negative (§1.22), Positive control (§10.30), Defense in depth (§1.18). Further reading: [412].