L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU)

CS 161, Lesson 2, in 50 slides. It covers the nine remaining design principles: defense in depth, least privilege, separation of responsibility, complete mediation, Shannon's Maxim, fail-safe defaults, designing security in from the start, the Trusted Computing Base, and TOCTTOU races. It is anchored to textbook sections 1.5 to 1.13 and to Saltzer & Schroeder (1975).

Subject: Computer Security · 64 slides · applied lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. Nine Principles That Keep Recurring

Title

CS 161 · Lesson 2 of 45

Defense in depth · least privilege · mediation · Shannon · fail-safe · TCB · TOCTTOU

2. By the end of this lesson you can…

Objectives

  1. Distinguish defense in depth (layers), least privilege (minimize grants), and separation of responsibility (split authority) by what each one buys you.
  2. Apply complete mediation via a reference monitor, and spot where a TOCTTOU race breaks it.
  3. State Shannon's Maxim and explain why security-through-obscurity is self-defeating.
  4. Decide a fail-safe default for a control and contrast it with fail-open.
  5. Identify what is in and out of a system's Trusted Computing Base, and argue for shrinking it using defect-rate math.

3. What survived from L01 · Security Principles I (Threat Models, Human Factors…?

Warm-up

Discussion prompt

Before we open L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU): without looking back, what was the main idea of L01 · Security Principles I (Threat Models, Human Factors, Economics), and what could you do by the end of it that you could not do before?

Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.

Answer:

CS 161, Lesson 1. It covers threat models, attacker assumptions, human factors, security economics, and the principle of detecting what you cannot prevent, across 20 slides anchored to textbook sections 1.1 to 1.4 and to Saltzer & Schroeder (1975).

4. Where these came from

Concept

Six of today's nine principles were named in a single 1975 paper. They recur in every later unit — memory safety, crypto, web, network.

Layer & minimize
§1.5 depth · §1.6 least privilege · §1.7 separation
Mediate & open
§1.8 complete mediation · §1.9 Shannon's Maxim
Default & design
§1.10 fail-safe · §1.11 design-from-start · §1.12 TCB · §1.13 TOCTTOU

5. Which is which: Where these came from

Matching

Match the pairs

From Where these came from — match each one to what it actually does. The descriptions have been shuffled.

  • c1. Layer & minimize
  • c2. Mediate & open
  • c3. Default & design
  • b1. §1.5 depth · §1.6 least privilege · §1.7 separation
  • b2. §1.8 complete mediation · §1.9 Shannon's Maxim
  • b3. §1.10 fail-safe · §1.11 design-from-start · §1.12 TCB · §1.13 TOCTTOU

Why: Layer & minimize, Mediate & open, Default & design are easy to tell apart while they are sitting next to their descriptions and much harder afterwards, which is what this checks.

6. Layer & Minimize

Section

Part 1 · §1.5–1.7

7. §1.5 Defense in depth

Concept

Layer multiple kinds of defense so an attacker must breach all of them, not just one.

Defense in depth — Independent layers stacked so a single failure is not catastrophic — high walls, then a moat, then inner walls.

But it is not foolproof (siege cannons ignore walls), and it has diminishing returns — the 101st wall rarely justifies its cost. That caveat is just §1.3 economics again.

8. Break it if you can: §1.5 Defense in depth

Counterexample

Discussion prompt

Layer multiple kinds of defense so an attacker must breach all of them, not just one.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

9. What has to happen first: §1.5 Two detectors: series vs parallel

Ranking

Put in order

Put the moves of §1.5 Two detectors: series vs parallel into the order they have to happen.

  1. Set up two detectors D1, D2, each with a false-alarm rate and a missed-attack rate
  2. Wire them in PARALLEL (either alert fires a response)
  3. Wire them in SERIES (both must alert)
  4. Choose by cost

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. A detector trades these two error types off against each other; composing them lets you steer the trade-off.

10. §1.5 Two detectors: series vs parallel

Worked example

