eBPF-based security platform
proofs: say which register theorems hold only of an idealized hash
Daniel Borkmann14f52c0cc216
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex 07968f0d..ffa046c2 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -1049,20 +1049,23 @@ the model follows the C.- ``max`` fits a ``__u64``- CBMC, ``string-number-model``, up to 4 bytes* - ``Shirudo.Chain``, the register of :src:`util/chain.c`- - ``register_injective``, ``register_tagged_injective``: equal- registers come from the same events, tagged the same, in the same- order; ``register_injective_on``: the same with the hash injective- only on the pairs the two sequences fold; ``register_eq_foldl``: the+ - ``register_injective``, ``register_tagged_injective``: for an+ idealized hash, equal registers come from the same events, tagged+ the same, in the same order; ``register_injective_on``: the same+ with the hash injective only on the pairs the two sequences fold,+ which SHA-256 can be; ``register_eq_foldl``: theregister folds the events in the order they came;``history_ignores_outcomes``: a upatch tree's history root is thesame on two nodes that processed operations of the same digests,whatever outcome each had; ``processAll_history``,``historyRoot_append_one``: it takes one step per operation- - The hash is injective on the (register, event) pairs (for- ``register_injective_on`` only those folded) and never yields the- initial value; ``register_tagged_injective`` also takes the tagged- encoding as injective, which ``Shirudo.Events`` proves; none for- the history root+ - The hash never yields the initial value and is injective on the+ (register, event) pairs: on every pair for ``register_injective``+ and ``register_tagged_injective``, which no hash onto 32 bytes+ is, so the two hold of an idealized hash only; on those folded for+ ``register_injective_on``. ``register_tagged_injective`` also+ takes the tagged encoding as injective, which ``Shirudo.Events``+ proves; none for the history root- Review; the bytes of the history root's step are``historyBytes`` of ``Shirudo.Events``, which CBMC,``chain-events``, checks@@ -1185,10 +1188,11 @@ the model follows the C.- Commands one at a time; atomic renames of ``state`` and``next-boot``; a crash leaves a prefix of a line; only shirudowrites the journal and the config mount during a boot; PCRs reset- only at a reboot or TPM Restart; equal values from equal- extensions (``pcr_value_eq_iff`` with ``Shirudo.Chain``'s- assumptions). All but ``journal_wellformed``,- ``mounted_selected``, ``boot_completion``,+ only at a reboot or TPM Restart; PCRs compared as their lists of+ extensions, which ``pcr_value_eq_iff`` justifies for the idealized+ hash of ``register_injective`` and SHA-256 meets unless it+ collides among the values compared. All but+ ``journal_wellformed``, ``mounted_selected``, ``boot_completion``,``completion_by_complete`` and ``extension_follows_save`` also takea calm TPM, whose boot changes only between commands and never toan identity it had, which root breaks with a suspend ordiff --git a/testing/proofs/lean4/Shirudo/Chain.lean b/testing/proofs/lean4/Shirudo/Chain.leanindex b20bacdc..17fc9cef 100644--- a/testing/proofs/lean4/Shirudo/Chain.lean+++ b/testing/proofs/lean4/Shirudo/Chain.lean@@ -6,13 +6,15 @@ The measurement register of util/chain.c. Each upatch state changeextends it as `H(register ‖ event)`, the way a TPM extends a PCR, with anevent that hashes a domain-separating tag and its payload. `attest verify`replays the eventlog and compares the result with the register the TPM-signed. Assuming `H` is collision resistant, modelled as injective on-(register, event) pairs and never yielding the initial value, and the-tagged encoding of events likewise, equal registers mean the target-measured exactly the events the log shows, in that order.-`register_injective_on` asks the same of `H` only on the pairs the two-sequences fold, which a real hash can meet; `Shirudo.Events` proves the-encodings of util/chain.c injective and builds the end theorem on it.+signed. For `H` injective on (register, event) pairs and never yielding+the initial value, and the tagged encoding of events likewise, equal+registers mean the target measured exactly the events the log shows, in+that order (`register_injective`, `register_tagged_injective`). No hash+onto a fixed width is injective on every pair, so those two hold of an+idealized hash only. `register_injective_on` asks the same of `H` only on+the pairs the two sequences fold, which SHA-256 can meet;+`Shirudo.Events` proves the encodings of util/chain.c injective and+builds the end theorem on it.A upatch tree has two roots of its own. A node's projection root foldsthe digests of the operations that chained on that node, so it differs@@ -38,7 +40,8 @@ theorem register_eq_foldl (H : D → D → D) (init : D) (events : List D) :| nil => rfl| cons e es ih => simp [register, ih]-/-- Equal registers come from equal event sequences. -/+/-- Equal registers come from equal event sequences, for an idealized+`H`: injective on every pair, which no hash onto a fixed width is. -/theorem register_injective (H : D → D → D) (init : D)(hH : ∀ a b c d, H a b = H c d → a = c ∧ b = d)(hinit : ∀ a b, H a b ≠ init) :@@ -111,7 +114,8 @@ theorem map_injective_on {α β : Type} (f : α → β) :(fun x hx y hy => hf x (by simp [hx]) y (by simp [hy])) h.2]/-- Equal registers come from the same tagged events, in the same order:-an event can be neither left out, added, swapped for another nor moved. -/+an event can be neither left out, added, swapped for another nor moved.+For an idealized `H`, as `register_injective`. -/theorem register_tagged_injective (H : D → D → D) (init : D)(encode : K → P → D)(hH : ∀ a b c d, H a b = H c d → a = c ∧ b = d)diff --git a/testing/proofs/lean4/Shirudo/ConfigActivation.lean b/testing/proofs/lean4/Shirudo/ConfigActivation.leanindex 545153ff..f2fd7d15 100644--- a/testing/proofs/lean4/Shirudo/ConfigActivation.lean+++ b/testing/proofs/lean4/Shirudo/ConfigActivation.lean@@ -76,9 +76,11 @@ commands run one at a time; a rename of `state` is atomic and survives acrash once made; a crash in an append leaves a prefix of the line; onlyshirudo writes the journal and the config mount during a boot; a PCRchanges only by extension and resets only at a reboot or a TPM Restart;-two PCR values are equal when their extensions are (`pcr_value_eq_iff`-from `Shirudo.Chain`'s assumptions on the hash); and, for the theorems-over `shirudo`, the calm TPM.+the model compares PCRs as their lists of extensions, which+`pcr_value_eq_iff` justifies for the idealized hash of+`Shirudo.Chain.register_injective` and SHA-256 meets unless it collides+among the values compared; and, for the theorems over `shirudo`, the+calm TPM.The variants `retry` and `recover` each add one step of code shirudodoes not have, and `retry_extends_twice` and `recover_admits_within_boot`@@ -635,9 +637,11 @@ theorem extendAt_suffix (pcr : Nat → List D) (i j : Nat) (d : D) (x : List D)· exact ⟨xs, by simp [extendAt, hj, hx]⟩/-- The C compares PCR values, which `Shirudo.Chain.register` gives of the-model's lists of extensions; under `Shirudo.Chain`'s assumptions on the-hash two values are equal exactly when the lists are, so comparing lists-is comparing values. -/+model's lists of extensions; for a hash injective on every pair, as+`Shirudo.Chain.register_injective` takes it, two values are equal exactly+when the lists are, so comparing lists is comparing values. No hash onto+32 bytes is that; SHA-256 is unless it collides among the values the C+compares. -/theorem pcr_value_eq_iff {H : D → D → D} {init : D}(hH : ∀ a b c d, H a b = H c d → a = c ∧ b = d)(hinit : ∀ a b, H a b ≠ init) (l1 l2 : List D) :