Skip to content

eBPF-based security platform

keys: support signing key rotation

KP Singh72a702290c39
diff --git a/Documentation/concepts/glossary.rst b/Documentation/concepts/glossary.rst
index 9a762a2b..550a03ec 100644
--- a/Documentation/concepts/glossary.rst
+++ b/Documentation/concepts/glossary.rst
@@ -318,7 +318,7 @@ it.
runtime image
The dm-verity image, mounted read-only at ``/run/shirudo/runtime``,
that carries the ``shirudo`` executable, the initial BPF certificate
- ``keys/cert.der``, the config verification certificate and the
+ ``keys/cert.der``, the config verification certificates and the
bootstrap settings. The UKI's initrd names its root hash, so the
measured boot covers it. Every executable on it gains runtime
authority when it runs. See :doc:`/internals/config-images`.
diff --git a/Documentation/concepts/upatches-and-packages.rst b/Documentation/concepts/upatches-and-packages.rst
index ade555bc..8c635a20 100644
--- a/Documentation/concepts/upatches-and-packages.rst
+++ b/Documentation/concepts/upatches-and-packages.rst
@@ -176,8 +176,8 @@ the tree publication, as a JSON document with a detached CMS signature.
Each generation names the one it replaces.
A target subscribes to a tree through its config image. ``shirudo bpm
-tree sync`` verifies the publication against the runtime image's
-certificate, evaluates each new operation's selector on the target, and
+tree sync`` verifies the publication against the active config's non-revoked BPF
+signer set, evaluates each new operation's selector on the target, and
applies the matching operations in sequence order. Each applied operation
loads or unloads the upatch and is then measured as a tree operation
event. An operation whose selector does not match is passed over for good:
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 01b6d170..3df5317f 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -204,7 +204,8 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
- Every state, pending record, tree eventlog replay and record of the
pending operation, publications of 0 to 2 operations that
``tree_parse()`` lets through, every selector answer and every
- failure below sync; strings of one byte
+ failure below sync, including loading and checking the active signing
+ set; strings of one byte
- The writes of the Lean model ``Shirudo.TreeSync``, in its order,
none after a failure, all of them when nothing fails
* - ``bpm-upatch-member``
@@ -469,9 +470,9 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
- ``bootstrap_parse()`` with ``read_text_line()``
- One settings line of 0 to 8 bytes, every earlier state, failed
reads and allocations
- - A certificate under the runtime directory; a PCR only one the
- config accepts; nothing changes the runtime outside the initial
- settings
+ - A bounded set of certificates under the runtime directory; a PCR
+ only one the config accepts; nothing changes the runtime outside
+ the initial settings
* - ``image-path``
- ``image_path_valid()``
- Up to 8 bytes
diff --git a/Documentation/images/operate-key-trust.svg b/Documentation/images/operate-key-trust.svg
index 0062fe32..6dd54da7 100644
--- a/Documentation/images/operate-key-trust.svg
+++ b/Documentation/images/operate-key-trust.svg
@@ -1,5 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 350" width="760" height="350" font-family="sans-serif" role="img" aria-labelledby="t">
- <title id="t">Init builds the .bpf keyring from the runtime image's primary certificate and the config image's vouched certificates minus its revocations, and the .dm-verity keyring from the runtime image's config certificate; tree publications verify against the primary alone and package indexes against their repository certificates</title>
+ <title id="t">Init builds the .bpf keyring from the runtime image's primary certificate and the config image's vouched certificates minus its revocations, and the .dm-verity keyring from the runtime image's config certificates; tree publications verify against the active non-revoked BPF set and package indexes against their repository certificates</title>
<style>@media (prefers-color-scheme: dark) { [fill="#5d6675"] { fill: #b4bcc7; } }</style>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
@@ -29,7 +29,7 @@
<text x="120" y="114">keys/cert.der</text>
<text x="120" y="130">runtime primary BPF certificate</text>
<text x="120" y="172">etc/shirudo/config-cert.der</text>
- <text x="120" y="188">config verification certificate</text>
+ <text x="120" y="188">config verification certificates</text>
<text x="380" y="64" font-size="13">Config image</text>
<text x="380" y="80">signed, checked against .dm-verity</text>
<text x="380" y="114">keys/trusted/&lt;name&gt;.der, .vouch</text>
@@ -45,11 +45,11 @@
<text x="640" y="151">minus revoked, at most 16</text>
<text x="640" y="173">checks signed loaders</text>
<text x="640" y="217" font-size="13">.dm-verity</text>
- <text x="640" y="235">the config certificate</text>
+ <text x="640" y="235">the config certificates</text>
<text x="640" y="251">checks config images</text>
<text x="509" y="190">removes</text>
</g>
- <text x="10" y="320">Tree publications verify against the runtime primary alone, whatever the config vouches for or revokes.</text>
+ <text x="10" y="320">Tree publications verify against the active BPF signer set, excluding revoked certificates.</text>
<text x="10" y="338">Package indexes verify against the certificate their repository definition names.</text>
</g>
</svg>
diff --git a/Documentation/internals/architecture.rst b/Documentation/internals/architecture.rst
index f4a91704..620f12c6 100644
--- a/Documentation/internals/architecture.rst
+++ b/Documentation/internals/architecture.rst
@@ -102,7 +102,7 @@ Runtime image
Mounted at ``/run/shirudo/runtime`` with ``ro,nodev,nosuid``. It holds
the target binary, its bootstrap ``etc/shirudo/shirudo.conf``, the
initial BPF certificate ``keys/cert.der`` and the config verification
- certificate. The UKI names its exact root hash.
+ certificates. The UKI names its exact root hash.
Config image
Mounted at ``/run/shirudo/config`` with ``ro,nodev,nosuid,noexec``. It
@@ -152,7 +152,7 @@ capability or an executable path.
The keyrings tie the operator to the target. ``init`` enrolls the
initial certificate and the vouched certificates of the selected config
-in ``.bpf``, the config verification certificate in ``.dm-verity``, and
+in ``.bpf``, the config verification certificates in ``.dm-verity``, and
seals both. The kernel verifies every upatch loader against ``.bpf`` and
every config root against its dm-verity trust path. The operator never
touches either keyring.
diff --git a/Documentation/internals/boot-flow.rst b/Documentation/internals/boot-flow.rst
index 027e30a3..4cdd3228 100644
--- a/Documentation/internals/boot-flow.rst
+++ b/Documentation/internals/boot-flow.rst
@@ -64,14 +64,16 @@ the switch to the root file system. It needs
``runtime.root_hash``, read the whole mapping, mount it and read the
runtime's bootstrap settings: ``config.image``,
``config.verification_key`` and ``config.pcr``.
-#. Enroll the config verification certificate in the ``.dm-verity``
- keyring and seal it; the keyring must then hold that certificate
- alone.
+#. Enroll every config verification certificate in ``.dm-verity``
+ and seal it. The keyring must hold exactly the configured set, whose
+ serials are frozen and protected by the key permission hook.
#. Open the TPM and the activation journal under
``/var/lib/shirudo/config-update``, and select the config: the one
- the activation record names, or ``config.image`` on a first boot. Map
- it, which makes the kernel verify its root signature, read it and
- validate its contents.
+ the activation record names, or ``config.image`` on a first boot.
+ On a later TPM boot, an eligible ``next-boot`` record selects its
+ candidate instead. Verify its signature against the runtime's config
+ certificates, map it through the kernel's signature check, read it
+ completely and validate its contents.
#. Build the BPF trust set from the runtime's ``keys/cert.der`` and the
config's vouched certificates, less its revocations, with the
runtime certificate always included. Enroll the set in the ``.bpf``
@@ -101,7 +103,8 @@ the switch to the root file system. It needs
covers the trust set, the restored set and the tree root, extend
PCR 9 with the anchor, and write the record to
``/run/shirudo/eventlog.pending``.
-#. Mark the config selection complete.
+#. Mark the config selection complete and remove its next-boot record,
+ if one was staged.
#. Detach the ``/var/lib/shirudo`` bind.
The keyrings are sealed before any guard attaches, by the initrd's
diff --git a/Documentation/internals/config-images.rst b/Documentation/internals/config-images.rst
index 759370dd..1de520ff 100644
--- a/Documentation/internals/config-images.rst
+++ b/Documentation/internals/config-images.rst
@@ -74,7 +74,7 @@ other refuses.
- ``tpm.tcti``, ``tpm.owner_auth``, and the ``config.*`` keys
* - ``etc/shirudo/shirudo.conf`` on the runtime image
- ``config.image``, the initial config prefix;
- ``config.verification_key``, a certificate path under
+ ``config.verification_key``, one or more certificate paths under
``/run/shirudo/runtime/``; ``config.pcr``, a PCR from 0 to 15
other than 9 and 11
- ``tpm.tcti``, ``tpm.owner_auth``, ``tls.classical_hosts``. Any
@@ -156,13 +156,23 @@ the platform keyring when
``CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING`` is set, and the
``.dm-verity`` keyring last, once it is sealed and holds a key.
-``init`` in the initrd enrolls the certificate that
-``config.verification_key`` names in ``.dm-verity`` and seals the
-keyring, which the kernel leaves open only when booted with
-``dm_verity.keyring_unsealed=1``. The keyring must then hold that
-certificate alone, and ``lsm/key_permission`` keeps root from unlinking
-it. The ``.bpf`` keyring is not involved: a valid config signature never
-authorizes BPF, and a BPF signature never authorizes a config.
+The runtime bootstrap lists the allowed config certificates through
+repeated ``config.verification_key`` entries, at most 16. The target
+reads them from the authenticated runtime device, requires ML-DSA-87 and
+rejects duplicate public keys. Before creating any config mapping,
+including the temporary full-read verification mapping, it verifies the
+CMS root signature against this set. A certificate trusted only by
+another kernel keyring cannot authorize a Shirudo config.
+
+``init`` enrolls all these certificates in ``.dm-verity`` and seals it,
+which the kernel leaves open only with
+``dm_verity.keyring_unsealed=1``. It verifies that the keyring holds
+exactly that set and freezes every serial in the identity map.
+``lsm/key_permission`` protects the ring and its certificates.
+
+The ``.bpf`` keyring is separate. A valid config signature does not
+authorize unsigned BPF: every loader still needs a signature under an
+enrolled BPF signing key.
Config contents
---------------
@@ -220,6 +230,29 @@ At boot, ``init`` runs the same sequence as a boot event for the selected
config, but completes it only at the end of ``init``, after the restore
and the register binding. :doc:`boot-flow` gives the boot order.
+Next-boot selection
+-------------------
+
+``shirudo image stage <prefix>`` verifies and caches a config without
+activating it. Unlike a live update, it allows new vouched BPF signers:
+init can enroll them during the next planned boot, before sealing
+``.bpf``. The command leaves the active config mount, keyrings, PCR and register
+unchanged.
+
+The sealed ``next-boot`` file uses the same selection record format as
+``state``. Its target is the candidate and its sequence and TPM reset and
+restart counts identify the completed activation it was staged from.
+Init selects it only in a later TPM boot with that parent still selected.
+It rechecks the exact root, signature, image contents and certificate
+vouches before enrollment. The normal boot event measures its activation.
+
+A live update that activates a different root invalidates the stage.
+Updating to the already active root preserves it. A stale stage is ignored
+with a warning. A valid stage stays on disk until full init succeeds,
+including upatch restore and register binding. An interrupted init uses
+the normal pending-activation recovery rules. Staging again replaces the
+record; ``image stage --cancel`` removes it. Neither operation reboots.
+
The journal lives in ``/var/lib/shirudo/config-update``: ``state`` holds
the current selection and whether it is pending, ``events`` the config
log, and ``lock`` the lock every target command holds while it runs,
@@ -258,7 +291,9 @@ and never after an interruption, a pending or drifted state refuses
every command but ``status`` and ``image status`` until the TPM boot
changes, and after a reboot an uninterrupted ``init`` records the boot
event and admits commands again. The model takes a TPM Restart or Resume
-to come only between commands. CBMC shows that ``event_follows()``
+to come only between commands. These proofs cover activation after a
+target is selected; they do not model next-boot selection authorization.
+The staging tests exercise its parent and TPM boot checks. CBMC shows that ``event_follows()``
accepts exactly the records the model lets follow. The proofs are in
:doc:`/contribute/testing/proof-coverage`.
@@ -280,6 +315,7 @@ What can change without a reboot
* - Adding a BPF certificate
- Not live. The ``.bpf`` keyring is sealed, so activation refuses a
candidate whose trust set holds a certificate the keyring lacks.
+ ``image stage`` selects such a candidate for the next boot.
* - The config verification certificate, the config PCR, the TPM
settings, ``tls.classical_hosts``, the initial BPF certificate
- Not live. They are on the runtime image, which only a new UKI and
@@ -287,13 +323,15 @@ What can change without a reboot
* - The shirudo binary
- Not live, for the same reason.
-Two boot-time rules bear on the changes that need a reboot. ``init``
+Two boot-time rules bear on key rotation. ``init``
selects the config that the journal names, not ``config.image``, once a
-selection exists. And it enrolls the config verification certificate of
-the runtime image before it maps that config. A reboot therefore does not
-pick up a config that was never activated, and a runtime image with
-another config verification certificate needs a selected config that
-certificate verifies. :doc:`/operate/maintain/keys` covers key changes.
+selection exists. A valid next-boot selection overrides that journal target on a later
+TPM boot. Init enrolls the config verification certificates from the
+runtime image before mapping the selected config. A replacement runtime
+must therefore include a certificate that verifies that selection.
+Config-key rotation uses a runtime with both old and new certificates,
+then a config signed by the new key, then a runtime with only the new
+certificate. :doc:`/operate/maintain/keys` covers key changes.
Limits
------
@@ -301,10 +339,6 @@ Limits
These are properties of the design as implemented.
:doc:`/security/threat-model` gives their consequences.
-- Every key the kernel trusts for dm-verity signatures verifies a config:
- the built-in trusted keys, and the secondary and platform keyrings when
- the kernel is built to use them. shirudo does not check the signer of a
- config in userspace.
- Nothing prevents rollback. Any config ever signed by an accepted key
can be activated again.
- Any process that can send ``TPM2_PCR_Extend`` can extend the config
diff --git a/Documentation/internals/kernel-interfaces.rst b/Documentation/internals/kernel-interfaces.rst
index 9b3a72d0..addbbd14 100644
--- a/Documentation/internals/kernel-interfaces.rst
+++ b/Documentation/internals/kernel-interfaces.rst
@@ -337,7 +337,7 @@ Keyrings
``add_key(..., KEY_SPEC_DM_VERITY_KEYRING)``,
``keyctl(KEYCTL_RESTRICT_KEYRING, KEY_SPEC_DM_VERITY_KEYRING, ...)``
- The same for ``.dm-verity`` (-10) and the config verification
- certificate.
+ certificates.
* - ``keyctl(KEYCTL_READ, <ring>)``, ``keyctl(KEYCTL_DESCRIBE, <key>)``
- List a keyring and compare it with the expected set.
* - ``keyctl(KEYCTL_UNLINK, <key>, <ring>)``
@@ -490,7 +490,7 @@ Kernel command line
keyring is sealed empty at boot and ``init`` fails.
* - ``dm_verity.keyring_unsealed=1``
- The kernel leaves ``.dm-verity`` open for ``init`` to enroll the
- config verification certificate and seal.
+ config verification certificates and seal.
* - ``lsm=`` including ``bpf``
- When ``CONFIG_LSM`` does not include it.
diff --git a/Documentation/operate/deploy/boot-integration.rst b/Documentation/operate/deploy/boot-integration.rst
index 325dfcfc..44df5c92 100644
--- a/Documentation/operate/deploy/boot-integration.rst
+++ b/Documentation/operate/deploy/boot-integration.rst
@@ -153,7 +153,10 @@ Build the runtime image
boot: from then on the activation record selects the config.
``config.verification_key`` must be a path inside the runtime image,
and ``shirudo-gen-runtime`` puts the config certificate at the path
- shown. ``config.pcr`` is the TPM PCR that records config activations:
+ shown. For config-key overlap, repeat ``--config-cert`` when generating
+ the runtime; it installs numbered certificates and writes all their
+ paths into this bootstrap. See :doc:`/operate/maintain/keys`.
+ ``config.pcr`` is the TPM PCR that records config activations:
0 to 15, except 9 and 11. Choose a PCR that nothing extends after the
initrd has run, because a later extension makes every command but
``status`` refuse until the next reboot. :doc:`/operate/plan/hardening`
diff --git a/Documentation/operate/maintain/keys.rst b/Documentation/operate/maintain/keys.rst
index 7d10d0be..c17f1129 100644
--- a/Documentation/operate/maintain/keys.rst
+++ b/Documentation/operate/maintain/keys.rst
@@ -14,9 +14,10 @@ with a signed config, and some change only with a new runtime image and a
reboot. This page lists the keys, shows what can change when, and walks
through vouching for a signer and revoking one.
-Plan the BPF signers before the first boot. A target that is already
-initialized cannot enroll a BPF signer that its first config did not
-enroll.
+Enroll replacement keys before switching signing to them. BPF signers
+join the sealed keyring at boot; use ``shirudo image stage`` to select a
+config with additional vouched signers for the next planned reboot.
+Config verification certificates come from the runtime image.
Before you begin
----------------
@@ -41,8 +42,8 @@ table lists every key.
:alt: The .bpf keyring holds the runtime image's primary certificate
and the config image's vouched certificates minus its
revocations; the .dm-verity keyring holds the runtime image's
- config certificate. Tree publications verify against the
- primary alone, package indexes against their repository
+ config certificates. Tree publications verify against the active,
+ non-revoked BPF signers; package indexes use their repository
certificate.
Figure 1. The keys a target trusts and the keyrings ``init`` builds
@@ -58,13 +59,13 @@ table lists every key.
* - Runtime primary BPF certificate
- ``keys/cert.der`` in the runtime image, read as
``/run/shirudo/runtime/keys/cert.der``
- - Signed loaders of upatches. It is also the only certificate that
- verifies upatch tree publications, whatever the config revokes or
- vouches for.
+ - Signed loaders of upatches and, while not revoked, upatch tree
+ publications.
* - Vouched BPF certificates
- ``keys/trusted/<name>.der`` with ``keys/trusted/<name>.vouch`` in
the config image
- - Signed loaders of upatches. A certificate joins the set when its
+ - Signed loaders of upatches and tree publications. A certificate
+ joins the set when its
vouch verifies under a certificate already in the set, starting
from the runtime primary. The set holds at most 16 certificates.
* - Revocation records
@@ -73,16 +74,17 @@ table lists every key.
set.
* - Config verification certificate
- ``etc/shirudo/config-cert.der`` in the runtime image, named by
- ``config.verification_key``
- - Config images. Init enrolls it in the kernel's ``.dm-verity``
- keyring and seals that keyring around it.
+ the repeatable ``config.verification_key`` setting
+ - Config images. Init enrolls all listed certificates in the
+ kernel's ``.dm-verity`` keyring before sealing it. The runtime
+ generator numbers additional files ``config-cert-2.der`` and on.
* - Kernel trusted keys
- The kernel's built-in trusted keyring, and the secondary and
platform keyrings when the kernel enables them for dm-verity
- - Config images as well. The kernel checks these keyrings before
- ``.dm-verity``, so their keys, including the kernel build's module
- signing key, can sign a config the target activates.
- :doc:`/operate/plan/hardening` lists the kernel options.
+ - The kernel's dm-verity signature check also consults these rings.
+ Before creating the mapping, shirudo additionally verifies the
+ root signature against the runtime's config certificates, so an
+ unrelated kernel-trusted key does not authorize a config.
* - Repository index certificates
- ``etc/shirudo/bpm/keys/`` in the config image, named by
``key_file`` in ``etc/shirudo/bpm/registries.d/``
@@ -126,10 +128,10 @@ What can change when
by a key in the new set, or the boot restore fails.
* - Vouched BPF certificates
- Enrolled from the initial config.
- - Refused when the config adds a certificate that is not in the
- ``.bpf`` keyring.
- - Not enrolled. The boot selects the config the activation record
- names, and that config passed the live check.
+ - Live activation refuses a certificate that is not in the
+ ``.bpf`` keyring. Stage that config for the next boot instead.
+ - Init verifies a staged config and enrolls its vouched signers
+ before sealing the keyring.
* - Revocation records
- Applied at boot.
- Applied at activation.
@@ -137,9 +139,9 @@ What can change when
* - Config verification certificate
- Set by the runtime image.
- Cannot change it.
- - Init fails at that boot, before enforcement starts: the selected
- config carries the old key's signature, and the sealed
- ``.dm-verity`` keyring holds only the new certificate.
+ - Use a runtime containing both old and new certificates, activate a
+ config signed by the new key, then use a runtime containing only
+ that key. A selected config signed by no listed key is refused.
* - Repository index certificates
- From the initial config.
- Change at activation.
@@ -201,8 +203,8 @@ Check what a target trusts
member by its SPKI fingerprint, with the SHA-256 of its DER and the
member that vouched for it. ``Keyring (.bpf)`` is what the kernel
verifies signed loaders against: the serial init froze, and one key
- per member. ``Keyring (.dm-verity)`` holds the one key the kernel
- verifies config roots with. ``(frozen)`` marks a member ``init``
+ per member. ``Keyring (.dm-verity)`` holds the configured certificates
+ for config roots. ``(frozen)`` marks a member ``init``
recorded; a member marked ``(not frozen)`` is trusted by the kernel
all the same, and ``shirudo status`` reports the target ``tampered``.
@@ -235,8 +237,8 @@ Vouch for a standby signer
A standby signer is a second BPF signing key that the initial config
enrolls, so that you can revoke the primary later and keep signing
-upatches. Tree publications stay with the runtime primary, as `Limits`_
-explains. Do this before the target's first boot with enforcement.
+upatches and tree publications. Include it in the first config or stage
+that config on an existing target and reboot when appropriate.
1. Create the standby key in a directory of its own:
@@ -270,12 +272,37 @@ explains. Do this before the target's first boot with enforcement.
config when a certificate under ``keys/trusted`` has no vouch that
verifies.
-4. Build, sign and place the initial config as
- :doc:`/operate/deploy/boot-integration` describes.
+4. Build and sign the config as
+ :doc:`/operate/deploy/boot-integration` describes. For a new target,
+ use it as the initial config. For an existing target, stage it:
-5. After the first boot, check that ``shirudo keys`` on the target lists
+ .. code-block:: console
+
+ target# shirudo image stage <prefix>
+ target# shirudo image status
+
+ Staging verifies the image and vouches but does not enroll the new
+ signer, activate the config or extend the TPM. The next planned boot
+ selects and verifies it before enrolling keys. Cancel a staged
+ selection with ``shirudo image stage --cancel``.
+
+5. After the planned reboot, check that ``shirudo keys`` on the target lists
the standby signer in the trusted set and the ``.bpf`` keyring.
+Once both signers are enrolled, switch signing to the standby key.
+For the first tree publication signed by it, verify the previous
+publication with the old certificate:
+
+.. code-block:: console
+
+ operator$ shirudo bpm tree append <package> oci://<registry>/<tree> \
+ --keys-dir <standby-keys-dir> --previous-cert <primary-keys-dir>/cert.der
+
+The new publication is signed by the standby key. Later appends use that
+key for both checks and can omit ``--previous-cert``. Targets accept
+either enrolled signer during the overlap. Replace upatches signed by the
+old key before activating a config that revokes it.
+
On a target, ``shirudo keys add`` and ``shirudo bpm key add`` refuse to
change the trusted set, and ``shirudo keys revoke`` always refuses. The
signed config is the only way in.
@@ -369,37 +396,72 @@ certificates only. :doc:`/operate/run/attest` shows how to predict the
register, and ``--event=revoke:<label>=<cert-sha256>`` adds a revocation
made after boot.
+Rotate a config signing key
+----------------------------
+
+Use an overlap period so the selected config remains verifiable while
+signing changes from C to D.
+
+1. Create D on the operator and build a runtime with both certificates:
+
+ .. code-block:: console
+
+ operator$ shirudo genkey --keys-dir <config-D>
+ operator$ shirudo-gen-runtime --binary <target-binary> \
+ --bootstrap-conf runtime.conf --cert <bpf-cert> \
+ --config-cert <config-C>/cert.der \
+ --config-cert <config-D>/cert.der \
+ --keys-dir <config-C> --output runtime-CD
+
+ The repeated option puts both config certificates on the runtime
+ image and lists them in its bootstrap settings. Init enrolls both
+ before sealing ``.dm-verity``.
+
+2. Deploy the runtime and a UKI naming its root hash as
+ :doc:`upgrade` describes, then reboot when appropriate. The selected
+ C-signed config still verifies.
+
+3. Build a config with D and activate it:
+
+ .. code-block:: console
+
+ operator$ shirudo-gen-image --source <config-root> --output config-D \
+ --keys-dir <config-D> --kind config
+ target# shirudo image update <path>/config-D
+
+ Build a fresh image with a new root hash, not just a new signature over
+ an old cached image. The cache keeps the signature already stored for
+ a root. Verify ``shirudo image status`` and ``shirudo keys`` before
+ retiring C.
+
+4. Build and deploy another runtime and UKI with only D's certificate.
+ After the planned reboot the selected D-signed config verifies, and
+ C is no longer in the config keyring.
+
+No target command enrolls a config certificate or removes one live.
+Signatures by either enrolled key work during the overlap; two
+signatures on one image are not required.
+
Limits
------
-These limits follow from the code as it is. :doc:`/security/threat-model`
-discusses the residual risks.
-
-- A signer that the first config did not enroll cannot be added to an
- initialized target. ``image update`` refuses the config with
- ``image: BPF signer was not enrolled at boot; reboot with the new
- trusted key set required``, and a reboot does not select it either. No
- supported procedure resets the activation record. Enroll standby
- signers at first provisioning.
-- A config signed by a new config verification key cannot be activated
- on an initialized target. Live activation verifies it under the
- current ``.dm-verity`` keyring, and a new runtime image fails at boot
- as the table above shows.
-- Tree publications verify only against the runtime primary
- certificate. Revoking the primary in the config does not stop the
- target from accepting tree publications that the primary signed, and a
- vouched signer cannot sign them. Moving tree publishing to another key
- takes a new runtime image.
-- A vouch carries no time. A vouch made by a key that was later revoked
- still admits the certificate it vouches for. The config signer decides
- which certificates are under ``keys/trusted``, so after a compromise,
- revoke the certificates that only the compromised key vouched for as
- well.
+- A live config activation cannot enroll a BPF key. Stage the config
+ and reboot instead.
+- A config certificate changes only with the authenticated runtime image
+ and a reboot. Removing the old key before changing the selected
+ config makes init refuse that config.
+- Revoking a BPF signer purges upatches it signed. Plan their replacement
+ before retiring the signer.
+- Vouches are historical authorizations. Revoking A does not
+ automatically revoke B merely because A vouched for it. After a
+ compromise, the config signer must explicitly revoke any certificate
+ whose authorization is no longer trusted.
- A certificate's validity dates do not end its trust. shirudo verifies
vouches and index and tree signatures without checking them.
-- Any key the kernel trusts for dm-verity signs a valid config. A config
- can change repositories, the tree subscription, export destinations and
- revocations.
+- Older signed configs can still be selected. Local rollback prevention
+ is not provided; a verifier must check the approved config root and
+ boot measurements. See :doc:`/security/threat-model`.
+
Next steps
----------
diff --git a/Documentation/operate/plan/interoperability.rst b/Documentation/operate/plan/interoperability.rst
index 995b6190..4ade7084 100644
--- a/Documentation/operate/plan/interoperability.rst
+++ b/Documentation/operate/plan/interoperability.rst
@@ -245,8 +245,8 @@ systemd-keyring-setup
:Symptom: ``init`` fails in the initrd. It stops at the ``.dm-verity``
keyring with one of
``initrd boot keys: add config verification certificate: <error>``,
- ``initrd boot keys: check dm-verity keyring holds only the config
- certificate: Key was rejected by service`` or, when the tool enrolled
+ ``initrd boot keys: check dm-verity verification keys: Key was rejected
+ by service`` or, when the tool enrolled
nothing, ``initrd boot keys: dm-verity keyring sealed empty at boot;
boot with dm_verity.keyring_unsealed=1: Required key not available``,
which names the boot parameter even when it is set. ``init: BPF
diff --git a/Documentation/operate/run/deliver-packages.rst b/Documentation/operate/run/deliver-packages.rst
index e46a4adf..8e123745 100644
--- a/Documentation/operate/run/deliver-packages.rst
+++ b/Documentation/operate/run/deliver-packages.rst
@@ -194,7 +194,7 @@ while it runs.
command writes ``<prefix>.img``, ``<prefix>.verity``,
``<prefix>.roothash`` and ``<prefix>.p7s`` and refuses to replace an
existing file. ``<config-keys-dir>`` holds the key whose certificate
- the runtime image names in ``config.verification_key``. The path is
+ the runtime image lists in a ``config.verification_key`` entry. The path is
the operator package's. From a checkout, run
:src:`tools/gen-image/shirudo-gen-image` and add ``--builder`` with the
path of ``shirudo-build``.
diff --git a/Documentation/reference/cheat-sheet.rst b/Documentation/reference/cheat-sheet.rst
index 7e8200e7..67748a16 100644
--- a/Documentation/reference/cheat-sheet.rst
+++ b/Documentation/reference/cheat-sheet.rst
@@ -348,6 +348,20 @@ Activate a new config image on a target with :doc:`image update
target# shirudo image update https://config.example/shirudo/config
+Select a config containing new vouched BPF signers for the next planned
+reboot with :doc:`image stage <cli/image>`. It leaves the active config,
+keyrings and measurements unchanged:
+
+.. code-block:: console
+
+ target# shirudo image stage https://config.example/shirudo/with-new-signer
+
+Cancel that selection before reboot:
+
+.. code-block:: console
+
+ target# shirudo image stage --cancel
+
Show the config activation with :doc:`image status <cli/image>`. It exits
with 1 while the activation is pending:
diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rst
index 2f04b205..d45a686d 100644
--- a/Documentation/reference/cli/bpm.rst
+++ b/Documentation/reference/cli/bpm.rst
@@ -211,6 +211,11 @@ package as the next operations of the signed tree at
* - ``--key``, ``--cert``
- from the keys directory
- Signing key and certificate.
+ * - ``--previous-cert``
+ - the signing certificate
+ - Certificate that verifies the existing publication. Use the old
+ certificate when the next publication will be signed by a new key.
+ It does not change the certificate used to sign the new publication.
* - ``--tree-id``
- the existing tree's, else the package name
- Tree ID. It must match the existing tree.
diff --git a/Documentation/reference/cli/gen-tools.rst b/Documentation/reference/cli/gen-tools.rst
index 02279e3d..62134907 100644
--- a/Documentation/reference/cli/gen-tools.rst
+++ b/Documentation/reference/cli/gen-tools.rst
@@ -98,6 +98,7 @@ shirudo-gen-runtime
--output <prefix> --keys-dir <dir>
[--size <mib>] [--builder <helper>]
[--unit-output <file>] [--extra-binary <file>]...
+ [--config-cert <additional-certificate>]...
Builds the runtime image, the image whose root hash the bootstrap
settings pin. It holds:
@@ -106,8 +107,9 @@ settings pin. It holds:
symbols and debug sections, as ``llvm-strip`` writes it
- ``etc/shirudo/shirudo.conf``: ``--bootstrap-conf``
- ``keys/cert.der``: ``--cert``, the initial BPF signing certificate
-- ``etc/shirudo/config-cert.der``: ``--config-cert``, the certificate
- that verifies config images
+- ``etc/shirudo/config-cert.der``: the first ``--config-cert``;
+ additional certificates are ``config-cert-2.der``, ``config-cert-3.der``
+ and on. Any of them may sign a config image
- for a dynamically linked binary, its ELF interpreter and libraries
under their own paths, found with ``ldd``
- each ``--extra-binary`` under ``usr/bin/`` with its libraries
@@ -140,7 +142,10 @@ trusted binaries. Requires ``readelf``, ``ldd`` and ``llvm-strip``.
- The initial BPF signing certificate.
* - ``--config-cert``
- required
- - The config image verification certificate.
+ - The config image verification certificate. Repeatable, at most 16.
+ With several certificates, the generator replaces the bootstrap's
+ ``config.verification_key`` entries with their installed paths.
+ With one certificate it preserves the bootstrap file.
* - ``--output``
- required
- Output prefix.
diff --git a/Documentation/reference/cli/image.rst b/Documentation/reference/cli/image.rst
index 4f10ddd1..6383e1ce 100644
--- a/Documentation/reference/cli/image.rst
+++ b/Documentation/reference/cli/image.rst
@@ -9,10 +9,10 @@ shirudo image
=============
Build and verify signed dm-verity images on the operator host, and
-activate a signed config image on a target.
+activate a signed config image on a target, or select one for its next boot.
Runs on: ``build`` and ``verify`` on the operator host, through the
-``shirudo-build`` helper, without the image gate. ``update`` and
+``shirudo-build`` helper, without the image gate. ``update``, ``stage`` and
``status`` on a target, as root with the runtime binary. Requires: ``veritysetup`` on the
operator host. Changes measured state: ``update`` yes, the others no.
@@ -27,12 +27,14 @@ Usage
[--salt <salt>]
shirudo image verify <prefix> --cert <certificate>
shirudo image update <prefix>
+ shirudo image stage <prefix>
+ shirudo image stage --cancel
shirudo image status [--json]
shirudo image --list-cmds
The subcommand names must be spelled out. ``image`` without a subcommand
prints the usage and exits with 2. ``--list-cmds`` prints
-``build verify update status`` on one line.
+``build verify update stage status`` on one line.
An image is four files that share a prefix: ``<prefix>.img`` (the ext4
file system), ``<prefix>.verity`` (the hash tree), ``<prefix>.roothash``
@@ -79,8 +81,10 @@ is a local path prefix or an ``https://`` URL prefix.
#. It fetches ``<prefix>.roothash``, ``.p7s``, ``.img`` and ``.verity``
into a staging directory under ``/var/lib/shirudo/images``, over HTTPS
with redirects to HTTPS only, or from local regular files.
-#. It checks the signature through the kernel's dm-verity trust path,
- maps the image read-only and reads it completely.
+#. It verifies the root signature against the config certificates in
+ the authenticated runtime image. It also checks the signature through
+ the kernel's dm-verity trust path, maps the image read-only and reads
+ it completely.
#. It links the files to ``/var/lib/shirudo/images/<root-hash>.*``. When
the root hash is the active one, it stops here.
#. It maps and mounts the candidate, validates its settings, and checks
@@ -93,12 +97,39 @@ is a local path prefix or an ``https://`` URL prefix.
leaves the ``.bpf`` keyring, the register receives a ``key_revoke``
event, and every archived upatch the certificate signed is unloaded
and measured. It mounts the image at ``/run/shirudo/config``.
-#. It clears the pending record.
+#. It clears the pending record and any previous next-boot selection.
+ Updating to the already active root is a no-op and preserves that
+ selection.
When ``update`` stops between steps 5 and 7, the activation stays pending.
Every command except ``status`` is then refused until the next reboot.
shirudo does not reboot the target.
+image stage
+-----------
+
+``stage <prefix>`` fetches and verifies a config in the same way as
+``update``, but saves it for the next planned reboot instead of activating
+it. It checks the settings and BPF certificate vouches. It permits a
+vouched signer that the current sealed ``.bpf`` keyring does not yet hold.
+
+The current config must be consistent. The staged selection is stored
+in ``/var/lib/shirudo/config-update/next-boot`` and tied to the current
+activation sequence and TPM boot. Staging does not change the mounted
+config, either keyring, the config PCR or the measurement register.
+
+At the next TPM boot, init verifies that the parent selection is
+unchanged, rechecks the candidate and its signature, and enrolls its BPF
+signers before sealing ``.bpf``. It measures the selected config through
+the normal boot path. The next-boot record is removed only after init
+completes. A re-run of init in the current boot cannot activate it.
+
+``stage --cancel`` removes the next-boot selection without changing the
+active config. Staging again replaces it. Activating a different config
+root through a live update invalidates it. An interruption before the atomic selection is saved
+leaves the previous selection in place. A saved selection whose files
+cannot be authenticated causes init to refuse it.
+
image status
------------
@@ -108,7 +139,8 @@ the activation is pending (``no``, or ``yes, until the next reboot``) and
whether it is consistent with its records (``yes`` or ``no``). With
``--json`` it prints one JSON object with ``root_hash``, ``pcr``,
``sequence``, ``reset_count``, ``restart_count``, ``pending`` and
-``consistent`` instead.
+``consistent`` instead. The text report also prints the next-boot config
+root, or ``none``. JSON adds ``next_boot_root_hash``, a string or ``null``.
Options
-------
@@ -146,6 +178,10 @@ Options
- ``<salt>``, 64 hex characters
- chosen by ``veritysetup``
- ``build``: the dm-verity salt.
+ * - ``--cancel``
+ - none
+ - off
+ - ``stage``: cancel the next-boot selection.
* - ``--json``
- none
- off
@@ -174,8 +210,8 @@ Exit status
activation state on this host``.
* - 2
- No subcommand, an unknown subcommand, a wrong number of arguments
- to ``update`` or ``status``, or ``verify`` arguments in another
- form.
+ to ``update``, ``stage`` or ``status``, or ``verify`` arguments
+ in another form.
* - 127
- ``build``, ``verify``: ``shirudo`` cannot execute the helper.
@@ -190,6 +226,8 @@ Files and environment
``shirudo-gen-verity``
- ``update``: ``/var/lib/shirudo/images``, ``/var/lib/shirudo/config-update``,
``/run/shirudo/config``, the config PCR and the register
+- ``stage``: the image cache and ``config-update/next-boot``; it leaves
+ the active config and measurements unchanged
Examples
--------
@@ -218,6 +256,7 @@ Show the active selection:
target# shirudo image status
Config root hash: 6d5ed552f4487728d1ccec8604ddb44b66b18e3430614c20bb4d284995f99f63
+ Next boot root hash: none
PCR: 14
Sequence: 1
TPM reset count: 1
diff --git a/Documentation/reference/cli/keys.rst b/Documentation/reference/cli/keys.rst
index 0b636a9f..03f803a3 100644
--- a/Documentation/reference/cli/keys.rst
+++ b/Documentation/reference/cli/keys.rst
@@ -61,7 +61,8 @@ directory, so that ``init`` enrolls it at the next boot:
#. It refuses on a host with an active config image, which every
production target has, with ``target: add vouched BPF signers to the
signed config selected for boot and reboot to enroll them``. On such a
- target, add vouched signers to the signed config image instead (see
+ target, add vouched signers to the signed config image, select it
+ with ``shirudo image stage`` and reboot when appropriate (see
:doc:`/operate/maintain/keys`).
#. It requires an ML-DSA-87 certificate and a trusted set under the keys
directory, and refuses a certificate listed under ``<dir>/revoked``.
diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rst
index 5e74c7ba..ee7043cd 100644
--- a/Documentation/reference/files.rst
+++ b/Documentation/reference/files.rst
@@ -189,12 +189,18 @@ the label as foreign. In the initrd, ``init`` binds
- ``init``, ``image update``
- ``0600``
- Config activation record and its event history.
+ * - ``config-update/next-boot``
+ - ``image stage``, ``init``
+ - ``0600``
+ - Candidate config for the next TPM boot and its parent activation
+ sequence and boot counts. Removed on cancellation, successful
+ boot initialization or a live update to a different root.
* - ``images/<root-hash>.img``, ``.verity``, ``.roothash``, ``.p7s``
- - ``image update``
+ - ``image update``, ``image stage``
- ``0600``
- Fetched config images, named by their dm-verity root hash.
* - ``images/incoming-XXXXXX/``
- - ``image update``
+ - ``image update``, ``image stage``
- none
- Staging directory of a fetch.
@@ -263,8 +269,10 @@ to ``/run/shirudo/runtime/``.
* - ``etc/shirudo/shirudo.conf``
- Runtime settings.
* - ``etc/shirudo/config-cert.der``
- - Certificate that verifies config image signatures, named by
- ``config.verification_key``.
+ - First config verification certificate. Additional
+ ``--config-cert`` inputs become ``config-cert-2.der`` and on.
+ The bootstrap's repeated ``config.verification_key`` entries name
+ all allowed certificates.
* - ``keys/cert.der``
- The initial BPF signing certificate.
* - Library paths
diff --git a/Documentation/reference/formats/bpm-formats.rst b/Documentation/reference/formats/bpm-formats.rst
index 683c4f3f..813bf4ee 100644
--- a/Documentation/reference/formats/bpm-formats.rst
+++ b/Documentation/reference/formats/bpm-formats.rst
@@ -62,7 +62,7 @@ What is signed
- None beyond the archive digest.
* - Tree publication document
- Detached CMS signature over the exact document bytes.
- - ``bpm tree sync``, against the runtime image's initial certificate.
+ - ``bpm tree sync``, against the active config's non-revoked BPF signer set.
* - Tree artifact manifest and ``.upatch`` layer
- Not signed. Each signed operation pins them by
``manifest_digest``, ``layer_digest`` and ``payload_sha256``.
@@ -74,7 +74,8 @@ What is signed
The detached signatures use the same CMS profile as the ``.upatch``
signature: DER ``SignedData``, no encapsulated content, no certificates,
ML-DSA-87, signer named by subject key identifier. The verifier checks it
-against the one configured certificate without a validity-time check.
+without a validity-time check: against the repository certificate for
+an index, or any active, enrolled BPF signer for a tree publication.
Names
-----
diff --git a/Documentation/reference/formats/configuration.rst b/Documentation/reference/formats/configuration.rst
index 611d4c4d..5cf84d12 100644
--- a/Documentation/reference/formats/configuration.rst
+++ b/Documentation/reference/formats/configuration.rst
@@ -86,9 +86,11 @@ Bootstrap keys
- Absolute path under ``/run/shirudo/runtime/``
- Allowed
- Required
- - DER certificate enrolled in the ``.dm-verity`` keyring to verify
- config signatures. ``shirudo-gen-runtime`` installs it as
- ``/run/shirudo/runtime/etc/shirudo/config-cert.der``.
+ - Repeatable, at most 16 DER certificates. Init enrolls them in
+ ``.dm-verity``; the target also checks signatures against this
+ exact set before mapping a config. ``shirudo-gen-runtime``
+ installs the first as ``etc/shirudo/config-cert.der`` and further
+ certificates as ``config-cert-2.der`` and on.
* - ``config.pcr``
- Decimal integer, 0 to 15, not 9 or 11
- Allowed
@@ -106,6 +108,10 @@ Bootstrap rules:
- A ``config.*`` or ``runtime.*`` key not in the table is refused with
``EINVAL``. A repeated ``runtime.image`` or ``runtime.root_hash`` is
refused with ``EINVAL``.
+- A repeated ``config.verification_key`` adds another allowed certificate.
+ A repeated path is refused with ``EEXIST`` and more than 16 entries
+ with ``E2BIG``. Runtime loading also rejects duplicate public keys and
+ certificates other than ML-DSA-87.
- A ``config.verification_key`` outside ``/run/shirudo/runtime/`` is
refused with ``EPERM``.
- A path is valid when it is absolute and contains no ``//``, ``/./`` or
@@ -258,7 +264,8 @@ All three files and the host file share one syntax:
- One ``key = value`` per line. Blanks around the key and the value are
removed.
- A line whose first non-blank character is ``#`` is a comment.
-- A later line sets a key again.
+- A later line sets a key again, except the repeatable bootstrap
+ ``config.verification_key``, which adds another certificate.
- A line without ``=`` is ignored, except in a bootstrap file and in the
config image.
@@ -369,7 +376,9 @@ Runtime image
- The initial BPF signing certificate (``--cert``), always in the
trusted set.
* - ``etc/shirudo/config-cert.der``
- - The config verification certificate (``--config-cert``).
+ - The first config verification certificate (``--config-cert``).
+ * - ``etc/shirudo/config-cert-2.der`` and on
+ - Additional config verification certificates (repeat ``--config-cert``).
* - The ELF interpreter and libraries
- Copied at their own paths for a dynamic binary.
diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rst
index 1fc009f9..7171edb6 100644
--- a/Documentation/reference/formats/status-json.rst
+++ b/Documentation/reference/formats/status-json.rst
@@ -110,7 +110,7 @@ determined, as noted.
see `Keyrings`_.
* - ``dm_verity_keyring``
- object
- - The ``.dm-verity`` keyring, the config certificate and its key,
+ - The ``.dm-verity`` keyring, its config certificates and their keys,
see `Keyrings`_.
* - ``signing_key_present``
- boolean
@@ -262,7 +262,7 @@ its details that applies, in the order listed.
- ``the dm-verity keyring holds <n> link(s) init did not freeze``
* -
- ``ALERT``
- - ``the config key init froze is gone from the dm-verity keyring``
+ - ``a config key init froze is gone from the dm-verity keyring``
* -
- ``OK``
- ``bpf serial <serial>, dm-verity serial <serial>, pins match``
@@ -365,7 +365,7 @@ recorded its serial: every key of ``.bpf`` and the config key of
* - ``certs``
- array of object
- The certificates the keyring should hold: the trusted set for
- ``.bpf``, the config certificate the runtime image names for
+ ``.bpf``, the config certificates the runtime image names for
``.dm-verity``. Each is described below.
* - ``other_links``
- array of object
diff --git a/Documentation/security/cryptography.rst b/Documentation/security/cryptography.rst
index 5ce0c89e..e29a0e8c 100644
--- a/Documentation/security/cryptography.rst
+++ b/Documentation/security/cryptography.rst
@@ -92,11 +92,12 @@ verifies:
algorithm. The pre-flight check ``cert_algorithm`` refuses
anything but ML-DSA-87, but in the initrd it reads
``/etc/shirudo/keys``, not that set (threat model U4).
- * - Kernel, config roots
- - Any key, of any supported algorithm, in the keyrings of
- assumption A7 (threat model U2).
+ * - Target, config roots
+ - ML-DSA-87 under one of the runtime bootstrap's config certificates.
+ The target checks this exact set before the kernel's dm-verity
+ signature check (threat model A7).
* - ``shirudo bpm``, indexes and tree publications
- - Whatever algorithm the repository or primary certificate holds
+ - Whatever algorithm the repository certificate or active BPF signer holds
(threat model U4).
* - Vouch check on the target
- Whatever algorithm the vouching certificate holds; the vouched
diff --git a/Documentation/security/security-model.rst b/Documentation/security/security-model.rst
index eabb06e9..ddb45672 100644
--- a/Documentation/security/security-model.rst
+++ b/Documentation/security/security-model.rst
@@ -65,9 +65,8 @@ What shirudo provides
* - Delivered content is authentic
- Indexes, tree publications and configs are signed; the kernel
verifies loaders and config roots.
- - A registry can withhold and replay; any key the kernel trusts for
- dm-verity signs a config.
- - :ref:`T7 <tm-t7>`, :ref:`T11 <tm-t11>`, R8, U2
+ - A registry can withhold and replay signed content.
+ - :ref:`T7 <tm-t7>`, :ref:`T11 <tm-t11>`, R8
Main adversary
--------------
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 167f0eaf..b353dca4 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -202,18 +202,14 @@ without the protection.
- No. shirudo checks neither Secure Boot nor where the initrd came
from. ``init`` warns when PCR 11 holds no phase measurement.
* - A7
- - Only keys trusted to sign shirudo configs can sign a dm-verity
- root. The kernel tries ``.builtin_trusted_keys`` (or the
- secondary keyring with
- ``CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_SECONDARY_KEYRING``), then
- the platform keyring with
- ``CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING``, and
- only then ``.dm-verity``. Both options are off and no built-in
- certificate belongs to a holder not trusted for configs.
+ - Config signing keys are selected by the authenticated runtime
+ bootstrap's repeated ``config.verification_key`` entries.
- A config chooses repository certificates, vouched signers,
revocations and export endpoints.
- - No, see U2. The test ``t5102`` shows a built-in certificate
- signing an accepted config root.
+ - Yes. Before mapping a config, the target verifies its root
+ signature against that exact certificate set. The kernel's
+ dm-verity signature check is required as well. A built-in,
+ secondary or platform key alone cannot authorize a config.
* - A8
- The TPM is reachable only through the kernel driver: no
``i2c-dev`` or ``spidev`` driver that root could bind to the
@@ -485,8 +481,8 @@ ADV-F, holder of a compromised or revoked signing key
programs that write them: the maps are frozen against ``bpf()``
writes, not against programs. An upatch does what its author wrote,
disabling enforcement included. Keys it vouched for stay admitted
- where a config lists them, and if it is the runtime image's primary
- key it signs tree publications that revocation does not reach (U13).
+ where a config lists them (U13). Tree publications require a
+ non-revoked member of the active config's BPF signer set.
A key that signs configs (A7) chooses repositories, vouched signers
and revocations.
@@ -1013,7 +1009,8 @@ repository must match the digests in that index, and the loader in it
is a signed upatch the kernel verifies at load (T1).
``shirudo bpm tree sync`` fetches a signed tree publication and verifies
-it against the runtime image's primary certificate. A publication
+it against the active config's non-revoked BPF signer set. Every
+member must also be present in the sealed ``.bpf`` keyring. A publication
carries a digest for each operation, is the one the target recorded or
has a higher generation, and names its parent, which the target
compares when the generation is exactly one higher. A delete applies
@@ -1028,8 +1025,7 @@ negotiated.
A registry can still withhold or replay signed content (R8). The
environment of the bpm units selects parts of the transport (U3), index
-and tree signatures accept algorithms other than ML-DSA (U4), and
-revocation does not reach tree publications (U13).
+and tree signatures accept algorithms other than ML-DSA (U4).
.. rst-class:: facts
@@ -1047,7 +1043,7 @@ revocation does not reach tree publications (U13).
``Shirudo.JsonString``, ``Shirudo.TreeSync``, ``bpm-tree-follows``,
``bpm-tree-sync-model``, ``bpm-tree-reader``, ``json-string``,
``json-limits``
-:Residual: R8, R9, U3, U4, U13, U15
+:Residual: R8, R9, U3, U4, U15
T8 Quantum-capable adversaries against the trust anchor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1198,7 +1194,7 @@ bootstrap key or TPM setting, and cannot enroll a key while the target
runs: a live activation that would trust a key the ``.bpf`` keyring does
not hold refuses before it changes anything.
-Which keys can sign a config is A7, and U2 is the gap there.
+The configured certificate set determines which keys can sign a config (A7).
.. rst-class:: facts
@@ -1216,7 +1212,7 @@ Which keys can sign a config is A7, and U2 is the gap there.
``t6113``, ``t6127``, ``t6130``, ``t6131``, ``t6132``
:Proofs: ``config-image``, ``image-bootstrap``, ``image-path``,
``dm-names``
-:Residual: R5, R14, U2
+:Residual: R5, R14
T12 Interrupted image activation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1474,7 +1470,7 @@ R13 Revocation reaches a target only through a config
unlinked, the revocation is unmeasured and the purge does not run.
At boot the revoked key is not enrolled, and the init event's
certificate list shows it. A target that has not activated the
- config still trusts the key. Vouches and tree publications are U13.
+ config still trusts the key. Historical vouches are U13.
R14 Configs roll back
shirudo accepts any validly signed config. A live activation cannot
@@ -1588,18 +1584,6 @@ U1 Verification passes without a pinned key or an expected state
and ``--expect-config-root`` with ``--expect-config-pcr``. See
:doc:`/operate/run/attest`.
-U2 Any key the kernel trusts for dm-verity signs a config
- :Affects: Config images (A7).
- :Consequence: A distribution's built-in key, and with the Kconfig
- options of A7 a MOK or UEFI db key, signs a config the target
- accepts, with its repositories, vouched signers, revocations and
- export endpoints. shirudo cannot tell which key verified a root.
- :Status: Confirmed in code and in the kernel; ``t5102`` exercises a
- built-in certificate.
- :Meanwhile: Build both options off, build in no certificate whose
- holder is not trusted to sign configs, and verify with
- ``--expect-config-root``.
-
U3 The environment reaches authorized processes
:Affects: The bpm and export units and any runtime command root
starts.
@@ -1701,16 +1685,16 @@ U11 The boot continues when init fails
prefers a halted boot can add an ``OnFailure=`` drop-in to
``shirudo-initrd.service``; this is not tested.
-U13 Revocation does not reach everything
- :Affects: Tree publications and vouched keys (R13).
- :Consequence: Tree publications verify against the runtime image's
- primary certificate without a revocation check. Vouches carry no
- time, and a revoked key's vouch for another key still admits it
- when a config lists that key.
- :Status: Confirmed in code.
- :Meanwhile: Ship a new runtime image when the primary key is
- compromised, and drop from the config every key the revoked key
- vouched for.
+U13 A revoked signer's historical vouches remain valid
+ :Affects: Vouched keys (R13).
+ :Consequence: Vouches carry no time. A revoked key's vouch for another
+ key still admits it when a config lists that key. This supports
+ planned rotation but does not distinguish a legitimate earlier
+ vouch from one made with a compromised signing key.
+ :Status: Confirmed in code. Rotation preserves this existing rule.
+ :Meanwhile: When a signer is compromised, also remove or revoke every
+ dependent key whose authority should no longer be trusted. A
+ planned overlap is not sufficient compromise recovery by itself.
U14 The operator runs commands from a registry package
:Affects: ``shirudo bpm config update --base-package oci://...``
@@ -1870,8 +1854,7 @@ The verifier:
``--expect-bind-pcr=11=<value>`` (U9, R7, R12)
- Gives an expected state: ``--cert`` with ``--upatch`` or ``--expect``
and ``--tree-root``, or ``--expect-chain`` (U1)
-- Gives ``--expect-config-root`` with ``--expect-config-pcr`` (U2,
- R14)
+- Gives ``--expect-config-root`` with ``--expect-config-pcr`` (R14)
- Gives ``--strict-anchor`` where nothing else measures into PCR 9
after ``init`` (R11), and ``--expect-pcr`` for the firmware, kernel and
initrd values its policy accepts
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 2d417427..f70709e3 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -902,13 +902,15 @@ testing/helper/test-image-config: testing/helper/test-image-config.c \
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(LIBCRYPTO_LIBS) $(LIBSSL_LIBS)
-testing/helper/test-image-cli: testing/helper/test-image-cli.c builtin-bpm.c \
+testing/helper/test-image-cli: testing/helper/test-image-cli.c \
+ testing/helper/image-cli.h builtin-bpm.c \
$(filter-out $(call obj,builtin-bpm.o),$(BUILTIN_OBJS)) \
$(UTIL_OBJS) $(VERSION_OBJ) $(LIBBPF_A)
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(RPATH_LDFLAGS) -o $@ \
- $(filter-out builtin-bpm.c,$^) \
+ $(filter-out builtin-bpm.c testing/helper/image-cli.h,$^) \
-Wl,--wrap=bpm_tree_fetch_publication \
+ -Wl,--wrap=keys_load_image_root -Wl,--wrap=keys_check_image_set \
$(STATIC_LIBS) $(DYNAMIC_LIBS)
testing/helper/test-image-cleanup: testing/helper/test-image-cleanup.c \
@@ -1003,7 +1005,8 @@ FUZZ_CONFIG := util/config.c util/image_config.c
FUZZ_SEAL := util/seal.c $(FUZZ_CONFIG)
FUZZ_OCI := util/bpm_oci.c util/io.c $(FUZZ_SEAL) util/crypto_openssl.c \
util/tls_openssl.c
-FUZZ_PACKAGE := util/bpm_package.c util/bpm_tree.c util/upatch.c $(FUZZ_OCI)
+FUZZ_PACKAGE := util/bpm_package.c util/bpm_tree.c util/upatch.c \
+ util/keys.c $(FUZZ_OCI)
FUZZ_TARGETS := $(patsubst %.c,%,$(wildcard testing/fuzz/fuzz-*.c))
diff --git a/bpf/bpf2.c b/bpf/bpf2.c
index 2550bdb8..d5d25c23 100644
--- a/bpf/bpf2.c
+++ b/bpf/bpf2.c
@@ -313,13 +313,18 @@ int BPF_PROG(shirudo_lsm_key_permission, key_ref_t key_ref,
if (id->keyring_serial == 0)
return 0;
possessed = (unsigned long)key_ref & 1;
- if (serial != id->keyring_serial && serial != id->dm_verity_ring &&
- serial != id->dm_verity_key) {
+ if (serial != id->keyring_serial && serial != id->dm_verity_ring) {
for (i = 0; i < IDENTITY_KEYS_MAX; i++)
if (i < id->n_keys && id->key_serials[i] == serial)
break;
- if (i == IDENTITY_KEYS_MAX)
- return 0; /* not the anchor -- not ours */
+ if (i == IDENTITY_KEYS_MAX) {
+ for (i = 0; i < IDENTITY_KEYS_MAX; i++)
+ if (i < id->n_dm_verity_keys &&
+ id->dm_verity_keys[i] == serial)
+ break;
+ if (i == IDENTITY_KEYS_MAX)
+ return 0;
+ }
}
if (need == KEY_NEED_SEARCH && possessed)
return 0;
diff --git a/bpf/lib/identity.h b/bpf/lib/identity.h
index f874d667..f601ec5a 100644
--- a/bpf/lib/identity.h
+++ b/bpf/lib/identity.h
@@ -21,7 +21,8 @@ struct sb_id {
__u8 nv_writer_public[TPM_NV_RSA_BYTES];
__u8 ek_name[TPM_NAME_LEN];
__s32 dm_verity_ring;
- __s32 dm_verity_key;
+ __u32 n_dm_verity_keys;
+ __s32 dm_verity_keys[IDENTITY_KEYS_MAX];
__u32 nv_index;
};
diff --git a/builtin-bpm.c b/builtin-bpm.c
index 0690a581..476716c4 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -45,6 +45,9 @@
#include "util/hex.h"
#include "util/io.h"
#include "util/initrd.h"
+#include "util/image_config.h"
+#include "util/image_keys.h"
+#include "util/keys.h"
#include "util/json.h"
#include "util/log.h"
#include "util/malloc.h"
@@ -1613,15 +1616,33 @@ static int tree_fetch_publication(const struct bpm_tree_config *cfg,
char *manifest_digest, size_t digest_sz)
{
struct bpm_oci_client c __cleanup(bpm_oci_client_clear) = {};
+ struct trusted_set *trusted = NULL;
char repository[BPM_MAX_ENDPOINT];
- int ret = bpm_oci_parse_tree_repo(cfg->endpoint, &c,
- repository, sizeof(repository));
+ int ret;
+ ret = bpm_oci_parse_tree_repo(cfg->endpoint, &c,
+ repository, sizeof(repository));
if (ret)
return ret;
- return bpm_tree_fetch_publication(&c, repository, cfg->reference,
- get_cert_path(), pub,
- manifest_digest, digest_sz);
+ if (image_config_active()) {
+ trusted = xcalloc(1, sizeof(*trusted));
+ if (!trusted)
+ return -ENOMEM;
+ ret = keys_load_image_root(get_cert_path(), image_config_root_fd(),
+ true, trusted);
+ if (!ret && (!trusted->n || trusted->n_unvouched))
+ ret = -EKEYREJECTED;
+ if (!ret)
+ ret = keys_check_image_set(trusted);
+ if (ret)
+ goto out;
+ }
+ ret = bpm_tree_fetch_publication(&c, repository, cfg->reference,
+ get_cert_path(), trusted, pub,
+ manifest_digest, digest_sz);
+out:
+ xfree(trusted, sizeof(*trusted));
+ return ret;
}
static int tree_verify_upatch(const char *path, const char *expected,
diff --git a/builtin-image.c b/builtin-image.c
index 4bc38a3c..c49971bd 100644
--- a/builtin-image.c
+++ b/builtin-image.c
@@ -17,6 +17,8 @@ static void image_help(void)
"usage: shirudo image build [image builder options]\n"
" shirudo image verify <prefix> --cert <certificate>\n"
" shirudo image update <prefix-or-https-prefix>\n"
+ " shirudo image stage <prefix-or-https-prefix>\n"
+ " shirudo image stage --cancel\n"
" shirudo image status [--json]\n");
}
@@ -25,7 +27,7 @@ int cmd_image(int argc, const char **argv)
int ret;
if (argc == 2 && !strcmp(argv[1], "--list-cmds")) {
- puts("build verify update status");
+ puts("build verify update stage status");
return 0;
}
if (argc < 2 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
@@ -39,6 +41,9 @@ int cmd_image(int argc, const char **argv)
argc - 1, argv + 1);
if (!strcmp(argv[1], "update") && argc == 3) {
ret = image_update(argv[2]);
+ } else if (!strcmp(argv[1], "stage") && argc == 3) {
+ ret = !strcmp(argv[2], "--cancel") ? image_stage_cancel() :
+ image_stage(argv[2]);
} else if (!strcmp(argv[1], "status") &&
(argc == 2 || (argc == 3 && !strcmp(argv[2], "--json")))) {
ret = image_status(argc == 3);
diff --git a/builtin-init.c b/builtin-init.c
index 88108b90..26ca59d3 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -489,7 +489,7 @@ static void collect_asymmetric(key_serial_t serial, const char *type,
k->serials[k->n++] = (__s32)serial;
}
-/* Boot keys left the sealed keyring holding the config certificate alone. */
+/* Boot validation checked the complete config verification key set. */
static int dm_verity_anchor(struct identity *id)
{
struct anchor_keys keys = {};
@@ -509,13 +509,15 @@ static int dm_verity_anchor(struct identity *id)
strerror(-err));
return err;
}
- if (keys.n != 1) {
- pr_err("dm-verity keyring %d holds %zu keys, not the config "
- "certificate alone", (int)ring, keys.n);
+ if (!keys.n || keys.overflow) {
+ pr_err("dm-verity keyring %d has an invalid key count %zu",
+ (int)ring, keys.n);
return -EKEYREJECTED;
}
id->dm_verity_ring = (__s32)ring;
- id->dm_verity_key = keys.serials[0];
+ id->n_dm_verity_keys = keys.n;
+ memcpy(id->dm_verity_keys, keys.serials,
+ keys.n * sizeof(keys.serials[0]));
return 0;
}
diff --git a/builtin-keys.c b/builtin-keys.c
index e4f89a08..4b23f800 100644
--- a/builtin-keys.c
+++ b/builtin-keys.c
@@ -1094,8 +1094,8 @@ static int keys_show(int argc, const char **argv)
id.key_serials,
min(id.n_keys, IDENTITY_KEYS_MAX) },
{ ".dm-verity", keyring_dm_verity_serial,
- id.dm_verity_ring, &id.dm_verity_key,
- id.dm_verity_key > 0 },
+ id.dm_verity_ring, id.dm_verity_keys,
+ min(id.n_dm_verity_keys, IDENTITY_KEYS_MAX) },
};
size_t i;
diff --git a/builtin-status.c b/builtin-status.c
index 558f049f..97a32670 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -601,39 +601,44 @@ static void keyring_view_bpf(struct status_keyring *k,
}
}
-/* The config certificate comes from the runtime image's bootstrap. */
-static void keyring_view_dm_verity(struct status_keyring *k,
- const struct identity *ident)
+/* The config certificates come from the runtime image's bootstrap. */
+static noinline_for_stack void
+keyring_view_dm_verity(struct status_keyring *k,
+ const struct identity *ident)
{
struct image_bootstrap boot = {};
- struct status_cert *c = &k->certs[0];
- __u8 *der = NULL;
- size_t len = 0;
- size_t i;
+ size_t i, j, n_frozen = 0;
- keyring_view_links(k, &ident->dm_verity_key,
- k->pinned >= 1 && ident->dm_verity_key > 0);
- if (!k->links_rc && k->pinned >= 1 && ident->dm_verity_key > 0) {
- k->key_missing = true;
- for (i = 0; i < k->n_links; i++)
- if (k->links[i].serial == ident->dm_verity_key)
- k->key_missing = false;
+ if (k->pinned >= 1)
+ n_frozen = min(ident->n_dm_verity_keys, IDENTITY_KEYS_MAX);
+ keyring_view_links(k, ident->dm_verity_keys, n_frozen);
+ for (i = 0; !k->links_rc && i < n_frozen; i++) {
+ for (j = 0; j < k->n_links; j++)
+ if (k->links[j].serial == ident->dm_verity_keys[i])
+ break;
+ if (j == k->n_links)
+ k->key_missing = true;
}
k->certs_rc = image_bootstrap_read(RUNTIME_CONF_PATH,
&boot, false);
- if (!k->certs_rc && !boot.certificate[0])
+ if (!k->certs_rc && !boot.n_certificates)
k->certs_rc = -ENOENT;
- if (!k->certs_rc)
- k->certs_rc = keys_read_der(boot.certificate, &der, &len);
- if (!k->certs_rc)
- k->certs_rc = keys_digest_der(der, len, c->sha256,
- c->fingerprint);
- if (!k->certs_rc) {
- c->primary = true;
- k->n_certs = 1;
- keyring_view_cert(k, c, der, len);
+ for (i = 0; !k->certs_rc && i < boot.n_certificates; i++) {
+ struct status_cert *c = &k->certs[k->n_certs];
+ __u8 *der = NULL;
+ size_t len = 0;
+
+ k->certs_rc = keys_read_der(boot.certificates[i], &der, &len);
+ if (!k->certs_rc)
+ k->certs_rc = keys_digest_der(der, len, c->sha256,
+ c->fingerprint);
+ if (!k->certs_rc) {
+ c->primary = true;
+ keyring_view_cert(k, c, der, len);
+ k->n_certs++;
+ }
+ xfree(der, len);
}
- xfree(der, len);
}
static void keyring_cond_input(struct conditions_input *in,
diff --git a/completion/shirudo.bash b/completion/shirudo.bash
index fc340dd6..12cbfc84 100644
--- a/completion/shirudo.bash
+++ b/completion/shirudo.bash
@@ -41,6 +41,8 @@ _shirudo()
--key --cert --salt --builder" -- "$cur") )
elif [[ $cur == -* && $sub == verify ]]; then
COMPREPLY=( $(compgen -W "--cert" -- "$cur") )
+ elif [[ $cur == -* && $sub == stage ]]; then
+ COMPREPLY=( $(compgen -W "--cancel" -- "$cur") )
elif [[ $cur == -* && $sub == status ]]; then
COMPREPLY=( $(compgen -W "--json" -- "$cur") )
else
@@ -155,8 +157,10 @@ _shirudo()
COMPREPLY=( $(compgen -W "sync append" -- "$cur") )
elif [[ $sub == tree && ${COMP_WORDS[3]} == sync && $cur == -* ]]; then
COMPREPLY=( $(compgen -W "--dry-run --report" -- "$cur") )
+ elif [[ $sub == tree && ${COMP_WORDS[3]} == append && $prev == --previous-cert ]]; then
+ COMPREPLY=( $(compgen -f -- "$cur") )
elif [[ $sub == tree && ${COMP_WORDS[3]} == append && $cur == -* ]]; then
- COMPREPLY=( $(compgen -W "--keys-dir --key --cert --tree-id \
+ COMPREPLY=( $(compgen -W "--keys-dir --key --cert --previous-cert --tree-id \
--reference --op" -- "$cur") )
elif [[ $sub == tree && ${COMP_WORDS[3]} == append ]]; then
COMPREPLY=( $(compgen -f -X '!*.bee' -- "$cur") \
diff --git a/testing/functional/image/t5004-image-cli.sh b/testing/functional/image/t5004-image-cli.sh
index 5fec0263..ce6d34e9 100755
--- a/testing/functional/image/t5004-image-cli.sh
+++ b/testing/functional/image/t5004-image-cli.sh
@@ -89,7 +89,7 @@ test_expect_success 'repository certificate references cannot escape to host fil
done
'
-test_expect_success 'tree publications verify against the runtime trust anchor' '
+test_expect_success 'tree publications use the active config trusted set' '
"$H" "$ROOT" tree >"$WORK/certificate" &&
grep -qx /run/shirudo/runtime/keys/cert.der "$WORK/certificate"
'
diff --git a/testing/fuzz/fuzz-image.c b/testing/fuzz/fuzz-image.c
index 566e01f6..f4b5e242 100644
--- a/testing/fuzz/fuzz-image.c
+++ b/testing/fuzz/fuzz-image.c
@@ -12,7 +12,7 @@
int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
{
- struct image_bootstrap boot;
+ struct image_bootstrap boot = {};
struct config_image image;
char path[64];
int fd;
diff --git a/testing/helper/image-cli.h b/testing/helper/image-cli.h
new file mode 100644
index 00000000..9a82685e
--- /dev/null
+++ b/testing/helper/image-cli.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/* Copyright (c) 2026 Authors of shirudo */
+
+#ifndef SHIRUDO_TEST_IMAGE_CLI_H
+#define SHIRUDO_TEST_IMAGE_CLI_H
+
+#include "util/bpm_package.h"
+#include "util/keys.h"
+
+int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,
+ const char *repository,
+ const char *reference,
+ const char *certificate,
+ const struct trusted_set *trusted,
+ struct tree_publication *pub,
+ char *digest, size_t capacity);
+int __wrap_keys_load_image_root(const char *primary, int root_fd,
+ bool with_trusted, struct trusted_set *set);
+int __wrap_keys_check_image_set(const struct trusted_set *set);
+
+#endif /* SHIRUDO_TEST_IMAGE_CLI_H */
diff --git a/testing/helper/test-image-cli.c b/testing/helper/test-image-cli.c
index d1bc3de1..c22b876c 100644
--- a/testing/helper/test-image-cli.c
+++ b/testing/helper/test-image-cli.c
@@ -4,17 +4,13 @@
#include "../../builtin-bpm.c"
#include "util/config.h"
-int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,
- const char *repository,
- const char *reference,
- const char *certificate,
- struct tree_publication *pub,
- char *digest, size_t capacity);
+#include "image-cli.h"
int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,
const char *repository,
const char *reference,
const char *certificate,
+ const struct trusted_set *trusted,
struct tree_publication *pub,
char *digest, size_t capacity)
{
@@ -22,6 +18,18 @@ int __wrap_bpm_tree_fetch_publication(struct bpm_oci_client *client,
return 0;
}
+int __wrap_keys_load_image_root(const char *primary, int root_fd,
+ bool with_trusted, struct trusted_set *set)
+{
+ set->n = 1;
+ return 0;
+}
+
+int __wrap_keys_check_image_set(const struct trusted_set *set)
+{
+ return set->n == 1 ? 0 : -EINVAL;
+}
+
int main(int argc, const char **argv)
{
struct config bootstrap;
diff --git a/testing/helper/test-image-config.c b/testing/helper/test-image-config.c
index 60c0e055..c6a07811 100644
--- a/testing/helper/test-image-config.c
+++ b/testing/helper/test-image-config.c
@@ -24,7 +24,7 @@ static int read_bootstrap(int argc, char **argv)
if (!ret) {
hex_encode(boot.runtime_root, 32, root);
printf("runtime=%s\nroot=%s\nconfig=%s\ncertificate=%s\npcr=%u\n",
- boot.runtime, root, boot.config, boot.certificate,
+ boot.runtime, root, boot.config, boot.certificates[0],
boot.pcr);
}
printf("rc=%d\n", ret);
diff --git a/testing/proofs/cbmc/bpm-tree-sync-model.c b/testing/proofs/cbmc/bpm-tree-sync-model.c
index e558c668..ffa3625b 100644
--- a/testing/proofs/cbmc/bpm-tree-sync-model.c
+++ b/testing/proofs/cbmc/bpm-tree-sync-model.c
@@ -183,6 +183,32 @@ void libc_free(void *p)
{
}
+void *xcalloc(size_t nmemb, size_t size)
+{
+ static struct trusted_set trusted;
+
+ __CPROVER_assert(nmemb == 1 && size == sizeof(trusted),
+ "only the active signing set is allocated");
+ return fail_here() ? NULL : &trusted;
+}
+
+int image_config_root_fd(void)
+{
+ return 3;
+}
+
+int keys_load_image_root(const char *primary, int root_fd,
+ bool with_trusted, struct trusted_set *trusted)
+{
+ trusted->n = 1;
+ return fail_here() ? -EIO : 0;
+}
+
+int keys_check_image_set(const struct trusted_set *trusted)
+{
+ return fail_here() ? -EKEYREJECTED : 0;
+}
+
void xfree(void *p, size_t size)
{
}
@@ -224,6 +250,7 @@ const char *get_cert_path(void)
int bpm_tree_fetch_publication(struct bpm_oci_client *c,
const char *repository, const char *reference,
const char *cert_path,
+ const struct trusted_set *trusted,
struct tree_publication *pub,
char *manifest_digest, size_t digest_sz)
{
diff --git a/testing/proofs/cbmc/image-bootstrap.c b/testing/proofs/cbmc/image-bootstrap.c
index 4996d1cc..63207a66 100644
--- a/testing/proofs/cbmc/image-bootstrap.c
+++ b/testing/proofs/cbmc/image-bootstrap.c
@@ -37,10 +37,12 @@ void harness(void)
strscpy(boot.runtime, "/r", sizeof(boot.runtime));
if (bootstrap_parse(f, &boot, initial))
return;
- __CPROVER_assert(!boot.certificate[0] ||
- !strncmp(boot.certificate, RUNTIME_DIR "/",
- sizeof(RUNTIME_DIR)),
- "a certificate under the runtime");
+ __CPROVER_assert(boot.n_certificates <= KEYS_MAX,
+ "bounded config verification certificate set");
+ for (i = 0; i < boot.n_certificates; i++)
+ __CPROVER_assert(!strncmp(boot.certificates[i],
+ RUNTIME_DIR "/", sizeof(RUNTIME_DIR)),
+ "a certificate under the runtime");
__CPROVER_assert(!boot.have_pcr || !config_measure_pcr_valid(boot.pcr),
"a PCR measurements may use");
if (!initial)
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 20b037b5..777df347 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -26,7 +26,7 @@ upatch-rodata -I ../../../vendor/libbpf/include/uapi -I ../../../vendor/libbpf
string-number-model --unwind 6
measured-fold-model --unwind 7
bpm-tree-follows --unwind 4
-bpm-tree-sync-model --unwind 60 --max-field-sensitivity-array-size 257 LEN=0-2
+bpm-tree-sync-model --object-bits 10 --unwind 60 --max-field-sensitivity-array-size 257 LEN=0-2
bpm-upatch-member --unwind 30 LEN=0-18
tpm-reader --unwind 1
tpm-signature --unwind 1 --unwindset bytes_at.0:33
diff --git a/tools/gen-image/shirudo-gen-runtime b/tools/gen-image/shirudo-gen-runtime
index 025c7aff..f177a22d 100755
--- a/tools/gen-image/shirudo-gen-runtime
+++ b/tools/gen-image/shirudo-gen-runtime
@@ -13,11 +13,11 @@ usage: shirudo-gen-runtime --binary <shirudo-target> --bootstrap-conf <file>
--cert <initial-BPF-cert.der> --config-cert <config-cert.der>
--output <prefix> --keys-dir <operator-key-directory>
[--size <MiB>] [--builder <shirudo-build>] [--unit-output <file>]
- [--extra-binary <trusted-ELF>]
+ [--extra-binary <trusted-ELF>] [--config-cert <additional-cert.der>]
Package the trusted executable without its symbols, bootstrap settings and
public certificates. Static targets run directly. Dynamic executables bring
-their loader and libraries.
+their loader and libraries. Repeat --config-cert to allow overlapping keys.
Use trusted inputs: ldd invokes dynamic loaders on the operator.
EOF
}
@@ -29,7 +29,7 @@ parse_args()
--binary) binary=${2:?}; shift 2 ;;
--bootstrap-conf) conf=${2:?}; shift 2 ;;
--cert) cert=${2:?}; shift 2 ;;
- --config-cert) config_cert=${2:?}; shift 2 ;;
+ --config-cert) config_certs+=("${2:?}"); shift 2 ;;
--output) output=${2:?}; shift 2 ;;
--keys-dir) keys_dir=${2:?}; shift 2 ;;
--size) size=${2:?}; shift 2 ;;
@@ -50,11 +50,20 @@ elf_interpreter()
check_inputs()
{
- local file
+ local file i j
- for file in "$binary" "$conf" "$cert" "$config_cert"; do
+ for file in "$binary" "$conf" "$cert"; do
[ -n "$file" ] && [ -f "$file" ] ||
- die 'binary, bootstrap config and both public certificates are required'
+ die 'binary, bootstrap config and BPF public certificate are required'
+ done
+ [ "${#config_certs[@]}" -gt 0 ] || die 'a config public certificate is required'
+ [ "${#config_certs[@]}" -le 16 ] || die 'at most 16 config certificates are allowed'
+ for ((i = 0; i < ${#config_certs[@]}; i++)); do
+ file=${config_certs[i]}
+ [ -f "$file" ] || die "config certificate not found: $file"
+ for ((j = 0; j < i; j++)); do
+ ! cmp -s "$file" "${config_certs[j]}" || die 'duplicate config certificate'
+ done
done
check_image_options "$output" "$keys_dir" "$size"
require_command readelf 'install binutils (readelf)'
@@ -68,15 +77,32 @@ check_inputs()
fi
}
+stage_config_certificates()
+{
+ local runtime_conf="$work/root/etc/shirudo/shirudo.conf"
+ local name i
+
+ awk '!/^[[:space:]]*config[.]verification_key[[:space:]]*=/' \
+ "$conf" >"$runtime_conf"
+ for ((i = 0; i < ${#config_certs[@]}; i++)); do
+ name=config-cert.der
+ if [ "$i" -gt 0 ]; then
+ name="config-cert-$((i + 1)).der"
+ fi
+ install -m 0644 "${config_certs[i]}" "$work/root/etc/shirudo/$name"
+ printf 'config.verification_key=/run/shirudo/runtime/etc/shirudo/%s\n' \
+ "$name" >>"$runtime_conf"
+ done
+}
+
stage_files()
{
mkdir -p "$work/root/usr/bin" "$work/root/etc/shirudo" "$work/root/keys"
# llvm-strip, unlike binutils strip, handles a target of another architecture.
llvm-strip -o "$work/root/usr/bin/shirudo" "$binary"
chmod 0755 "$work/root/usr/bin/shirudo"
- install -m 0644 "$conf" "$work/root/etc/shirudo/shirudo.conf"
install -m 0644 "$cert" "$work/root/keys/cert.der"
- install -m 0644 "$config_cert" "$work/root/etc/shirudo/config-cert.der"
+ stage_config_certificates
: >"$work/ldd"
: >"$work/interpreters"
if [ -n "$interpreter" ]; then
@@ -175,7 +201,7 @@ main()
binary=
conf=
cert=
-config_cert=
+config_certs=()
output=
keys_dir=
# The stripped static target with its certificates, plus about 1 MiB.
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index 0702a716..63710c28 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -44,7 +44,8 @@ static void tree_append_usage(void)
fprintf(stderr,
"usage: shirudo bpm tree append <package-file> <repository>\n"
" [--keys-dir <dir>] [--key <signing_key.pem>]\n"
- " [--cert <cert.der>] [--tree-id <id>]\n"
+ " [--cert <cert.der>] [--previous-cert <cert.der>]\n"
+ " [--tree-id <id>]\n"
" [--reference <ref>] [--op add|delete]\n\n"
"Publishes the [upatches.tree] entries of a built package as the next\n"
"operations of the signed tree at <repository>:<ref> (default stable).\n"
@@ -645,6 +646,7 @@ static int cmd_bpm_tree_append(int argc, char **argv)
char repository[BPM_MAX_ENDPOINT], repo_ref[BPM_MAX_ENDPOINT];
struct bpm_descriptor config, payload_layer, sig_layer;
const char *key = NULL, *cert = NULL, *tree_id = NULL;
+ const char *previous_cert = NULL;
const char *reference = "stable", *operation = "add";
char key_path[PATH_MAX], cert_path[PATH_MAX];
char parent[BPM_MAX_DIGEST] = {}, digest[72];
@@ -677,6 +679,10 @@ static int cmd_bpm_tree_append(int argc, char **argv)
cert = argv[++i];
} else if (!strncmp(a, "--cert=", 7)) {
cert = a + 7;
+ } else if (!strcmp(a, "--previous-cert") && i + 1 < argc) {
+ previous_cert = argv[++i];
+ } else if (!strncmp(a, "--previous-cert=", 16)) {
+ previous_cert = a + 16;
} else if (!strcmp(a, "--tree-id") && i + 1 < argc) {
tree_id = argv[++i];
} else if (!strncmp(a, "--tree-id=", 10)) {
@@ -729,6 +735,8 @@ static int cmd_bpm_tree_append(int argc, char **argv)
}
if (build_check_keys(key, cert))
return -EACCES;
+ if (!previous_cert)
+ previous_cert = cert;
if (bpm_trim(raw_repository, repo_ref, sizeof(repo_ref))) {
pr_err("bpm tree append: repository is longer than %zu bytes",
sizeof(repo_ref) - 1);
@@ -760,8 +768,8 @@ static int cmd_bpm_tree_append(int argc, char **argv)
pr_err("bpm tree append: the repository must be oci://registry/repository");
goto out;
}
- ret = bpm_tree_fetch_publication(&c, repository, reference, cert, &pub,
- parent, sizeof(parent));
+ ret = bpm_tree_fetch_publication(&c, repository, reference, previous_cert,
+ NULL, &pub, parent, sizeof(parent));
if (ret == -ENOENT) {
pub = (struct tree_publication){ .schema = 1,
.generation = 1 };
diff --git a/util/bpm_package.c b/util/bpm_package.c
index a0fd30f6..55edf310 100644
--- a/util/bpm_package.c
+++ b/util/bpm_package.c
@@ -33,6 +33,7 @@
#include "hex.h"
#include "io.h"
#include "json.h"
+#include "keys.h"
#include "log.h"
#include "malloc.h"
#include "seal.h"
@@ -895,6 +896,7 @@ int bpm_tree_fetch_publication(struct bpm_oci_client *c,
const char *repository,
const char *reference,
const char *cert_path,
+ const struct trusted_set *trusted,
struct tree_publication *pub,
char *manifest_digest, size_t digest_sz)
{
@@ -934,10 +936,11 @@ int bpm_tree_fetch_publication(struct bpm_oci_client *c,
BPM_TREE_SIG_MEDIA, &payload, &sig);
if (ret)
goto out;
- if (bpm_verify_cms(payload.data, payload.len, sig.data, sig.len, cert_path)) {
- ret = -EKEYREJECTED;
+ ret = trusted ? keys_verify_signature(trusted, payload.data, payload.len,
+ sig.data, sig.len, NULL) :
+ bpm_verify_cms(payload.data, payload.len, sig.data, sig.len, cert_path);
+ if (ret)
goto out;
- }
ret = tree_parse((const char *)payload.data, payload.len, pub);
out:
xfree(layers, BPM_MAX_ENTRIES * sizeof(*layers));
diff --git a/util/bpm_package.h b/util/bpm_package.h
index a4f75627..7f0dc39d 100644
--- a/util/bpm_package.h
+++ b/util/bpm_package.h
@@ -16,6 +16,8 @@
#include "bpm_oci.h"
#include "bpm_tree.h"
+struct trusted_set;
+
struct bpm_index_entry {
char name[BPM_MAX_NAME];
char version[BPM_MAX_NAME];
@@ -95,12 +97,14 @@ int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info);
/*
* Fetch the signed tree publication at repository:reference, check every
- * layer against its descriptor and the payload against cert_path, and
+ * layer against its descriptor and the payload against trusted, or
+ * cert_path when trusted is NULL, and
* parse it. -ENOENT when the reference does not exist yet.
*/
int bpm_tree_fetch_publication(struct bpm_oci_client *c,
const char *repository, const char *reference,
const char *cert_path,
+ const struct trusted_set *trusted,
struct tree_publication *pub,
char *manifest_digest, size_t digest_sz);
diff --git a/util/conditions.c b/util/conditions.c
index 00052a15..cf38dee4 100644
--- a/util/conditions.c
+++ b/util/conditions.c
@@ -86,7 +86,7 @@ static void keyring_condition(const struct conditions_input *in,
in->dmv_unfrozen, in->dmv_unfrozen == 1 ? "" : "s");
else if (in->dmv_key_missing)
set_detail(c, "ALERT",
- "the config key init froze is gone from the dm-verity keyring");
+ "a config key init froze is gone from the dm-verity keyring");
else if (in->ksp_seen && in->dmvp_seen)
set_detail(c, "OK",
"bpf serial %lld, dm-verity serial %lld, pins match",
diff --git a/util/conditions.h b/util/conditions.h
index 6ae78190..dae694d1 100644
--- a/util/conditions.h
+++ b/util/conditions.h
@@ -37,7 +37,7 @@ struct conditions_input {
int dmv_serial_matches; /* 0/1 if dmvm_seen */
int dmvp_seen, dmvm_seen;
int dmv_unfrozen;
- int dmv_key_missing; /* init's config key is gone */
+ int dmv_key_missing; /* a config key init froze is gone */
int tpm_reachable;
int chain_seen;
int chain_matches; /* 0/1 if cm_seen */
diff --git a/util/config_update.c b/util/config_update.c
index 4ebc7df2..f301d01f 100644
--- a/util/config_update.c
+++ b/util/config_update.c
@@ -244,8 +244,8 @@ void config_update_close(struct config_update *update)
update->lock_fd = -1;
}
-int config_update_read(struct config_update *update,
- struct config_update_record *out)
+static int selection_read(struct config_update *update, const char *name,
+ struct config_update_record *out)
{
char wire[RECORD_MAX];
struct stat st;
@@ -255,7 +255,7 @@ int config_update_read(struct config_update *update,
if (!update || update->dir_fd < 0 || !out)
return -EINVAL;
- fd = openat(update->dir_fd, "state",
+ fd = openat(update->dir_fd, name,
O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK);
if (fd < 0)
return -errno;
@@ -282,9 +282,16 @@ int config_update_read(struct config_update *update,
return ret;
}
-static int state_save(struct config_update *update,
- const struct config_update_record *record,
- bool inject)
+int config_update_read(struct config_update *update,
+ struct config_update_record *out)
+{
+ return selection_read(update, "state", out);
+}
+
+static int selection_save(struct config_update *update,
+ const struct config_update_record *record,
+ const char *name, const char *temporary,
+ bool inject)
{
char wire[RECORD_MAX];
size_t length;
@@ -293,9 +300,9 @@ static int state_save(struct config_update *update,
ret = record_encode(record, true, wire, sizeof(wire), &length);
if (ret)
return ret;
- if (unlinkat(update->dir_fd, ".state.tmp", 0) && errno != ENOENT)
+ if (unlinkat(update->dir_fd, temporary, 0) && errno != ENOENT)
return -errno;
- fd = openat(update->dir_fd, ".state.tmp",
+ fd = openat(update->dir_fd, temporary,
O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC | O_NOFOLLOW, 0600);
if (fd < 0)
return -errno;
@@ -309,17 +316,24 @@ static int state_save(struct config_update *update,
if (close(fd) && !ret)
ret = -errno;
if (!ret &&
- renameat(update->dir_fd, ".state.tmp", update->dir_fd, "state"))
+ renameat(update->dir_fd, temporary, update->dir_fd, name))
ret = -errno;
if (!ret && inject)
ret = checkpoint(update, CONFIG_CHECK_STATE_RENAME);
if (!ret && fsync(update->dir_fd))
ret = -errno;
if (ret)
- unlinkat(update->dir_fd, ".state.tmp", 0);
+ unlinkat(update->dir_fd, temporary, 0);
return ret;
}
+static int state_save(struct config_update *update,
+ const struct config_update_record *record,
+ bool inject)
+{
+ return selection_save(update, record, "state", ".state.tmp", inject);
+}
+
static bool same_boot(const struct config_update_record *a,
const struct config_update_record *b)
{
@@ -327,6 +341,13 @@ static bool same_boot(const struct config_update_record *a,
a->restart_count == b->restart_count;
}
+static bool same_target(const struct config_update_target *a,
+ const struct config_update_target *b)
+{
+ return !strcmp(a->prefix, b->prefix) &&
+ !memcmp(a->root_hash, b->root_hash, 32);
+}
+
static bool same_event(const struct config_update_record *a,
const struct config_update_record *b)
{
@@ -627,6 +648,79 @@ static int begin_event(struct config_update *update,
return complete(update);
}
+int config_update_stage_read(struct config_update *update,
+ struct config_update_record *out)
+{
+ return selection_read(update, "next-boot", out);
+}
+
+int config_update_clear_staged(struct config_update *update)
+{
+ if (!update || update->dir_fd < 0 || update->lock_fd < 0)
+ return -EINVAL;
+ if (unlinkat(update->dir_fd, "next-boot", 0))
+ return errno == ENOENT ? 0 : -errno;
+ return fsync(update->dir_fd) ? -errno : 0;
+}
+
+int config_update_stage(struct config_update *update,
+ const struct config_update_target *target)
+{
+ struct config_update_record record;
+ int ret;
+
+ if (!update || update->lock_fd < 0 || target_valid(target))
+ return -EINVAL;
+ ret = config_update_check(update, &record);
+ if (ret)
+ return ret;
+ record.target = *target;
+ return selection_save(update, &record, "next-boot", ".next-boot.tmp",
+ false);
+}
+
+int config_update_staged(struct config_update *update,
+ const struct config_update_record *previous,
+ __u32 reset, __u32 restart,
+ struct config_update_target *target)
+{
+ struct config_update_record staged;
+ int ret;
+
+ if (!previous || !target)
+ return -EINVAL;
+ ret = config_update_stage_read(update, &staged);
+ if (ret)
+ return ret == -ENOENT ? 0 : ret;
+ if (staged.pending)
+ return -EBADMSG;
+ if (staged.reset_count == reset && staged.restart_count == restart)
+ return 0;
+ if (same_target(&staged.target, &previous->target))
+ return 0;
+ if (staged.sequence != previous->sequence ||
+ !same_boot(&staged, previous)) {
+ pr_warn("image: ignoring staged config because the active selection changed");
+ return 0;
+ }
+ *target = staged.target;
+ return 1;
+}
+
+static int complete_staged(struct config_update *update)
+{
+ struct config_update_record staged, current;
+ int ret;
+
+ ret = config_update_stage_read(update, &staged);
+ if (ret)
+ return ret == -ENOENT ? 0 : ret;
+ ret = config_update_read(update, &current);
+ if (ret || same_boot(&current, &staged))
+ return ret;
+ return config_update_clear_staged(update);
+}
+
int config_update_begin(struct config_update *update,
const struct config_update_target *t,
__u32 pcr)
@@ -644,8 +738,15 @@ int config_update_begin(struct config_update *update,
return -EPERM;
if (!memcmp(t->root_hash, previous.target.root_hash, 32))
return 0;
- return begin_event(update, t, &previous, pcr,
- CONFIG_EVENT_UPDATE);
+ ret = begin_event(update, t, &previous, pcr, CONFIG_EVENT_UPDATE);
+ if (!ret) {
+ int err = config_update_clear_staged(update);
+
+ if (err)
+ pr_warn("image: cannot remove obsolete staged config: %s",
+ strerror(-err));
+ }
+ return ret;
}
int config_update_boot(struct config_update *update,
@@ -653,6 +754,7 @@ int config_update_boot(struct config_update *update,
__u32 pcr)
{
struct config_update_record previous = {}, last;
+ struct config_update_target staged;
__u32 reset, restart;
int ret;
@@ -675,10 +777,14 @@ int config_update_boot(struct config_update *update,
return -EBUSY;
return config_update_check(update, NULL);
}
- if (previous.sequence &&
- (strcmp(t->prefix, previous.target.prefix) ||
- memcmp(t->root_hash, previous.target.root_hash, 32)))
- return -EUCLEAN;
+ if (previous.sequence && !same_target(t, &previous.target)) {
+ ret = config_update_staged(update, &previous, reset, restart,
+ &staged);
+ if (ret < 0)
+ return ret;
+ if (!ret || !same_target(t, &staged))
+ return -EUCLEAN;
+ }
ret = events_scan(update, &last, NULL, NULL, previous.pending,
NULL, NULL);
if (ret)
@@ -699,9 +805,11 @@ int config_update_complete_boot(struct config_update *update)
if (!update || update->dir_fd < 0)
return -EINVAL;
- if (!update->boot_pending)
- return config_update_check(update, NULL);
- update->boot_pending = false;
- ret = complete(update);
- return ret;
+ if (!update->boot_pending) {
+ ret = config_update_check(update, NULL);
+ } else {
+ update->boot_pending = false;
+ ret = complete(update);
+ }
+ return ret ? ret : complete_staged(update);
}
diff --git a/util/config_update.h b/util/config_update.h
index 2587627c..10bc67ae 100644
--- a/util/config_update.h
+++ b/util/config_update.h
@@ -77,6 +77,20 @@ int config_update_open(const char *directory,
void config_update_close(struct config_update *update);
int config_update_read(struct config_update *update,
struct config_update_record *out);
+/*
+ * next-boot uses the selection record format: its target is the candidate,
+ * and its sequence and TPM counts identify the selection it was staged from.
+ */
+int config_update_stage(struct config_update *update,
+ const struct config_update_target *target);
+int config_update_stage_read(struct config_update *update,
+ struct config_update_record *out);
+/* 1 selects an eligible staged target, 0 leaves the current selection. */
+int config_update_staged(struct config_update *update,
+ const struct config_update_record *previous,
+ __u32 reset, __u32 restart,
+ struct config_update_target *target);
+int config_update_clear_staged(struct config_update *update);
int config_update_begin(struct config_update *update,
const struct config_update_target *t,
__u32 pcr);
diff --git a/util/identity.h b/util/identity.h
index e44fda71..5e0b5a3c 100644
--- a/util/identity.h
+++ b/util/identity.h
@@ -30,7 +30,8 @@ struct identity {
__u8 nv_writer_public[TPM_NV_RSA_BYTES];
__u8 ek_name[TPM_NAME_LEN];
__s32 dm_verity_ring;
- __s32 dm_verity_key;
+ __u32 n_dm_verity_keys;
+ __s32 dm_verity_keys[IDENTITY_KEYS_MAX];
__u32 nv_index;
};
@@ -70,7 +71,7 @@ struct task_policy {
BUILD_BUG_ON(sizeof(struct device_authority) != 48);
BUILD_BUG_ON(sizeof(struct task_authority) != 8);
-BUILD_BUG_ON(sizeof(struct identity) != 580);
+BUILD_BUG_ON(sizeof(struct identity) != 644);
BUILD_BUG_ON(sizeof(struct task_policy) != 16);
/* The bpffs mount init made, which the unmount guard keeps mounted. */
diff --git a/util/image_bootstrap.c b/util/image_bootstrap.c
index 5f4443a5..53a8cddb 100644
--- a/util/image_bootstrap.c
+++ b/util/image_bootstrap.c
@@ -39,6 +39,26 @@ static char *trim(char *text)
return text;
}
+static int bootstrap_add_certificate(struct image_bootstrap *boot,
+ const char *path)
+{
+ size_t i;
+
+ if (strncmp(path, RUNTIME_DIR "/", sizeof(RUNTIME_DIR)) ||
+ !image_path_valid(path))
+ return -EPERM;
+ if (boot->n_certificates == KEYS_MAX)
+ return -E2BIG;
+ for (i = 0; i < boot->n_certificates; i++)
+ if (!strcmp(boot->certificates[i], path))
+ return -EEXIST;
+ if (strscpy(boot->certificates[i], path,
+ sizeof(boot->certificates[i])) < 0)
+ return -ENAMETOOLONG;
+ boot->n_certificates++;
+ return 0;
+}
+
/* The stream is consumed and closed. */
static int bootstrap_parse(FILE *file, struct image_bootstrap *boot,
bool initial)
@@ -87,13 +107,7 @@ static int bootstrap_parse(FILE *file, struct image_bootstrap *boot,
sizeof(boot->config)) < 0)
ret = -ENAMETOOLONG;
} else if (!strcmp(key, "config.verification_key")) {
- if (strncmp(value, RUNTIME_DIR "/",
- sizeof(RUNTIME_DIR)) ||
- !image_path_valid(value))
- ret = -EPERM;
- else if (strscpy(boot->certificate, value,
- sizeof(boot->certificate)) < 0)
- ret = -ENAMETOOLONG;
+ ret = bootstrap_add_certificate(boot, value);
} else if (!strcmp(key, "config.pcr")) {
__u64 pcr;
diff --git a/util/image_bootstrap.h b/util/image_bootstrap.h
index 77e9db30..0a4fb1cc 100644
--- a/util/image_bootstrap.h
+++ b/util/image_bootstrap.h
@@ -10,10 +10,13 @@
#include <stdbool.h>
#include <stdint.h>
+#include "keys.h"
+
struct image_bootstrap {
char runtime[PATH_MAX];
char config[PATH_MAX];
- char certificate[PATH_MAX];
+ char certificates[KEYS_MAX][PATH_MAX];
+ size_t n_certificates;
__u8 runtime_root[32];
__u32 pcr;
bool have_root;
diff --git a/util/image_cache.c b/util/image_cache.c
index c51d77ef..6bd28417 100644
--- a/util/image_cache.c
+++ b/util/image_cache.c
@@ -171,7 +171,8 @@ static int verify_incoming(const struct config_image_open *opened,
}
int image_cache_fetch(const char *source,
- struct config_update_target *target)
+ struct config_update_target *target,
+ image_cache_verify_fn verify, void *ctx)
{
static const struct {
const char *suffix;
@@ -189,6 +190,8 @@ int image_cache_fetch(const char *source,
int dir = -1, ret;
size_t i;
+ if (!verify)
+ return -EINVAL;
if (!mkdtemp(staging))
return -errno;
ret = seal_label(staging);
@@ -211,7 +214,9 @@ int image_cache_fetch(const char *source,
ret = config_image_open(incoming, &opened);
if (ret)
goto out;
- ret = verify_incoming(&opened, staging);
+ ret = verify(&opened, ctx);
+ if (!ret)
+ ret = verify_incoming(&opened, staging);
if (!ret) {
memcpy(target->root_hash, opened.image.root_hash, 32);
hex_encode(target->root_hash, 32, hex);
diff --git a/util/image_cache.h b/util/image_cache.h
index 39e77325..6bd05870 100644
--- a/util/image_cache.h
+++ b/util/image_cache.h
@@ -5,9 +5,17 @@
#define SHIRUDO_IMAGE_CACHE_H
struct config_update_target;
+struct config_image_open;
-/* The caller holds the update lock and owns the sealed cache directory. */
+typedef int (*image_cache_verify_fn)(const struct config_image_open *image,
+ void *ctx);
+
+/*
+ * The caller holds the update lock and owns the sealed cache directory.
+ * verify authenticates the root before a kernel mapping is created.
+ */
int image_cache_fetch(const char *source,
- struct config_update_target *target);
+ struct config_update_target *target,
+ image_cache_verify_fn verify, void *ctx);
#endif /* SHIRUDO_IMAGE_CACHE_H */
diff --git a/util/image_runtime.c b/util/image_runtime.c
index e978c6d0..f1c00f3f 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -29,6 +29,7 @@
#include "config.h"
#include "config_image.h"
#include "config_update.h"
+#include "crypto.h"
#include "dm_verity.h"
#include "hex.h"
#include "identity.h"
@@ -48,6 +49,19 @@
#include "seal.h"
#include "tpm.h"
+enum config_prepare {
+ CONFIG_PREPARE_BOOT,
+ CONFIG_PREPARE_UPDATE,
+ CONFIG_PREPARE_STAGE,
+};
+
+struct config_certificate {
+ struct cert parsed;
+ __u8 *der;
+ size_t size;
+ __u8 fingerprint[32];
+};
+
struct image_context {
struct config_update_target boot_target;
struct dm_verity boot_runtime;
@@ -58,7 +72,7 @@ struct image_context {
struct image_bootstrap bootstrap;
struct tpm *tpm;
int candidate_fd;
- int certificate_fd;
+ struct config_certificate certificates[KEYS_MAX];
int config_state; /* what current_config() refused status with */
bool loaded;
bool boot_keys_open;
@@ -67,7 +81,6 @@ struct image_context {
static struct image_context image = {
.candidate_fd = -1,
- .certificate_fd = -1,
.update = { .dir_fd = -1, .lock_fd = -1 },
.candidate = { .data_fd = -1, .hash_fd = -1, .signature_fd = -1 },
.candidate_device = { .data_loop_fd = -1, .hash_loop_fd = -1 },
@@ -263,10 +276,78 @@ static int open_runtime_file(const char *path, dev_t device)
return fd;
}
+static void close_config_certificates(void)
+{
+ size_t i;
+
+ for (i = 0; i < KEYS_MAX; i++) {
+ cert_free(&image.certificates[i].parsed);
+ xfree(image.certificates[i].der, image.certificates[i].size);
+ memset(&image.certificates[i], 0, sizeof(image.certificates[i]));
+ }
+}
+
+static int read_config_certificate(size_t index, dev_t device)
+{
+ struct config_certificate *key = &image.certificates[index];
+ char algorithm[32];
+ int fd, ret;
+ size_t i;
+
+ fd = open_runtime_file(image.bootstrap.certificates[index], device);
+ if (fd < 0)
+ return fd;
+ ret = keys_read_der_fd(fd, &key->der, &key->size);
+ close(fd);
+ if (!ret)
+ ret = cert_read_der(key->der, key->size, &key->parsed);
+ if (!ret)
+ ret = cert_key_algorithm(&key->parsed, algorithm, sizeof(algorithm));
+ if (!ret && strcmp(algorithm, "ML-DSA-87"))
+ ret = -EKEYREJECTED;
+ if (!ret)
+ ret = cert_pubkey_digest(&key->parsed, key->fingerprint);
+ if (ret)
+ return ret;
+ for (i = 0; i < index; i++)
+ if (!memcmp(image.certificates[i].fingerprint,
+ key->fingerprint, 32))
+ return -EEXIST;
+ return 0;
+}
+
+static int verify_config_root(const struct config_image_open *opened, void *ctx)
+{
+ struct image_context *current = ctx;
+ __u8 *signature = NULL;
+ char root[65];
+ size_t size = 0, i;
+ int ret;
+
+ if (!current->bootstrap.n_certificates || opened->signature_fd < 0)
+ return -ENOKEY;
+ ret = read_fd(opened->signature_fd, "config root signature",
+ CONFIG_IMAGE_SIG_MAX, &signature, &size);
+ if (ret)
+ return ret;
+ hex_encode(opened->image.root_hash, 32, root);
+ ret = -EKEYREJECTED;
+ for (i = 0; i < current->bootstrap.n_certificates; i++) {
+ if (!verify_detached((const __u8 *)root, 64, signature, size,
+ &current->certificates[i].parsed)) {
+ ret = 0;
+ break;
+ }
+ }
+ xfree(signature, size);
+ return ret;
+}
+
static int load_runtime_config(bool trusted_boot)
{
struct stat root;
int fd, ret;
+ size_t i;
if (!trusted_boot) {
ret = image_guards_ready();
@@ -284,6 +365,7 @@ static int load_runtime_config(bool trusted_boot)
fd = open_runtime_file(RUNTIME_CONF_PATH, root.st_dev);
if (fd < 0)
return fd;
+ image.bootstrap.n_certificates = 0;
ret = image_bootstrap_read_fd(fd, &image.bootstrap, false);
if (!ret)
ret = config_load_fd(&image.bootstrap_config, fd,
@@ -291,19 +373,21 @@ static int load_runtime_config(bool trusted_boot)
close(fd);
if (ret)
return ret;
- if (!image.bootstrap.config[0] || !image.bootstrap.certificate[0] ||
+ if (!image.bootstrap.config[0] || !image.bootstrap.n_certificates ||
!image.bootstrap.have_pcr)
return -EINVAL;
ret = image_config_set(&image.bootstrap_config, -1);
if (ret)
return ret;
- fd = open_runtime_file(image.bootstrap.certificate, root.st_dev);
- if (fd < 0)
- return fd;
- if (image.certificate_fd >= 0)
- close(image.certificate_fd);
- image.certificate_fd = fd;
+ close_config_certificates();
+ for (i = 0; i < image.bootstrap.n_certificates; i++) {
+ ret = read_config_certificate(i, root.st_dev);
+ if (ret) {
+ close_config_certificates();
+ return ret;
+ }
+ }
fd = open_runtime_file(RUNTIME_CERT_PATH, root.st_dev);
if (fd < 0)
@@ -313,7 +397,7 @@ static int load_runtime_config(bool trusted_boot)
if (ret)
return ret;
- /* The verified config certificate stays open through key enrollment. */
+ /* Keep the certificates read from the verified runtime for this command. */
return 0;
}
@@ -490,11 +574,14 @@ static int remove_candidate(struct dm_verity *device)
return ret;
}
-static int candidate_keys(int fd)
+static noinline_for_stack int candidate_keys(int fd, bool enrolled)
{
+ struct trusted_set set = {};
int ret;
- ret = keys_validate_image(fd);
+ ret = keys_validate_image_set(RUNTIME_CERT_PATH, fd, &set);
+ if (!ret && enrolled)
+ ret = keys_check_image_set(&set);
if (ret == -ENOKEY)
pr_err("image: BPF signer was not enrolled at boot; "
"reboot with the new trusted key set required");
@@ -529,9 +616,10 @@ static int mount_candidate(struct image_context *current)
static int prepare_config(struct image_context *current,
const struct config_update_target *target,
- bool trusted_boot)
+ enum config_prepare purpose)
{
struct dm_verity *device = &current->candidate_device;
+ bool trusted_boot = purpose == CONFIG_PREPARE_BOOT;
bool created = false;
int ret, cleanup;
char name[128];
@@ -548,6 +636,9 @@ static int prepare_config(struct image_context *current,
return ret;
if (memcmp(target->root_hash, current->candidate.image.root_hash, 32))
return -EKEYREJECTED;
+ ret = verify_config_root(&current->candidate, current);
+ if (ret)
+ return ret;
ret = mapping_name(target->root_hash, name);
if (ret)
return ret;
@@ -573,7 +664,8 @@ static int prepare_config(struct image_context *current,
if (!ret)
ret = image_config_validate(current->candidate_fd);
if (!ret && !trusted_boot)
- ret = candidate_keys(current->candidate_fd);
+ ret = candidate_keys(current->candidate_fd,
+ purpose == CONFIG_PREPARE_UPDATE);
out:
if (ret && created) {
close_candidate();
@@ -625,7 +717,7 @@ static int activate_config(struct image_context *current, bool boot)
static int prepare_update(void *ctx,
const struct config_update_target *target)
{
- return prepare_config(ctx, target, false);
+ return prepare_config(ctx, target, CONFIG_PREPARE_UPDATE);
}
static int activate_update(void *ctx,
@@ -679,6 +771,8 @@ static int boot_target(struct config_update_target *target)
{
struct config_update_record previous;
struct config_image_open opened;
+ struct config_update_target staged;
+ __u32 reset, restart;
const char *prefix;
bool selected;
int ret;
@@ -688,6 +782,18 @@ static int boot_target(struct config_update_target *target)
prefix = selected ? previous.target.prefix : image.bootstrap.config;
if (ret && ret != -ENOENT)
return ret;
+ if (selected) {
+ ret = tpm_boot_identity(image.tpm, &reset, &restart);
+ if (!ret)
+ ret = config_update_staged(&image.update, &previous,
+ reset, restart, &staged);
+ if (ret < 0)
+ return ret;
+ if (ret > 0) {
+ *target = staged;
+ return 0;
+ }
+ }
ret = config_image_open(prefix, &opened);
if (ret)
return ret;
@@ -708,26 +814,27 @@ static int boot_keys_error(const char *step, int ret)
return ret;
}
-/*
- * The kernel trusts every key in the sealed keyring for config roots, so
- * whether init sealed it now or earlier this boot, it must hold exactly
- * the config certificate.
- */
-static int seal_config_key(key_serial_t ring, const __u8 *der, size_t size)
+static int enroll_config_keys(void)
{
- struct keyring_cert cert = { .der = der, .len = size };
- key_serial_t key;
+ struct keyring_cert certs[KEYS_MAX];
+ bool added = false;
+ key_serial_t ring, key;
+ size_t i;
int ret;
- key = keyring_dm_verity_add_cert(der, size);
- if (key < 0 && key != -EPERM && key != -EACCES)
- return boot_keys_error("add config verification certificate",
- (int)key);
- if (key < 0 && keyring_holds_exactly(ring, NULL, 0) == 1)
- return boot_keys_error("dm-verity keyring sealed empty at boot; "
- "boot with dm_verity.keyring_unsealed=1",
- -ENOKEY);
- if (key >= 0) {
+ ring = keyring_dm_verity_serial();
+ if (ring < 0)
+ return boot_keys_error("lookup dm-verity keyring", (int)ring);
+ for (i = 0; i < image.bootstrap.n_certificates; i++) {
+ struct config_certificate *cert = &image.certificates[i];
+
+ certs[i] = (struct keyring_cert){ .der = cert->der, .len = cert->size };
+ key = keyring_dm_verity_add_cert(cert->der, cert->size);
+ if (key < 0 && key != -EPERM && key != -EACCES)
+ return boot_keys_error("add config verification certificate", (int)key);
+ added |= key >= 0;
+ }
+ if (added) {
ret = keyring_dm_verity_seal();
if (ret == -EEXIST)
return boot_keys_error("seal dm-verity keyring restricted "
@@ -736,36 +843,17 @@ static int seal_config_key(key_serial_t ring, const __u8 *der, size_t size)
if (ret)
return boot_keys_error("seal dm-verity keyring", ret);
}
- ret = keyring_holds_exactly(ring, &cert, 1);
- if (ret <= 0)
- return boot_keys_error("check dm-verity keyring holds only the "
- "config certificate",
- ret ? ret : -EKEYREJECTED);
+ if (!added && keyring_holds_exactly(ring, NULL, 0) == 1)
+ return boot_keys_error("dm-verity keyring sealed empty at boot; "
+ "boot with dm_verity.keyring_unsealed=1",
+ -ENOKEY);
+ ret = keyring_holds_exactly(ring, certs, image.bootstrap.n_certificates);
+ if (ret != 1)
+ return boot_keys_error("check dm-verity verification keys",
+ ret < 0 ? ret : -EKEYREJECTED);
return 0;
}
-static int enroll_config_key(void)
-{
- __u8 *der = NULL;
- key_serial_t ring;
- size_t size = 0;
- int ret;
-
- ret = image.certificate_fd < 0 ? -EBADF :
- keys_read_der_fd(image.certificate_fd, &der, &size);
- if (ret)
- return boot_keys_error("read config verification certificate", ret);
- ring = keyring_dm_verity_serial();
- if (ring < 0) {
- ret = (int)ring;
- xfree(der, size);
- return boot_keys_error("lookup dm-verity keyring", ret);
- }
- ret = seal_config_key(ring, der, size);
- xfree(der, size);
- return ret;
-}
-
/* The authenticated initrd validates the boot set before installing guards. */
int image_boot_keys(struct trusted_set *set)
{
@@ -778,7 +866,7 @@ int image_boot_keys(struct trusted_set *set)
ret = mount_runtime(true);
if (ret)
return boot_keys_error("mount runtime", ret);
- ret = enroll_config_key();
+ ret = enroll_config_keys();
if (ret)
return boot_keys_error("enrol config certificate", ret);
ret = open_update();
@@ -787,7 +875,7 @@ int image_boot_keys(struct trusted_set *set)
ret = boot_target(&image.boot_target);
if (ret)
return boot_keys_error("select boot config", ret);
- ret = prepare_config(&image, &image.boot_target, true);
+ ret = prepare_config(&image, &image.boot_target, CONFIG_PREPARE_BOOT);
if (ret)
return boot_keys_error("prepare boot config", ret);
ret = keys_validate_image_set(RUNTIME_CERT_PATH,
@@ -823,9 +911,7 @@ int image_boot_keys_close(void)
if (image.candidate_fd >= 0)
close(image.candidate_fd);
image.candidate_fd = -1;
- if (image.certificate_fd >= 0)
- close(image.certificate_fd);
- image.certificate_fd = -1;
+ close_config_certificates();
if (umount(CONFIG_CANDIDATE_DIR) && errno != EINVAL &&
errno != ENOENT)
ret = -errno;
@@ -1021,8 +1107,8 @@ int image_config_state(__u8 root[32])
int image_status(bool json)
{
- struct config_update_record record;
- char buffer[512], root[65];
+ struct config_update_record record, staged;
+ char buffer[768], root[65], next_root[65];
struct json_emit emit = {
.buf = buffer,
.cap = sizeof(buffer),
@@ -1034,10 +1120,19 @@ int image_status(bool json)
ret = config_update_read(&image.update, &record);
if (ret)
return ret;
+ ret = config_update_stage_read(&image.update, &staged);
+ if (ret && ret != -ENOENT)
+ return ret;
+ if (ret == -ENOENT)
+ next_root[0] = 0;
+ else
+ hex_encode(staged.target.root_hash, 32, next_root);
hex_encode(record.target.root_hash, 32, root);
ret = record.pending ? -EINPROGRESS : current_config();
if (!json) {
printf("%-22s %s\n", "Config root hash:", root);
+ printf("%-22s %s\n", "Next boot root hash:",
+ next_root[0] ? next_root : "none");
printf("%-22s %d\n", "PCR:", record.pcr);
printf("%-22s %lld\n", "Sequence:", (long long)record.sequence);
printf("%-22s %lld\n", "TPM reset count:",
@@ -1051,6 +1146,10 @@ int image_status(bool json)
}
json_obj_open(&emit);
json_kv_string(&emit, "root_hash", root);
+ if (next_root[0])
+ json_kv_string(&emit, "next_boot_root_hash", next_root);
+ else
+ json_kv_null(&emit, "next_boot_root_hash");
json_kv_int(&emit, "pcr", record.pcr);
json_kv_int(&emit, "sequence", record.sequence);
json_kv_int(&emit, "reset_count", record.reset_count);
@@ -1074,9 +1173,7 @@ void image_leave(void)
config_update_close(&image.update);
tpm_close(image.tpm);
image.tpm = NULL;
- if (image.certificate_fd >= 0)
- close(image.certificate_fd);
- image.certificate_fd = -1;
+ close_config_certificates();
memzero_explicit(&image.bootstrap_config, sizeof(image.bootstrap_config));
}
@@ -1091,9 +1188,38 @@ int image_update(const char *prefix)
if (!ret)
ret = mkdir_owned(IMAGE_CACHE_DIR);
if (!ret)
- ret = image_cache_fetch(prefix, &target);
+ ret = image_cache_fetch(prefix, &target, verify_config_root, &image);
if (!ret)
ret = config_update_begin(&image.update, &target,
image.bootstrap.pcr);
return ret;
}
+
+int image_stage(const char *prefix)
+{
+ struct config_update_target target = {};
+ int ret;
+
+ if (image.update.lock_fd < 0)
+ return -ENODEV;
+ ret = current_config();
+ if (!ret)
+ ret = mkdir_owned(IMAGE_CACHE_DIR);
+ if (!ret)
+ ret = image_cache_fetch(prefix, &target, verify_config_root, &image);
+ if (!ret)
+ ret = prepare_config(&image, &target, CONFIG_PREPARE_STAGE);
+ if (!ret)
+ ret = config_update_stage(&image.update, &target);
+ return ret;
+}
+
+int image_stage_cancel(void)
+{
+ int ret;
+
+ if (image.update.lock_fd < 0)
+ return -ENODEV;
+ ret = current_config();
+ return ret ? ret : config_update_clear_staged(&image.update);
+}
diff --git a/util/image_runtime.h b/util/image_runtime.h
index 2f021ca3..905e9bf2 100644
--- a/util/image_runtime.h
+++ b/util/image_runtime.h
@@ -22,6 +22,8 @@ int image_boot_complete(void);
int image_enter(const char *command, int argc, const char **argv);
void image_leave(void);
int image_update(const char *prefix);
+int image_stage(const char *prefix);
+int image_stage_cancel(void);
int image_status(bool json);
/*
diff --git a/util/keys.c b/util/keys.c
index 46dd4cc8..fb68fe6b 100644
--- a/util/keys.c
+++ b/util/keys.c
@@ -272,31 +272,45 @@ int keys_vouch_payload(const __u8 *der, size_t der_sz,
return 0;
}
+int keys_verify_signature(const struct trusted_set *set,
+ const __u8 *payload, size_t payload_sz,
+ const __u8 *sig, size_t sig_sz,
+ __u8 signer[32])
+{
+ size_t i;
+
+ for (i = 0; i < set->n; i++) {
+ struct cert cert = {};
+ int ret;
+
+ ret = keys_cert_read(&set->certs[i], &cert);
+ if (ret)
+ return ret;
+ ret = verify_detached(payload, payload_sz, sig, sig_sz, &cert);
+ cert_free(&cert);
+ if (!ret) {
+ if (signer)
+ memcpy(signer, set->certs[i].fingerprint, 32);
+ return 0;
+ }
+ }
+ return -EKEYREJECTED;
+}
+
int keys_verify_vouch(const struct trusted_set *set,
const __u8 *der, size_t der_sz,
const __u8 *sig, size_t sig_sz,
__u8 voucher[32])
{
- size_t payload_sz = 0, i;
+ size_t payload_sz = 0;
__u8 *payload = NULL;
int ret;
ret = keys_vouch_payload(der, der_sz, &payload, &payload_sz);
if (ret)
return ret;
- ret = -EKEYREJECTED;
- for (i = 0; i < set->n && ret; i++) {
- struct cert cert = {};
-
- if (keys_cert_read(&set->certs[i], &cert))
- continue;
- if (verify_detached(payload, payload_sz, sig, sig_sz,
- &cert) == 0) {
- memcpy(voucher, set->certs[i].fingerprint, 32);
- ret = 0;
- }
- cert_free(&cert);
- }
+ ret = keys_verify_signature(set, payload, payload_sz, sig, sig_sz,
+ voucher);
xfree(payload, payload_sz);
return ret;
}
diff --git a/util/keys.h b/util/keys.h
index 802d0f1d..659c51a0 100644
--- a/util/keys.h
+++ b/util/keys.h
@@ -106,10 +106,15 @@ bool keys_is_revoked(const char *revoked_dir,
int keys_vouch_payload(const __u8 *der, size_t der_sz,
__u8 **out, size_t *out_sz);
+/* Verify a detached signature under a member; signer may be NULL. */
+int keys_verify_signature(const struct trusted_set *set,
+ const __u8 *payload, size_t payload_sz,
+ const __u8 *sig, size_t sig_sz,
+ __u8 signer[32]);
+
/*
* Whether a member of the set signed the vouch for this certificate:
- * 0 with the member's fingerprint in voucher, -EKEYREJECTED when none
- * did.
+ * 0 with the member's fingerprint in voucher, -EKEYREJECTED when none did.
*/
int keys_verify_vouch(const struct trusted_set *set,
const __u8 *der, size_t der_sz,