Set up two detectors D1, D2, each with a false-alarm rate and a missed-attack rate

Why: A detector trades these two error types off against each other; composing them lets you steer the trade-off.

Wire them in PARALLEL (either alert fires a response)

Why: Fewer attacks slip past (lower miss rate) but more false alarms — you catch more, and cry wolf more.

Wire them in SERIES (both must alert)

Why: Far fewer false alarms, but more misses — you only act when both agree, so quiet attacks get through.

Choose by cost

Why: There is no free lunch: the right wiring depends on whether a missed attack or a false alarm costs you more — economics decides the layering.

11. Draw the shape of it: §1.5 Two detectors: series vs parallel

Blank canvas

Draw it

Draw what §1.5 Two detectors: series vs parallel just did — the shape of it, not the line-by-line working. One picture, labels only where you need them. Then check it against the steps: anything you could not draw is a step you followed rather than understood.

12. §1.6 Least privilege

Concept

Give each program exactly the access it needs to do its job — and nothing more.

It does not lower the probability of failure; it lowers the expected cost of failure. Less privilege ⇒ less harm when (not if) the program is subverted.

13. By analogy: §1.6 Least privilege

Analogy

Discussion prompt

Explain §1.6 Least privilege by analogy to something with no Computer Security in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

Give each program exactly the access it needs to do its job — and nothing more.

14. §1.6 Unix is 'pretty lousy' at this

Intuition

On Unix every program you launch inherits all your user's privileges. A text editor opening one file can also read, modify, or delete every other file you own — far more than it needs. Windows: 'just as lousy.'

Mobile does better: each app is sandboxed and cannot touch other apps' data, so one compromised app does limited harm.

Ask yourself: when a buffer overflow (next unit) fully takes over a process, what determines the blast radius? The privileges that process was holding.

15. Teach it back: §1.6 Unix is 'pretty lousy' at this

Explain it

Discussion prompt

Explain §1.6 Unix is 'pretty lousy' at this to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

Mobile does better: each app is sandboxed and cannot touch other apps' data, so one compromised app does limited harm.

16. Something is wrong here: 'least privilege stops the exploit'

Anomaly

Predict first

A student writes this, and it looks reasonable:

A media server has an exploitable bug.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Confuses reducing impact with reducing likelihood — the bug is just as reachable.

A media server has an exploitable bug.

Why: Confuses reducing impact with reducing likelihood — the bug is just as reachable.

17. Trap: 'least privilege stops the exploit'

Trap

The trap

A media server has an exploitable bug.

Claim: running it as a low-privilege user PREVENTS the compromise

Why: Confuses reducing impact with reducing likelihood — the bug is just as reachable.

The fix

A media server has an exploitable bug.

Claim: it still gets compromised, but the attacker inherits only the server's tiny privilege set

Why: §1.6: least privilege does not change the probability of failure, only the cost. The exploit lands; the damage is contained.

18. §1.7 Separation of responsibility

Concept

Split privilege so no single person or program has complete power. Require more than one party to approve a sensitive action.

A nuclear silo needs two launch officers to agree. The bar: it is far likelier that one party is malicious than that all parties collude.

19. §1.7 Why the movie usher tears your ticket

Intuition

You pay a cashier for a ticket; ten feet later a different employee tears it and drops half in a lockbox. Why two people for one transaction?

Insider fraud. With one employee, they could wave a friend in for free. Splitting 'sell' and 'admit' across two people means a free entry now requires both to collude — much harder.

Ask yourself: this is the human-world version of which later crypto idea? (Threshold / multi-signature schemes.)

20. Mediate & Open

Section

Part 2 · §1.8–1.9

21. §1.8 Complete mediation

Concept

Check every access to every object — no exceptions, no caching a decision past the point it can go stale.

Reference monitor — A single, unbypassable point through which all access must pass — so getting that one point right protects everything behind it.

22. Take the definitions apart: Defense in depth vs Reference monitor

Definition probe

Sort into buckets

