Chapter 20

Question trees: crash prevention, bytecode, and key lifecycles

Each entry in this chapter is a question tree: a root question followed by follow-up questions that change one assumption at a time, each with a full answer. All trees share one hypothetical scenario. A sensor gateway receives a small decision program through a phone; the phone only transports bytes, and an authorized publisher may change the policy. The gateway runs the program inside a virtual machine §2.3, keeps serving other work, and must recover sensibly if power fails during a key change §5.29. That one story raises several different questions: who may send a program, what its instructions may do, when the requested effect is complete, and which authority survives a failure. A correct answer keeps these questions apart instead of letting a word such as “verified” or “encrypted” stand for all of them.

The trees apply mechanisms whose complete treatment is in the core chapters, for example the eBPF verifier §3.3, the overflow-safe range check §4.17, HMAC (hash-based message authentication code) §5.8 and authenticated encryption with associated data (AEAD) §5.16; the links lead to those entries. Each answer applies the mechanisms to a changed assumption or a failure and gives a complete general answer. All numbers, protocols, roles and devices in the trees are hypothetical teaching choices.

For the key-lifecycle questions, let KaK_a denote the current active message-authentication key, KpK_p a pending replacement, KrK_r a recovery credential, and gg a generation number that the gateway’s policy accepts. These roles are choices for the exercise, not a prescribed deployment. A complete request has an unambiguous encoding of its device, operation, role, generation, transaction §8.7 identity and object bytes wherever those fields affect authority. Later questions deliberately remove one of these assumptions.

In this chapter

  1. 20.1 Tree 1: “Does eBPF guarantee that a device cannot crash?”
  2. 20.2 Tree 2: “How can a verifier establish memory safety?”
  3. 20.3 Tree 3: “Can handwritten assembly bypass checks on C code?”
  4. 20.4 Tree 4: “Why use a different instruction set at all?”
  5. 20.5 Tree 5: “Can one prove that a read stays inside its object?”
  6. 20.6 Tree 6: “Can a bounds check itself overflow?”
  7. 20.7 Tree 7: “Are buffer overflow and stack overflow the same?”
  8. 20.8 Tree 8: “What about uninitialized data and use-after-free?”
  9. 20.9 Tree 9: “Can helpers or a JIT break an accepted program?”
  10. 20.10 Tree 10: “If memory is safe, can malicious code still deny service?”
  11. 20.11 Tree 11: “What changes on an MCU without process isolation?”
  12. 20.12 Tree 12: “The HMAC is valid; why verify the program?”
  13. 20.13 Tree 13: “What exactly does HMAC compute and authenticate?”
  14. 20.14 Tree 14: “How are good keys generated and provisioned?”
  15. 20.15 Tree 15: “Why derive separate keys and bind context?”
  16. 20.16 Tree 16: “How do keys survive storage, boot, and transport safely?”
  17. 20.17 Tree 17: “How do rotation, activation, and revocation work together?”
  18. 20.18 Tree 18: “What happens if power fails during a key change?”
  19. 20.19 Tree 19: “What if the active or recovery key is compromised?”
  20. 20.20 Tree 20: “When can a key be retired or destroyed?”
  21. 20.21 One connected exercise: from a publisher’s bytes to a retired key