eBPF-based security platform
proofs: say what the UpatchLoad theorems leave out
Daniel Borkmannd5c45b5f33ee
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex ffa046c2..8df6ce1f 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -1207,25 +1207,33 @@ the model follows the C.boot's records hold, and every archive file shirudo wrote is onrecord; ``loaded_once``: no name holds two links;``recorded_runs``: every name the records hold is pinned with one- link of that payload; ``commands_need_init``: every command runs- in a boot whose init record is on the log;- ``init_restores_exactly``: ``init`` loads exactly the labeled- archive files whose last record is a load of that payload, and the- new boot's records hold exactly those; ``log_sublist_register``,- ``register_length``, ``register_eq_log_iff``, ``replay_differs``:- this boot's records are a sublist of the register's events, equal- once the lock is free unless an append was lost, and a difference- shows in the replay; dropping the lock, the undo pass, its refusal,+ link of that payload; ``commands_need_init``: with enforcement+ active, every command runs in a boot whose init record is on the+ log; ``init_restores_exactly``: an ``init`` whose every restore+ succeeds loads exactly the labeled archive files, of those the+ boot's revocations left, whose last record is a load of that+ payload, and the new boot's records hold exactly those;+ ``log_sublist_register``, ``register_length``,+ ``register_eq_log_iff``, ``replay_differs``: this boot's upatch+ records are a sublist of the register's upatch events, equal once+ the lock is free unless an append was lost, and a difference shows+ in the replay; dropping the lock, the undo pass, its refusal,the gate, the undo of a failed payload xattr, the lock across thepurge or the restore's filter breaks the matching theorem- The lock excludes and a kill releases it; a kill keeps pins andfiles; pin directory removals, archive renames and appends arewhole; a reboot clears pins and register and ``init`` runs as one- step; root changes only unlabeled archive files and brings files- back; the hash of ``Shirudo.Chain`` for ``replay_differs``, and+ step; no TPM Restart without a reboot, as hibernation is refused+ (A9 of :doc:`/security/threat-model`); root changes only unlabeled+ archive files and brings files back. For+ ``replay_differs`` the idealized hash of ``register_injective``;for the undo pass, which reads the set only when this boot's- records fold to the register's value, taken as the records being- the register's events+ records fold to the register's value, those records taken as the+ register's events. Left out: the boot in which enforcement never+ came up, where ``image_enter()`` admits commands without an init+ record; the revocation purge ``init`` runs before the restore; a+ restore that fails, which is ``rebootFail``; key revocations and+ tree operations, which extend the same register- CBMC, ``measured-fold-model``, for ``measured_event()`` and``measured_holds()`` up to six records; review for the rest* - ``Shirudo.TreeSync``, ``cmd_bpm_tree_sync()`` anddiff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rstindex a8a043cb..e28bf619 100644--- a/Documentation/internals/measurement-register.rst+++ b/Documentation/internals/measurement-register.rst@@ -389,13 +389,17 @@ purges, kills, failed steps, reboots and root's changes to unlabeledarchive files: once a command's undo pass is done every pin directoryholds one link of the payload this boot's records hold, no name everholds two links, every name the records hold runs with that payload,-this boot's records are the register's events in order but for appends-that failed after their extension, and ``init`` restores exactly the-archives whose last record is their load. The model takes the lock to-exclude and ``init`` to run as one step, which the gate that refuses-every command until ``init`` completes justifies. CBMC shows that-``measured_event()`` and ``measured_holds()`` fold the records as the-model does. The proofs are in :doc:`/contribute/testing/proof-coverage`.+this boot's upatch records are the register's upatch events in order+but for appends that failed after their extension, and an ``init`` whose+every restore succeeds restores exactly the archives, of those its+config's revocations left, whose last record is their load. The model+takes the lock to exclude and ``init`` to run as one step, which the+gate that refuses every command until ``init`` completes justifies. It+leaves out the boot in which enforcement never came up, where the gate+admits commands and their undo pass refuses for want of an ``init``+record. CBMC shows that ``measured_event()`` and ``measured_holds()``+fold the records as the model does. The proofs are in+:doc:`/contribute/testing/proof-coverage`.Evidence--------diff --git a/testing/proofs/lean4/Shirudo/UpatchLoad.lean b/testing/proofs/lean4/Shirudo/UpatchLoad.leanindex b10d3b08..4aa97441 100644--- a/testing/proofs/lean4/Shirudo/UpatchLoad.lean+++ b/testing/proofs/lean4/Shirudo/UpatchLoad.lean@@ -7,9 +7,10 @@ import Shirudo.ChainThe upatch load and unload protocol of builtin-upatch.c and the bootrestore of builtin-init.c, against crashes, concurrent commands and root.-`image_enter()` admits an upatch command only once this boot's config-activation is complete, which `image_boot_complete()` does after `init`-restored the archive and wrote its record. A load (`upatch_load()`, which+With enforcement active, `image_enter()` admits an upatch command only+once this boot's config activation is complete, which+`image_boot_complete()` does after `init` restored the archive and wrote+its record. A load (`upatch_load()`, which`upatch load` and a package install run) takes the register lock(`eventlog_lock()`) and runs the undo pass(`undo_unmeasured()`). The pass folds this boot's records into the@@ -35,6 +36,7 @@ detaches and removes the archive. Its signer check, which leaves in placean archive another key signed, changes nothing and is left out: themodel's purge takes what it finds. After a reboot the pins are gone and`init` restores every labeled archive file the whole log's fold holds+and the revocations of the config it activates left(`boot_restore()`, `measured_set_log()`, `measured_holds()`), binds theregister with one init event and appends its record, which carries therestored set.@@ -63,22 +65,39 @@ every move. The assumptions, each a step or the absence of one:record. The gate is why: no upatch command runs in a boot before an`init` run completed, a run after one that stopped refuses at`image_boot()`, and a run after one that completed changes nothing the- model keeps.+ model keeps. The model leaves out the boot in which enforcement never+ came up, which R6 leaves unprotected: `image_enter()` admits commands+ there without a config, and their undo pass refuses at+ `measured_set_boot()`, which finds no register or no init record of it.+- No TPM Restart comes without a reboot, as no hibernation does (A9):+ one clears the register and keeps the pins, a state the model has no+ step to, in which every later command refuses at `chain_live()`.+- The archive `init` restores from is the one the revocations of the+ config it activates left: `image_boot()` runs `purge_signed_by()`+ before `boot_restore()`, with no record. `init_restores_exactly` holds+ of that archive, and only of a run whose every restore succeeds; one+ that fails is `rebootFail`.- Root starts and kills commands at will, adds, replaces and deletesunlabeled archive files and brings back a file of any content under afree name. The seal stops every other change to the archive, theeventlog and the private bpffs: root cannot write, rename onto orunlink a labeled file, nor touch a pin.-- The register's hash and the event encoding are collision resistant,- as `Shirudo.Chain` assumes, for `replay_differs` and for the undo- pass's check of the records against the register, which the step- takes as their being the register's events.+- The register's hash and the event encoding are injective, as+ `Shirudo.Chain.register_injective` takes them, an idealized hash, for+ `replay_differs`. The undo pass's check of the records against the+ register the step takes as their being the register's events, which+ `Shirudo.Events.verify_sound` and `verify_events` show for SHA-256+ collision free on the strings hashed.+- The register and `lost` are of upatch events only. A key revocation+ and a tree operation extend the same register under the same lock; one+ whose append is lost after its extend makes the C refuse every later+ load and unload (`EBADMSG`), which the model's `lost` does not count.For every sequence of steps from a fresh install, in the C's protocol(`C`):-- `commands_need_init`: every command runs in a boot whose init record- is on the log.+- `commands_need_init`: with enforcement active, every command runs in+ a boot whose init record is on the log.- `undo_pass_sound`: once an upatch command's undo pass is done, everypin directory holds one link, of the payload its xattr names and thisboot's measured set holds, and every labeled archive file shirudo wrote@@ -86,10 +105,11 @@ For every sequence of steps from a fresh install, in the C's protocol- `loaded_once`: no name ever holds two links.- `recorded_runs`: every name this boot's records hold is pinned with onelink of the payload they hold, under the xattr that names it.-- `init_restores_exactly`: after a reboot whose `init` completes, the- upatches loaded are exactly the labeled archive files whose last record- in the log is a load of that name and payload, each once with its- xattr, and the new boot's measured set is exactly what was loaded.+- `init_restores_exactly`: after a reboot whose `init` completes with+ every restore, the upatches loaded are exactly the labeled archive+ files, of those the boot's revocations left, whose last record in the+ log is a load of that name and payload, each once with its xattr, and+ the new boot's measured set is exactly what was loaded.- `log_sublist_register`: this boot's records are always a sublist of theregister's events, in the same order. `register_length` and`register_eq_log_iff`: once the lock is free, the register holds them@@ -2255,8 +2275,9 @@ theorem reach_inv {s : State Name Payload} (h : Reach C s) : Inv s := by| init => exact inv_s0| step _ hs ih => exact inv_step ih hs-/-- `image_enter()` admits upatch commands only in a boot whose init-record is on the log. -/+/-- With enforcement active, `image_enter()` admits upatch commands only+in a boot whose init record is on the log. The boot in which enforcement+never came up, where it admits them without one, is not modelled. -/theorem commands_need_init {s : State Name Payload} (h : Reach C s) {i : Nat}{c : Proc Name Payload} (hi : s.procs i = some c) : hasInit s = true :=(reach_inv h).gate i c hi@@ -2290,10 +2311,12 @@ theorem recorded_runs {s : State Name Payload} (h : Reach C s) :∀ n p, fold (bootEvs s) n = some p → s.pins n = some ⟨[p], some p⟩ :=(reach_inv h).wf.2.1-/-- After a reboot whose `init` completes, the loaded upatches are-exactly the labeled archive files whose last record in the log is a load-of that name with that payload, each loaded once with its xattr, and the-new boot's measured set is exactly what was loaded. -/+/-- After a reboot whose `init` completes with every restore, the loaded+upatches are exactly the labeled archive files whose last record in the+log is a load of that name with that payload, each loaded once with its+xattr, and the new boot's measured set is exactly what was loaded. The+archive is the one the boot's revocations left, which the model leaves+out. -/theorem init_restores_exactly {s : State Name Payload} (h : Reach C s){ks : List Name}(hks : ∀ k, s.arch k ≠ none → k ∈ ks) {pins : Pins Name Payload}@@ -2355,7 +2378,9 @@ theorem log_sublist_register {s : State Name Payload} (h : Reach C s) :/-- Once the lock is released, the register holds this boot's records and`lost` more: the events whose append failed, whose extend failed after the-TPM took it, or whose process was killed between the two. -/+TPM took it, or whose process was killed between the two. The register+here is its upatch events; key revocations and tree operations are left+out. -/theorem register_length {s : State Name Payload} (h : Reach C s)(hfree : s.lock = none) :s.reg.length = (bootEvs s).length + s.lost := by@@ -2377,9 +2402,10 @@ theorem register_eq_log_iff {s : State Name Payload} (h : Reach C s)rw [h0, Nat.add_zero] at hlenexact ((log_sublist_register h).eq_of_length hlen.symm).symm-/-- A disagreement is always detectable: with the register's hash and-the event encoding collision resistant as `Shirudo.Chain` assumes, the-replay of this boot's records differs from the register. -/+/-- A disagreement is always detectable: for a register's hash and an+event encoding injective on everything, as the idealized hash of+`Shirudo.Chain.register_injective`, the replay of this boot's records+differs from the register. -/theorem replay_differs {D : Type} (H : D → D → D) (z : D)(enc : Ev Name Payload → D)(hH : ∀ a b c d, H a b = H c d → a = c ∧ b = d) (hz : ∀ a b, H a b ≠ z)