Every line below is part of the definition of Defense in depth or of Reference monitor — one or the other, never both. Put each where it belongs.

Defense in depth
Independent layers stacked so a single failure is not catastrophic; high walls, then a moat, then inner walls.
Reference monitor
A single, unbypassable point through which all access must pass; so getting that one point right protects everything behind it.
b1
Independent layers stacked so a single failure is not catastrophic — high walls, then a moat, then inner walls.
b2
A single, unbypassable point through which all access must pass — so getting that one point right protects everything behind it.

23. §1.8 The airport checkpoint

Intuition

An airport funnels every passenger through a few security checkpoints. Get those checkpoints right and there is no way around them, and you protect hundreds of gates with a handful of controls.

The failure mode to watch: any path that reaches a gate without passing a checkpoint. In software, a cached 'already authorized' flag that outlives the authorization is exactly that bypass — which sets up TOCTTOU (Part 4).

24. §1.9 Shannon's Maxim

Concept

Assume the attacker knows the system — its algorithms, hardware, and defenses. Never rely on the design being secret.

The related Kerckhoff's Principle (crypto unit): a system must stay secure even when everything except the key is public — and keys are easy to rotate when leaked, unlike a whole codebase.

25. Teach it back: §1.9 Shannon's Maxim

Explain it

Discussion prompt

Explain §1.9 Shannon's Maxim to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

The related Kerckhoff's Principle (crypto unit): a system must stay secure even when everything except the key is public — and keys are easy to rotate when leaked, unlike a whole codebase.

26. Something is wrong here: security through obscurity

Anomaly

Predict first

A student writes this, and it looks reasonable:

A vendor: 'Only ~100 people understand our protocol, so attackers won't bother.'

It is wrong. Say what breaks — and say it before you turn the page.

Correct: Self-defeating: success makes the system popular, which raises the incentive to reverse-engineer it — and then the obscurity is gone.

A vendor: 'Only ~100 people understand our protocol, so attackers won't bother.'

Why: Self-defeating: success makes the system popular, which raises the incentive to reverse-engineer it — and then the obscurity is gone.

27. Trap: security through obscurity

Trap

The trap

A vendor: 'Only ~100 people understand our protocol, so attackers won't bother.'

Treat secrecy of design as the security mechanism

Why: Self-defeating: success makes the system popular, which raises the incentive to reverse-engineer it — and then the obscurity is gone.

The fix

A vendor: 'Only ~100 people understand our protocol, so attackers won't bother.'

Assume the design is public and rest security on a rotatable secret key

Why: §1.9 / Kerckhoff: security must survive full knowledge of the system. Obscurity may be a thin extra layer, never the foundation.

28. Default & Design

Section

Part 3 · §1.10–1.11

29. §1.10 Fail-safe defaults

Concept

When a mechanism fails or crashes, it should fail toward the secure state, not away from it. Default to deny; allow only what is explicitly permitted.

30. By analogy: §1.10 Fail-safe defaults

Analogy

Discussion prompt

Explain §1.10 Fail-safe defaults by analogy to something with no Computer Security in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

When a mechanism fails or crashes, it should fail toward the secure state, not away from it. Default to deny; allow only what is explicitly permitted.

31. Plan first: §1.10 Firewall: fail-safe vs fail-open

Step zero

Discussion prompt

§1.10 Firewall: fail-safe vs fail-open — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Adopt a default-deny policy

Answer:

  1. Adopt a default-deny policy
  2. Now crash the firewall
  3. Contrast a fail-open design

32. §1.10 Firewall: fail-safe vs fail-open

Worked example

Adopt a default-deny policy

Why: The firewall must explicitly decide to forward each packet; anything not permitted is dropped.

Now crash the firewall

Why: With default-deny, a crashed firewall forwards nothing — it fails closed. Inconvenient, but safe.

Contrast a fail-open design

Why: If a crash let all packets through, the attacker's whole job is to induce a crash, then 'the fort is wide open.' Fail-open hands the attacker a one-step win.

33. §1.11 Design security in from the start

Concept

Retrofitting security onto a finished system is painful: you are stuck with an architecture that may not permit least privilege, complete mediation, or a clean TCB.

Backwards compatibility makes it worse — you can inherit the worst insecurities of every prior version. Bake the decomposition in while the architecture is still soft.

34. Where does each piece belong: L02 · Security Principles II (the remaining…

Sorting

Sort into buckets

These are the pieces of L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU), out of order. Put each one back under the part of the lesson it belongs to.

Layer & Minimize
§1.5 Defense in depth; §1.5 Two detectors: series vs parallel; §1.6 Least privilege
Mediate & Open
§1.8 Complete mediation; §1.8 The airport checkpoint; §1.9 Shannon's Maxim
Default & Design
§1.10 Fail-safe defaults; §1.10 Firewall: fail-safe vs fail-open; §1.11 Design security in from the start
s1
Layer & Minimize is where L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU) puts §1.5 Defense in depth, §1.5 Two detectors: series vs parallel, §1.6 Least privilege. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s2
Mediate & Open is where L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU) puts §1.8 Complete mediation, §1.8 The airport checkpoint, §1.9 Shannon's Maxim. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.
s3
Default & Design is where L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU) puts §1.10 Fail-safe defaults, §1.10 Firewall: fail-safe vs fail-open, §1.11 Design security in from the start. Knowing which part of the lesson a problem belongs to is most of knowing which method to reach for.

35. The TCB & TOCTTOU

Section

Part 4 · §1.12–1.13

36. §1.12 The Trusted Computing Base

Concept

TCB — The portion of a system that must operate correctly for the security goals to hold. Everything outside it can misbehave — even maliciously — without defeating those goals.

Make the TCB unbypassable (no path around it), tamper-resistant (nothing outside can modify its code or state), and verifiable (simple enough to actually check).

37. Break it if you can: §1.12 The Trusted Computing Base

Counterexample

Discussion prompt

Make the TCB unbypassable (no path around it), tamper-resistant (nothing outside can modify its code or state), and verifiable (simple enough to actually check).

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

38. §1.12 What's in the TCB for 'only authorized SSH logins'?

Intuition

Goal: only authorized users may SSH into the server. Walk the dependency chain.

ComponentIn TCB?Why
SSH daemonYesIt makes the auth decision — a bug here lets in unauthorized users
Operating systemYesIt can tamper with the daemon's memory, so it must be correct
CPUYesWe rely on it to execute the daemon's instructions faithfully
Web browser on same hostNo (hopefully)OS memory protection isolates it from the daemon — its bugs can't grant SSH access

Ask yourself: if the browser can reach the daemon's memory, what just happened to your TCB? (It silently grew — and the 'tamper-resistant' property failed.)

39. Which is which, by In TCB?

Discrimination

Sort into buckets

Sort these by In TCB?, from memory, without looking back at §1.12 What's in the TCB for 'only authorized SSH…. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

Yes
SSH daemon; Operating system; CPU
No (hopefully)
Web browser on same host
g1
In TCB? is "Yes" for SSH daemon, Operating system, CPU — that is what the table on "§1.12 What's in the TCB for 'only…" records, and it is the single property separating this group from the rest.
g2
In TCB? is "No (hopefully)" for Web browser on same host — that is what the table on "§1.12 What's in the TCB for 'only…" records, and it is the single property separating this group from the rest.

40. What has to happen first: §1.12 Why a small TCB wins: the defect-rate math

Ranking

Put in order

Put the moves of §1.12 Why a small TCB wins: the defect-rate math into the order they have to happen.

  1. Take the industry error rate: 1–5 defects per 1,000 lines of code
  2. A 1,000-line TCB → about 1–5 defects
  3. A 100,000-line TCB → about 100–500 defects
  4. Conclusion: shed code

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. An empirical baseline — more code means proportionally more latent bugs.

41. §1.12 Why a small TCB wins: the defect-rate math

Worked example

Take the industry error rate: 1–5 defects per 1,000 lines of code

Why: An empirical baseline — more code means proportionally more latent bugs.

A 1,000-line TCB → about 1–5 defects

Why: Few enough that you can plausibly find and remove the security-relevant ones.

A 100,000-line TCB → about 100–500 defects

Why: Now auditing every exploitable flaw is hopeless. (Windows XP put ~40 million lines in the TCB — a virtual certainty of vulnerabilities.)

Conclusion: shed code

Why: Decompose so as much code as possible lives OUTSIDE the TCB. Smaller TCB ⇒ fewer defects to chase ⇒ better odds of a secure system.

42. Draw the shape of it: §1.12 Why a small TCB wins: the defect-rate…

Blank canvas

Draw it

Draw what §1.12 Why a small TCB wins: the defect-rate math just did — the shape of it, not the line-by-line working. One picture, labels only where you need them. Then check it against the steps: anything you could not draw is a step you followed rather than understood.

43. §1.13 TOCTTOU: a race that breaks mediation

Concept

A time-of-check-to-time-of-use bug: state is validated at the check, then changes before the use, so the stale check authorizes something it shouldn't. It is the classic failure of complete mediation under concurrency.

44. What has to happen first: §1.13 The $100 → $200 ATM withdrawal

Ranking

Put in order

Put the moves of §1.13 The $100 → $200 ATM withdrawal into the order they have to happen.

  1. Balance is $100; you request w = $100 at ATM-1, and pause it right after step 2
  2. Walk to ATM-2 and withdraw $100 to completion
  3. Unpause ATM-1; it completes steps 3–4 on its stale check

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. The check (b ≥ w) has passed, but the use (set balance) has not happened yet — the decision is now stale-able.

45. §1.13 The $100 → $200 ATM withdrawal

Worked example

procedure withdraw(amount w) {
  // contact central server to get balance
  1. let b := balance
  2. if b < w, abort
  // contact central server to set the balance
  3. set balance := b - w
  4. give w dollars to the user
}

Balance is $100; you request w = $100 at ATM-1, and pause it right after step 2

Why: The check (b ≥ w) has passed, but the use (set balance) has not happened yet — the decision is now stale-able.

Walk to ATM-2 and withdraw $100 to completion

Why: ATM-2 reads balance $100, passes its own check, sets balance to $0, dispenses $100. Account is now empty.

StepATM-1 seesATM-2 seesReal balance
ATM-1 reads bb=100—100
ATM-1 check passes, PAUSE100 ≥ 100 ✓—100
ATM-2 full withdraw(paused)100→0, pays $1000
ATM-1 resumes step 3–4sets 100−100=0, pays $100—0 (but $200 paid)

Unpause ATM-1; it completes steps 3–4 on its stale check

Why: ATM-1 never re-checked the balance after the pause, so it pays a second $100. You withdrew $200 from a $100 account — the check and the use disagreed.

46. Which is which, by ATM-2 sees

Discrimination

Sort into buckets

Sort these by ATM-2 sees, from memory, without looking back at §1.13 The $100 → $200 ATM withdrawal. Telling them apart on the spot is the skill; the table is only where the answer happens to be written down.

—
ATM-1 reads b; ATM-1 check passes, PAUSE; ATM-1 resumes step 3–4
100→0, pays $100
ATM-2 full withdraw
g1
ATM-2 sees is "—" for ATM-1 reads b, ATM-1 check passes, PAUSE, ATM-1 resumes step 3–4 — that is what the table on "§1.13 The $100 → $200 ATM withdrawal" records, and it is the single property separating this group from the rest.
g2
ATM-2 sees is "100→0, pays $100" for ATM-2 full withdraw — that is what the table on "§1.13 The $100 → $200 ATM withdrawal" records, and it is the single property separating this group from the rest.

47. Something is wrong here: 'just re-order the lines to fix TOCTTOU'

Anomaly

Predict first

A student writes this, and it looks reasonable:

Fix attempt: move the balance read closer to the write.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: A smaller race window is still a race window — under enough tries (persistent attacker) it still hits.

Fix attempt: make check-and-use one indivisible step.

Why: A smaller race window is still a race window — under enough tries (persistent attacker) it still hits.

48. Trap: 'just re-order the lines to fix TOCTTOU'

Trap

The trap

Fix attempt: move the balance read closer to the write.

Shrink the gap between check and use, call it fixed

Why: A smaller race window is still a race window — under enough tries (persistent attacker) it still hits.

The fix

Fix attempt: make check-and-use one indivisible step.

Use an atomic compare-and-set / a lock / a transaction so no other withdraw can interleave

Why: §1.13: the only real fix removes the interleaving entirely — check and use must be one atomic operation, restoring complete mediation.

49. Which of these survive contact with L02 · Security Principles II (the remaining…?

Two truths and a lie

Sort into buckets

Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.

Holds up
Layer multiple kinds of defense so an attacker must breach all of them, not just one.; Give each program exactly the access it needs to do its job — and nothing more.; Mobile does better: each app is sandboxed and cannot touch other apps' data, so one compromised app does limited harm.
Breaks
A media server has an exploitable bug.; A vendor: 'Only ~100 people understand our protocol, so attackers won't bother.'
sound
These are stated as this lesson states them — each one survives the edge cases L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU) puts it through.
flawed
Each of these is lifted from a trap in this deck: reasonable-sounding, and wrong in a way that only shows up once you rely on it.

50. The nine-principle checklist

Pattern

  1. Defense in depth (§1.5): independent layers; mind diminishing returns.
  2. Least privilege (§1.6): minimize grants; shrinks blast radius, not bug count.
  3. Separation of responsibility (§1.7): require ≥2 parties for sensitive actions.
  4. Complete mediation (§1.8): check every access via a reference monitor.
  5. Shannon's Maxim (§1.9): assume the design is public; protect the key, not the secret.
  6. Fail-safe defaults (§1.10): default-deny; fail closed.
  7. Design from the start (§1.11): you cannot bolt security on later.
  8. Minimal TCB (§1.12): unbypassable, tamper-resistant, verifiable; shed code.
  9. Beware TOCTTOU (§1.13): make check-and-use atomic.

51. Where does it stop working: The nine-principle checklist

Edge cases

Discussion prompt

The nine-principle checklist works on the cases you have just seen. Push it to the edge: what is the most degenerate input it still handles — empty, zero, one item, everything equal — and what is the first case where it stops being true? Name the case, not just "it breaks".

Hint: Try the smallest legal input, then the largest, then the one where two things collide. Methods are specified at their edges; the middle takes care of itself.

Answer:

  1. Defense in depth (§1.5): independent layers; mind diminishing returns.
  2. Least privilege (§1.6): minimize grants; shrinks blast radius, not bug count.
  3. Separation of responsibility (§1.7): require ≥2 parties for sensitive actions.
  4. Complete mediation (§1.8): check every access via a reference monitor.
  5. Shannon's Maxim (§1.9): assume the design is public; protect the key, not the secret.
  6. Fail-safe defaults (§1.10): default-deny; fail closed.
  7. Design from the start (§1.11): you cannot bolt security on later.
  8. Minimal TCB (§1.12): unbypassable, tamper-resistant, verifiable; shed code.
  9. Beware TOCTTOU (§1.13): make check-and-use atomic.

52. Rule out three: Checkpoint 1 — which principle limits the damage?

Elimination

Eliminate the wrong options

Which principle most directly limits how much harm the attacker can do, and why?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. Least privilege — if the reader runs sandboxed, the attacker inherits only its tiny privilege set.
  • B. Complete mediation — checking every access would have blocked the exploit.
  • C. Defense in depth — more layers would have prevented the bug from existing.
  • D. Shannon's Maxim — keeping the reader's code secret would have stopped the attacker.

Survives elimination: A

Why: §1.6: least privilege does not reduce the probability of compromise, but it bounds the cost. A sandboxed reader hands the attacker only the reader's minimal privileges, so the blast radius is small.

53. Checkpoint 1 — which principle limits the damage?

Check

A PDF reader is taken over by a memory-corruption exploit while a user opens an email attachment.

Check your understanding

Which principle most directly limits how much harm the attacker can do, and why?

  • A. Least privilege — if the reader runs sandboxed, the attacker inherits only its tiny privilege set. (correct)
  • B. Complete mediation — checking every access would have blocked the exploit.
  • C. Defense in depth — more layers would have prevented the bug from existing.
  • D. Shannon's Maxim — keeping the reader's code secret would have stopped the attacker.

Answer: A

Why: §1.6: least privilege does not reduce the probability of compromise, but it bounds the cost. A sandboxed reader hands the attacker only the reader's minimal privileges, so the blast radius is small.

Why B tempts people
Complete mediation governs access checks, not the privilege a compromised process already holds — it wouldn't bound this blast radius.
Why C tempts people
Defense in depth adds layers but does not erase an existing bug, and the question asks about limiting damage after compromise.
Why D tempts people
Shannon's Maxim says to assume the attacker already knows the code; secrecy of design is not a real defense.

54. Answer it before you see the options: Checkpoint 2 — the TOCTTOU window

Prediction

Predict first

To double-withdraw, between which two steps must the attacker stall ATM-1?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: Between step 2 and step 3 — after the check passes but before the balance is updated.

Why: The race is the gap between the check (step 2) and the use (step 3). Stalling there lets ATM-2 complete a full withdrawal, so ATM-1 later acts on a balance value that is no longer true.

55. Checkpoint 2 — the TOCTTOU window

Check

Re-read the withdraw() procedure: (1) read balance, (2) abort if too low, (3) set balance, (4) dispense.

Check your understanding

To double-withdraw, between which two steps must the attacker stall ATM-1?

  • A. Between step 1 and step 2 — before the balance is even read.
  • B. Between step 2 and step 3 — after the check passes but before the balance is updated. (correct)
  • C. Between step 3 and step 4 — after the balance is already decremented.
  • D. After step 4 — once the cash is dispensed.

Answer: B

Why: The race is the gap between the check (step 2) and the use (step 3). Stalling there lets ATM-2 complete a full withdrawal, so ATM-1 later acts on a balance value that is no longer true.

Why A tempts people
Before the read there is no checked value to make stale — the vulnerable state hasn't been established yet.
Why C tempts people
By step 3 the balance is already being written; the stale-check exploitation has to happen before the write, not after.
Why D tempts people
After dispensing, ATM-1's transaction is over; there is nothing left to exploit on that run.

56. Answer it before you see the options: Checkpoint 3 — in or out of the TCB?

Prediction

Predict first

Which component is (hopefully) NOT in the TCB for this goal?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: An unprivileged web browser installed on the same machine.

Why: §1.12: the TCB is whatever must be correct for the goal to hold. The daemon, OS, and CPU all can directly defeat the goal, so they're in. A correctly isolated, unprivileged browser is kept out by OS memory protection — its bugs cannot grant SSH access.

57. Checkpoint 3 — in or out of the TCB?

Check

Security goal: only authorized users may log into a Linux server over SSH.

Check your understanding

Which component is (hopefully) NOT in the TCB for this goal?

  • A. The SSH daemon that performs authentication.
  • B. The operating system kernel.
  • C. An unprivileged web browser installed on the same machine. (correct)
  • D. The CPU executing the daemon's instructions.

Answer: C

Why: §1.12: the TCB is whatever must be correct for the goal to hold. The daemon, OS, and CPU all can directly defeat the goal, so they're in. A correctly isolated, unprivileged browser is kept out by OS memory protection — its bugs cannot grant SSH access.

Why A tempts people
The daemon makes the authorization decision itself, so a bug in it directly violates the goal — it is squarely in the TCB.
Why B tempts people
The OS can tamper with the daemon's address space, so it must be trusted — in the TCB.
Why D tempts people
We rely on the CPU to execute the daemon faithfully; if it misbehaves the goal can fail — in the TCB.

58. Rule out three: Checkpoint 4 — fail-safe reasoning

Elimination

Eliminate the wrong options

Why does §1.10 prefer design X even though it can lock out legitimate traffic on failure?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. Because default-deny is faster to evaluate per packet.
  • B. Because on a crash X forwards nothing, so a failure can't open the network to the attacker.
  • C. Because default-allow violates Shannon's Maxim.
  • D. Because X needs no explicit rules, simplifying configuration.

Survives elimination: B

Why: §1.10 fail-safe defaults: a mechanism should fail toward the secure state. Default-deny fails closed, so inducing a crash gains the attacker nothing; default-allow fails open, turning a crash into a one-step breach.

59. Checkpoint 4 — fail-safe reasoning

Check

Two firewall designs: (X) default-deny, drops anything not explicitly allowed; (Y) default-allow, forwards anything not explicitly blocked.

Check your understanding

Why does §1.10 prefer design X even though it can lock out legitimate traffic on failure?

  • A. Because default-deny is faster to evaluate per packet.
  • B. Because on a crash X forwards nothing, so a failure can't open the network to the attacker. (correct)
  • C. Because default-allow violates Shannon's Maxim.
  • D. Because X needs no explicit rules, simplifying configuration.

Answer: B

Why: §1.10 fail-safe defaults: a mechanism should fail toward the secure state. Default-deny fails closed, so inducing a crash gains the attacker nothing; default-allow fails open, turning a crash into a one-step breach.

Why A tempts people
Per-packet speed is not the reason; the principle is about the direction of failure, not performance.
Why C tempts people
Shannon's Maxim is about assuming the attacker knows the design, unrelated to default-deny vs default-allow.
Why D tempts people
Backwards — default-deny requires you to explicitly allow each permitted flow; it is more configuration, not less.

60. Misconceptions graduate students still make

Concept

61. Synthesis — how Lesson 2 threads the whole course

Concept

62. Primary sources & where to read more

Concept

63. Connect it up: L02 · Security Principles II (the remaining nine: Defense in Depth → TOCTTOU)

Connect it up

Draw it

One page, no notation unless you need it: draw how these connect — Layer & Minimize · Mediate & Open · Default & Design · The TCB & TOCTTOU. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.

64. Recap — Lesson 2

Recap

You can now place each of the nine principles, name what it actually buys you, find a TOCTTOU window, and argue for a small, verifiable TCB.

Principle§Buys you
Defense in depth1.5Survive one failed layer
Least privilege1.6Smaller blast radius
Separation1.7No single point of betrayal
Complete mediation1.8No unchecked access path
Shannon's Maxim1.9Security without secret designs
Fail-safe defaults1.10Crashes fail closed
Design from start1.11Architecture that allows the above
Minimal TCB1.12Fewer defects to trust
TOCTTOU-aware1.13Atomic check-and-use

Sources

  1. CS 161 Computer Security Textbook §1.5–1.13 — Wagner, Weaver, Kao, Shakir, Law & Ngai, UC Berkeley — defense in depth, least privilege, separation, complete mediation, Shannon's Maxim, fail-safe defaults, design-from-start, TCB, TOCTTOU
  2. The Protection of Information in Computer Systems — J. Saltzer & M. Schroeder, Proc. IEEE 63(9), 1975 — origin of least privilege, complete mediation, fail-safe defaults, separation of privilege, economy of mechanism
  3. TOCTTOU: A Study of Time-of-Check-to-Time-of-Use Race Conditions — Bishop & Dilger, Computing Systems, 1996 — the canonical analysis of filesystem TOCTTOU races

Want this taught 1-on-1? Alexander tutors Computer Security — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108