Skip to content

eBPF-based security platform

Documentation: try to improve tpm.rst

Leonard Cohnen5b82cc887b39
diff --git a/Documentation/concepts/background/tpm.rst b/Documentation/concepts/background/tpm.rst
index c11219d8..60ab63d0 100644
--- a/Documentation/concepts/background/tpm.rst
+++ b/Documentation/concepts/background/tpm.rst
@@ -8,19 +8,18 @@
TPM 2.0 and how shirudo uses it
===============================
-A target's TPM 2.0 does two jobs for shirudo. It holds a per-boot
-measurement register that records every change to the target's BPF
-state, and it signs evidence about that register and the boot PCRs, so
-that an operator can check a target without taking its word for
-anything. This page explains the parts of TPM 2.0 those jobs rely on
-and, for each, what shirudo does with it. The event formats and the
-eventlog are in :doc:`/internals/measurement-register`, the
+A :term:`target`'s TPM 2.0 does two jobs for shirudo. It holds a per-boot
+:term:`measurement register` that records every change to the
+target's BPF state, and it signs evidence about that register and
+the boot PCRs, so that an :term:`operator` can cryptographically verify the
+target's state.
+This page explains how shirudo uses the TPM. The event formats and the
+:term:`eventlog` are in :doc:`/internals/measurement-register`, the
verification procedure in :doc:`/operate/attest`.
Every target needs a TPM 2.0 with an active SHA-256 PCR bank. There is
-no unmeasured mode. The operator host never talks to a TPM: it
-computes and checks everything in software. Table 1 lists the TPM
-objects shirudo uses.
+no unmeasured mode. The :term:`operator host` does not use a TPM.
+Table 1 lists the TPM objects shirudo uses.
.. list-table:: Table 1. TPM objects shirudo uses
:header-rows: 1
@@ -29,28 +28,29 @@ objects shirudo uses.
* - Object
- Kind
- Purpose
- * - Measurement register
- - NV extend index ``0x01818E00``, owner hierarchy
- - Records ``init``, upatch loads and unloads, tree operations and
- key revocations. Clears at every TPM reset and TPM restart.
- * - NV writer key
+ * - :term:`Measurement register <measurement register>`
+ - :term:`NV extend index` ``0x01818E00``, owner hierarchy
+ - Records ``init``, :term:`upatch` loads and unloads, tree operations and
+ key :term:`revocations <revocation>`. Clears at every TPM reset and
+ TPM restart.
+ * - :term:`NV writer key`
- RSA-3072 primary key, owner hierarchy
- Authorizes each extension of the register. A new key every
host boot.
- * - Attestation key
+ * - :term:`Attestation key <attestation key>`
- ECC NIST P-256 primary key, endorsement hierarchy
- Signs quotes and NV certifications. The same key for the life
of the TPM's endorsement seed.
- * - Endorsement key
+ * - :term:`Endorsement key <endorsement key>`
- RSA 2048 or ECC NIST P-256 primary key, endorsement hierarchy
- - Ties the attestation key to a certified TPM through credential
+ - Ties the :term:`attestation key` to a certified TPM through credential
activation.
* - PCR 9
- SHA-256 bank
- - Carries the register's anchor.
+ - Carries the register's :term:`anchor`.
* - Config PCR
- SHA-256 bank, chosen by ``config.pcr``
- - Records config image activations, see
+ - Records :term:`config image` activations, see
:doc:`/internals/config-images`.
Roots of trust
@@ -63,15 +63,11 @@ machine. It keeps keys and registers in shielded memory that only its
own commands can reach, and it never releases a private key it
generated.
-The TCG specification names three roots of trust that a trusted
-platform needs. The root of trust for measurement is the first code
-that runs after reset; it measures the next stage and starts the chain
-that :doc:`boot` describes. The TPM is the root of trust for storage,
-because it keeps measurements and keys out of reach of software, and
-the root of trust for reporting, because it signs statements about
-what it holds. shirudo trusts the TPM in both roles. The software path
-between shirudo and the TPM is a different matter, which the limits at
-the end of this page cover.
+Early boot stages hash the code and configuration they load and extend
+those hashes into the TPM's PCRs; see :doc:`boot`. The TPM protects the
+accumulated measurement values and signs evidence about them on request.
+shirudo relies on the boot chain to measure what actually runs, and on
+the TPM to preserve and report the results.
Hierarchies and seeds
---------------------
@@ -93,9 +89,10 @@ seed that never leaves the TPM and its own authorization:
- The null hierarchy has a seed that the TPM replaces at every reset.
Its keys last until the next reset.
-shirudo uses the owner hierarchy for the measurement register and the
-NV writer key, and the endorsement hierarchy for the attestation key
-and the endorsement key. It never uses the platform or null
+shirudo uses the owner hierarchy for the :term:`measurement register` and the
+:term:`NV writer key`, and the endorsement hierarchy for the
+:term:`attestation key` and the :term:`endorsement key`. It never uses the
+platform or null
hierarchies. When the TPM has an owner authorization, shirudo takes it
from ``tpm.owner_auth`` in its authenticated configuration. The
endorsement authorization must be empty: shirudo has no setting for
@@ -119,13 +116,14 @@ two parties that agree on a Name agree on the key and on what the TPM
allows it to do.
shirudo keeps no persistent objects in the TPM. Each command creates
-the keys it needs and flushes them before it exits. The attestation
-key's template is fixed, so its Name stays the same as long as the
-endorsement seed does, and an operator can pin it once at enrollment.
-The NV writer key's ``unique`` field is 32 random bytes that ``init``
+the keys it needs and flushes them before it exits. The
+:term:`attestation key`'s template is fixed, so its Name stays the same as
+long as the endorsement seed does, and an :term:`operator` can pin it once
+at enrollment.
+The :term:`NV writer key`'s ``unique`` field is 32 random bytes that ``init``
draws at every host boot, so every boot has its own writer key.
``init`` freezes those bytes and the resulting public modulus in
-shirudo's identity map, a BPF map nothing can change for the rest of
+shirudo's :term:`identity map`, a BPF map nothing can change for the rest of
the boot. Every later command creates the key again from the frozen
bytes and refuses one whose modulus differs. A ``TPM2_Clear`` replaces
the owner seed, so the key no longer matches and extensions fail
@@ -134,7 +132,7 @@ closed.
Endorsement key and certificate
-------------------------------
-The endorsement key (EK) is the TPM's identity. It is a primary key in
+The :term:`endorsement key` (EK) is the TPM's identity. It is a primary key in
the endorsement hierarchy created from a template that the TCG
defines, so anyone who knows the template knows which key a given TPM
derives. The manufacturer creates the key at production, signs a
@@ -151,32 +149,33 @@ described below, proves where another key lives.
``shirudo attest`` reads the EK certificate, the ECC one first, and
creates the EK of the certificate's type from the TCG default
-template, or the ECC EK when the TPM holds no certificate. The evidence
-carries the EK's public area and the certificate. ``shirudo attest
-challenge`` checks that the public area is the TCG default template
-under the endorsement policy and that the certificate describes that
-key. With ``--ek-ca`` it also checks that the certificate chains to
-the issuers given. Otherwise the operator pins the EK with
-``--ek-name``, or accepts it unvouched with ``--trust-presented-ek``.
+template. If no certificate is found it creates the default ECC EK.
+The :term:`evidence` carries the EK's public area and the certificate.
+``shirudo attest challenge`` checks that the public area is the
+TCG default template under the endorsement policy and that the
+certificate describes that key. With ``--ek-ca`` it also checks
+that the certificate chains to those issuers. Otherwise the
+:term:`operator` pins the EK with ``--ek-name``, or accepts any EK
+with ``--trust-presented-ek``.
Attestation keys
----------------
A key that signs whatever a caller asks would make a quote worthless,
because software could have it sign a quote it made up. A restricted
-signing key avoids this. The TPM signs with it only structures the TPM
-built itself, such as quotes and certifications, which start with the
-value ``TPM_GENERATED_VALUE`` (``0xFF544347``), and it refuses to sign
+signing key can only sign structures the TPM
+built itself, such as PCR quotes, which start with the
+value ``TPM_GENERATED_VALUE`` (``0xFF544347``). It refuses to sign
outside data that could pass for one. A structure that starts with
that value and carries a valid signature by a restricted key came from
the TPM that holds the key.
-shirudo's attestation key (AK) is an ECC NIST P-256 primary key in the
+shirudo's :term:`attestation key` (AK) is an ECC NIST P-256 primary key in the
endorsement hierarchy that signs with ECDSA and SHA-256. Its attributes
are ``fixedTPM``, ``fixedParent``, ``sensitiveDataOrigin``,
``userWithAuth``, ``restricted`` and ``sign``, and it has no
authorization value and no policy. ``init`` records its Name in the
-identity map. Before each write to the register, shirudo creates the
+:term:`identity map`. Before each write to the register, shirudo creates the
AK again and compares its Name with the recorded one, which detects a
different TPM behind the device path. ``attest verify`` checks that
the AK's public area has these attributes, that the Name matches the
@@ -197,10 +196,12 @@ applications, nothing else does. Any process that can send commands
to the TPM can read the PCRs and extend the ones the operating system
uses. :doc:`boot` lists who extends which PCR during a boot.
-shirudo works in the SHA-256 bank only, and ``init`` refuses a TPM
+shirudo uses the SHA-256 bank only, and ``init`` refuses a TPM
whose SHA-256 bank lacks PCR 9 or PCR 11. ``init`` reads PCRs 9 and 11
-when it binds the register and extends PCR 9 with the register's
-anchor. Config image activation extends the config PCR.
+when it binds the register and extends PCR 9 with the
+:term:`anchor`. When shirudo activates a :term:`config image`,
+it extends the PCR selected by ``config.pcr`` with a measurement
+identifying that image.
``shirudo attest`` quotes PCRs 0 to 7, 9 and 11 to 15 by default, and
the config PCR as well when a config image is active.
@@ -210,26 +211,34 @@ NV indices and the extend type
Besides PCRs, a TPM has NV indices: storage locations that an owner
defines with ``TPM2_NV_DefineSpace``. Each has a handle, a size,
attributes, an authorization value and a policy. Their types include
-ordinary data, counters, bit fields and extend indices. An extend
-index behaves like a PCR: ``TPM2_NV_Extend`` sets it to the hash of
+ordinary data, counters, bit fields and
+NV extend index.
+An :term:`NV extend index` behaves like a PCR:
+``TPM2_NV_Extend`` sets it to the hash of
the old value and the new data. The first extension after the index
is defined starts from a zero digest and sets the attribute
``TPMA_NV_WRITTEN``.
The attributes decide who may read and write an index and when it
-clears. With ``TPMA_NV_ORDERLY`` the TPM keeps the value in RAM and
-saves it only at an orderly shutdown. Together with
-``TPMA_NV_CLEAR_STCLEAR`` the index loses its value and
-``TPMA_NV_WRITTEN`` at every TPM reset and TPM restart, so it starts
-over with each boot, like a PCR.
-
-An index's Name is the hash of its public area: handle, name
-algorithm, attributes, policy and size. ``TPMA_NV_WRITTEN`` is one of
+clears. ``TPMA_NV_CLEAR_STCLEAR`` clears the index's ``TPMA_NV_WRITTEN``
+flag at every TPM reset and restart. For an extend index, the next
+permitted extension starts from a zero digest.
+``TPMA_NV_ORDERLY`` lets extensions update the value in TPM RAM without
+requiring a nonvolatile data write after every operation. This reduces
+persistent-storage writes for a history that only needs to last for the
+current boot.
+
+An index's Name is the hash of its public area: handle, hash algorithm
+identifier, attributes, policy and size. ``TPMA_NV_WRITTEN`` is one of
the attributes, so the Name changes at the first write. Unlike a PCR,
an index can be deleted with ``TPM2_NV_UndefineSpace`` and defined
again by anyone who satisfies the owner authorization. A recreated
-index starts empty. This is why systemd and shirudo record an
-index's Name in a PCR, which cannot be deleted.
+index starts empty. This is why shirudo extends PCR 9 with the
+:term:`anchor`, which incorporates the :term:`measurement register`'s
+Name after its first write. Deleting the NV index does not remove
+that anchor from PCR 9. A deletion and recreation of the NV index
+with the same policy cannot be initialized since the policy requires
+the old PCR 9 value which shirudo extended with the anchor.
shirudo's register is the index ``0x01818E00``, which a build can
change with ``SHIRUDO_NV_INDEX``. It holds one SHA-256 digest and has
@@ -238,112 +247,111 @@ the attributes ``0x0E060048``: ``TPM2_NT_EXTEND``,
``TPMA_NV_NO_DA``, ``TPMA_NV_ORDERLY`` and ``TPMA_NV_CLEAR_STCLEAR``.
Its authorization value is empty, so anyone can read it, and only a
policy session can write it. It is an NV index rather than a PCR
-because a typical Linux system has no PCR left over, and PCR 23 can be
-reset by any application.
+because a typical Linux system has no PCR that are not used already.
Authorization and sessions
--------------------------
-Every command that uses a protected entity carries an authorization,
-in one of three forms.
-
-A password authorization carries the entity's authorization value in
-the command, in plaintext. Anything that sees the command sees the
-password.
-
-An HMAC session proves knowledge of the authorization value without
-sending it: the caller computes an HMAC over the command and over
-nonces from both sides, and the TPM answers with an HMAC over its
-response. A session is salted when the caller encrypts a random salt to
-a TPM key it trusts. Only that TPM can recover the salt, so only it can
-compute the session key and the HMACs on its responses. A session is
-bound when it mixes in the authorization value of a chosen entity. A
-session that is neither has no session key. Sessions can also encrypt
-the first parameter of commands and responses.
-
-A policy session authorizes by conditions instead of a secret. The
-caller runs policy assertions on the session, and each one that holds
-extends the session's policy digest. The TPM allows the command only
-when the final digest equals the entity's policy. The assertions
-shirudo uses are:
-
-- ``TPM2_PolicyPCR``: the selected PCRs hold the values whose hash the
- policy contains.
-- ``TPM2_PolicyNvWritten``: the index has, or has not, been written.
-- ``TPM2_PolicyOR``: the digest so far equals one of the listed branch
- digests.
-- ``TPM2_PolicySigned``: a key with a given Name signed the hash of
- the session's TPM nonce, an expiration, a command parameter hash
- (cpHash) and a policy reference. The nonce ties the signature to this
- session, and the cpHash restricts it to one command with exactly
- these parameters.
-- ``TPM2_PolicyCommandCode``: the session may authorize only this
- command.
-- ``TPM2_PolicySecret``: the caller satisfies another entity's
- authorization. The EK's policy uses it.
-
-``TPM2_PolicyGetDigest`` returns the session's digest so far, which
-lets a caller compare it with the digest it computed.
-
-shirudo uses password authorizations and policy sessions, and no HMAC
-sessions. Its policy sessions are unsalted and unbound and encrypt no
-parameters. The owner authorization, when set, travels as a password.
+shirudo uses password authorizations for operations such as creating
+TPM keys, defining or deleting the :term:`measurement register`, reading
+it and signing. The owner authorization comes from ``tpm.owner_auth``;
+register reads and signing use empty authorization values. A password
+authorization carries that value in plaintext in the command.
+
+Extending the register requires a policy session instead. This is
+temporary state inside the TPM that shirudo updates with policy commands.
+The TPM checks that the session's policy digest matches the register's
+policy and that its restrictions hold when executing the extension.
+shirudo uses these commands:
+
+- ``TPM2_PolicyNvWritten`` requires an unwritten index for the first
+ extension, or an already written index for later extensions.
+- ``TPM2_PolicyPCR`` ties the first extension to the values of PCRs 9
+ and 11 recorded at initialization.
+- ``TPM2_PolicyOR`` accepts either the first-write or the already-written
+ branch.
+- ``TPM2_PolicySigned`` requires the :term:`NV writer key` to sign an
+ authorization tied to the session's nonce and a command hash. This
+ SHA-256 hash covers the command code, the target index's Name and the
+ event data, so the authorization cannot be reused for a different index
+ or event.
+- ``TPM2_PolicyCommandCode`` restricts the authorized command to
+ ``TPM2_NV_Extend``.
+
+Before submitting the extension, shirudo calls ``TPM2_PolicyGetDigest``
+and compares the session's digest with the policy it computed in software.
+The next section explains how these conditions protect the register.
+
+Credential activation uses a separate policy session for the
+:term:`endorsement key`. shirudo satisfies that policy with
+``TPM2_PolicySecret``, using the empty endorsement-hierarchy authorization.
+
+These sessions do not encrypt command parameters or authenticate command
+responses. The TPM signatures on attestation :term:`evidence` are separate
+from session authentication. `Limits`_ describes the transport risks.
Register binding
----------------
-The register has to record what shirudo did and nothing else. Root on
-the target must not be able to add events of its own, delete the
-register and start a fresh history, or bind the register later from a
-state it chose. An NV index alone stops none of this: root can define
+The register records what shirudo did. Root on
+the :term:`target` must not be able to add events of its own, delete the
+register and start a fresh history, or initialize the register later
+in the boot process. An NV index alone stops none of this: root can define
an index, write it and delete it. We combine the policy assertions
above, the boot phases that :doc:`boot` describes and an LSM hook.
-Figure 1 shows how ``init`` binds the register from the initrd.
+:ref:`Figure 1 <tpm-register-binding-figure>` shows how ``init`` binds the
+register from the initrd.
+
+.. _tpm-register-binding-figure:
.. figure:: /images/background-tpm-register.svg
:alt: PCR 9 and PCR 11 values enter the write policy, the policy
- defines the NV index, and the index's written Name is
- extended into PCR 9 as the anchor.
+ defines the NV index, and its public fields after the first write
+ determine the anchor digest extended into PCR 9.
Figure 1. Binding the register: (1) read PCRs 9 and 11, (2) define
the index with the write policy, (3) write the first event through
- the init branch, (4) extend PCR 9 with the anchor.
-
-1. ``init`` reads PCRs 9 and 11. It computes the write policy:
- ``TPM2_PolicyOR`` of a written branch, ``TPM2_PolicyNvWritten(YES)``,
- and an init branch, ``TPM2_PolicyNvWritten(NO)`` followed by
- ``TPM2_PolicyPCR`` over PCRs 9 and 11 at the values it read; then
- ``TPM2_PolicySigned`` by the NV writer key with the policy
- reference ``shirudo-nv-writer-v1``; then
- ``TPM2_PolicyCommandCode`` for ``TPM2_NV_Extend``. It also computes
- the index's Names before and after the first write.
-2. It defines the index with that policy, replacing any index at the
- handle that is written or has another Name, and refuses with
- ``EPROTO`` if the Name the TPM reports differs from the computed
- one.
-3. It extends the index with the init event through the init branch.
- The TPM evaluates each assertion, the writer key signs the session
- nonce and the cpHash of this ``TPM2_NV_Extend``, and
- ``TPM2_PolicyGetDigest`` confirms that the session reached the
- computed policy. The index is now written and has its written Name.
-4. It extends PCR 9 with the SHA-256 of
+ the init branch, (4) extend PCR 9 with the :term:`anchor`.
+
+1. Compute the policy. ``shirudo init`` reads PCRs 9 and 11 and
+ computes a policy that requires those values for the first write.
+ Both the first and later writes require the :term:`NV writer key` to
+ authorize the exact extension command. It also computes the index's
+ expected Names before and after the first write.
+2. Define and check the index. ``init`` defines it with that policy,
+ replacing any index at the handle that is written or has another Name.
+ It refuses with ``EPROTO`` if the Name the TPM reports differs from the
+ expected one.
+3. Write the initial event. ``init`` obtains the writer key's signature
+ and checks the session's policy digest before submitting the first
+ extension. The TPM enforces the policy and records the init event.
+ This sets ``TPMA_NV_WRITTEN``, changing the index's Name.
+4. Record the :term:`anchor`. ``init`` extends PCR 9 with the SHA-256 of
``nvpcr-init:shirudo:0x1818e00:<written-name>``, systemd's anchor
format, where ``<written-name>`` is the index's written Name in
- hex.
+ lowercase ASCII hex.
+
+The Name contains the two-byte SHA-256 algorithm identifier ``0x000B``
+followed by the SHA-256 hash of the index's public fields. Those fields
+use TPM wire encoding: integers are big-endian, and the 32-byte policy
+digest is preceded by its two-byte length, ``0x0020``. The hash includes
+the complete attribute bitmask, with ``TPMA_NV_WRITTEN`` set after the
+first write.
After step 4, PCR 9 no longer holds the value the init branch
requires, and once systemd measures ``leave-initrd``, PCR 11 does not
either. Nothing can satisfy the init branch again before the next TPM
reset, so an index that is deleted and recreated under the same policy
can never be written. An index recreated under another policy has
-another Name, which matches neither the anchor in PCR 9 nor the record
+another Name, which matches neither the :term:`anchor` in PCR 9 nor the record
``init`` kept.
Every later extension goes through the written branch, which also
-requires the writer key's signature over the session nonce and the
-cpHash of that one command. Before it extends, shirudo checks that the
-live index carries the Name and policy ``init`` recorded, that the TPM
+requires the writer key's signature over the session nonce and a SHA-256
+hash covering the extension command code, the index's Name and the event
+data. Before it extends, shirudo checks that the live index carries the
+Name and policy ``init`` recorded, that the TPM
reports the recorded reset count, and that the writer key it creates
from the frozen bytes has the recorded modulus.
@@ -353,18 +361,19 @@ the key could ask the TPM to sign. An LSM hook in the kernel keeps
them out. The companion kernel patch
``kernel/0002-tpm-Let-LSMs-inspect-userspace-commands.patch`` adds an
LSM hook, ``tpm_command``, that sees every command written to
-``/dev/tpm0`` or ``/dev/tpmrm0`` before the driver sends or queues it,
-whichever process holds the descriptor. shirudo's ``lsm/tpm_command``
+``/dev/tpm0`` or ``/dev/tpmrm0`` before the driver sends or queues it.
+shirudo's ``lsm/tpm_command``
program refuses ``TPM2_NV_Extend`` of the frozen index to any task
-without runtime authority. It also refuses, to every task, a command
+without :term:`runtime authority`. It also refuses, to every task, a command
too short to carry a command code and a ``TPM2_NV_Extend`` too short to
-name its index. Each refusal counts as ``TpmExtend``. All other
+name its index. Each rejection increments the
+``TpmExtend`` :term:`tamper counter`. All other
commands pass, including extensions of other NV indices, signing and
PCR extensions.
The construction follows systemd's NvPCRs, which :doc:`boot`
introduces: the same index type, the two-branch policy and the
-``nvpcr-init`` anchor. It differs in three ways. systemd's written
+``nvpcr-init`` :term:`anchor`. It differs in three ways. systemd's written
branch needs no further authorization, so anyone can append to an
NvPCR; shirudo requires a signed, command-bound authorization and the
LSM check on every write, because its events assert that an operation
@@ -372,10 +381,10 @@ happened. systemd binds the init branch to PCR 11 through a signed PCR
policy from the UKI, or through a plain ``TPM2_PolicyPCR`` on PCR 11
where none exists; shirudo binds it with a plain ``TPM2_PolicyPCR``
over PCRs 9 and 11, so the register's Name changes with the initrd and
-the UKI, and the operator pins both values with ``--expect-bind-pcr``.
+the UKI, and the :term:`operator` pins both values with ``--expect-bind-pcr``.
And the register is not a ``.nvpcr`` definition: systemd neither
initializes nor extends it, and its anchor appears in shirudo's
-eventlog, not in systemd's measurement log.
+:term:`eventlog`, not in systemd's measurement log.
Quotes and NV certification
---------------------------
@@ -389,20 +398,21 @@ and the nonce proves that it signed after the verifier asked.
``TPM2_NV_Certify`` signs the same kind of structure for an NV index,
with the index's Name, an offset and the contents.
-``shirudo attest`` reads the selected PCRs, quotes them with the
-verifier's nonce and keeps the quote only when its digest covers the
-values it read, retrying up to three times. It certifies the
-register's 32 bytes at offset 0 with the same nonce. The evidence
+``shirudo attest`` collects the selected PCR values and a TPM quote
+containing their digest and the verifier's nonce. Separately,
+it obtains a TPM-signed statement of the measurement register's
+Name and current value, using the same nonce as the PCR quote.
+The :term:`evidence`
document also carries the public areas of the AK and EK, this boot's
-eventlog records, the config history, the firmware and systemd event
-logs and the EK certificate.
+shirudo :term:`eventlog` records, the config history, the firmware
+and systemd event logs and the EK certificate.
Only the quote and the certification are signed by the TPM. The rest
-of the document is the target's own account, which ``attest verify``
+of the document is the :term:`target`'s own account, which ``attest verify``
checks against the signed values. In particular, it recomputes the
-register's Name from the PCR values and the writer key that the init
-record names. A register bound under other PCR values or with another
-writer key has another Name and fails. :doc:`/operate/attest` lists
+register's Name from the PCR values and the writer key that the
+:term:`init record` names. A register bound under other PCR values or with
+another writer key has another Name and fails. :doc:`/operate/attest` lists
the checks and the options that pin each value.
Credential activation
@@ -420,17 +430,19 @@ holding that EK can recover it, and only for a key with a given Name.
recovers a seed with the EK, checks an HMAC over the loaded key's
Name, and releases the secret only when the Name matches.
-``shirudo attest challenge`` computes the credential on the operator
-host. It draws a random 32-byte credential and a seed, which it wraps
+``shirudo attest challenge`` computes the credential on the
+:term:`operator host`. It draws a random 32-byte credential and a seed,
+which it wraps
with RSA-OAEP under the label ``IDENTITY`` for an RSA EK or derives
from an ephemeral ECDH agreement on P-256 for an ECC EK. From the seed
it derives an AES-128-CFB key and an HMAC key with the TPM's key
-derivation function. On the target, ``shirudo attest --challenge``
-satisfies the EK's policy with ``TPM2_PolicySecret`` and runs
-``TPM2_ActivateCredential``, and the evidence carries the recovered
-value. ``attest verify --expect-credential`` compares it. Together with
-the attribute checks on the AK, this shows that the key that signed
-the evidence is a restricted key fixed in the TPM that holds the EK.
+derivation function. On the :term:`target`, ``shirudo attest --challenge``
+calls ``TPM2_ActivateCredential`` to recover the challenge secret for the
+loaded AK and includes the result in the :term:`evidence` document.
+On the operator host, ``attest verify --expect-credential`` compares it.
+Together with the attribute checks on the AK, this shows that the key
+that signed the evidence is a restricted key fixed in the TPM
+that holds the EK.
Reset count and clock
---------------------
@@ -442,14 +454,14 @@ returns to zero at a TPM reset. ``TPM2_ReadClock`` reads them, and
every quote and certification carries them. For keys outside the
endorsement and platform hierarchies the TPM obfuscates the counts in
signed structures. shirudo's AK is in the endorsement hierarchy, so the
-evidence carries the real values.
+:term:`evidence` carries the real values.
-``init`` records the reset count in its eventlog record, and uses it
+``init`` records the reset count in its :term:`eventlog` record, and uses it
to decide whether it has already bound the register in this TPM
period. An extension refuses when the TPM's reset count is not the
recorded one. ``attest verify`` checks that the quote and the
certification carry the same reset count and that it is the one the
-init record names. Config activation records both counts.
+:term:`init record` names. Config activation records both counts.
Device interface
----------------
@@ -460,10 +472,12 @@ process sees the TPM's real handles and must manage its few slots for
objects and sessions itself. ``/dev/tpmrm0`` goes through the kernel's
resource manager. Any number of processes can open it, and the kernel
swaps objects and sessions in and out so that each open file sees only
-its own. The kernel's own TPM users, such as IMA and trusted keys,
+its own. The kernel's own TPM users, such as the kernel's
+Integrity Measurement Architecture (IMA) and trusted keys,
reach the TPM without either device.
-shirudo talks to the TPM through the tpm2-tss library and the TCTI
+shirudo talks to the TPM through the tpm2-tss library and the
+TPM Command Transmission Interface (TCTI)
named by ``tpm.tcti`` in its authenticated configuration,
``device:/dev/tpmrm0`` by default. While an authenticated image is
active it accepts only a ``device:`` TCTI, so its commands pass through
@@ -483,8 +497,8 @@ these.
public Name. A root process that substitutes the device can keep
shirudo's extensions from reaching the real register.
- The owner authorization travels as a password to whatever device is
- at the path, and root on the target can read it from the runtime
- image.
+ at the path, and root on the :term:`target` can read it from the
+ :term:`runtime image`.
- The ``tpm_command`` guard covers ``TPM2_NV_Extend`` of the register
only. ``TPM2_NV_UndefineSpace`` with the owner authorization and
``TPM2_PCR_Extend`` of PCR 9 or the config PCR remain open to root.
@@ -493,26 +507,26 @@ these.
boot.
- The guard sees commands written to the TPM character devices.
Kernel-internal TPM use and direct access to the TPM's bus are
- outside it, and every executable in the runtime image runs with
- runtime authority and can extend the register.
+ outside it, and every executable in the :term:`runtime image` runs with
+ :term:`runtime authority` and can extend the register.
- A TPM restart clears the register but not the reset count. ``init``
then refuses to bind the register again, and extensions fail with
``tpm_error`` until the next reboot.
- The algorithms are classical: ECDSA P-256 for the AK, RSA-3072 for
the writer key, RSA 2048 or P-256 for the EK. Version 185 of the
- TPM 2.0 library specification adds ML-DSA and ML-KEM, and shirudo
- does not use them. See :doc:`pqc`.
+ TPM 2.0 library specification adds ML-DSA and ML-KEM, but shirudo
+ does not yet use them. See :doc:`pqc`.
- An EK is only as trustworthy as its certificate chain or the
enrollment pin. Virtual TPMs usually have no EK certificate.
- ``attest verify`` warns but proceeds without ``--ak-name``, so the
- operator has to pin the AK on every verification.
+ :term:`operator` has to pin the AK on every verification.
Related
-------
- :doc:`boot` for measured boot, PCR 11 phases and NvPCRs.
-- :doc:`/internals/measurement-register` for events and the eventlog.
-- :doc:`/operate/attest` to attest a target.
+- :doc:`/internals/measurement-register` for events and the :term:`eventlog`.
+- :doc:`/operate/attest` to attest a :term:`target`.
- :doc:`/security/threat-model` for the residual risks.
- `TPM 2.0 Library specification
<https://trustedcomputinggroup.org/resource/tpm-library-specification/>`__
diff --git a/Documentation/images/background-tpm-register.svg b/Documentation/images/background-tpm-register.svg
index 3e70d04a..cd94589c 100644
--- a/Documentation/images/background-tpm-register.svg
+++ b/Documentation/images/background-tpm-register.svg
@@ -1,5 +1,5 @@
-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 400" width="760" height="400" font-family="sans-serif" role="img" aria-labelledby="t">
- <title id="t">Binding the measurement register: the PCR 9 and 11 values enter the write policy, the policy defines the NV extend index, and the index name is anchored in PCR 9</title>
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 433" width="900" height="433" font-family="sans-serif" role="img" aria-labelledby="t">
+ <title id="t">Binding the measurement register: PCRs 9 and 11 enter the write policy, and the initialized NV index's public fields determine the anchor extended into PCR 9</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">
@@ -11,16 +11,16 @@
<rect x="20" y="140" width="210" height="110" rx="6"/>
<rect x="280" y="30" width="260" height="180" rx="6"/>
<rect x="280" y="250" width="260" height="70" rx="6"/>
- <rect x="575" y="30" width="165" height="140" rx="6"/>
- <rect x="575" y="205" width="165" height="125" rx="6"/>
+ <rect x="575" y="30" width="305" height="132" rx="6"/>
+ <rect x="575" y="205" width="305" height="155" rx="6"/>
</g>
<g fill="none" stroke="#8a93a0" stroke-width="1.5" marker-end="url(#arrow)">
<line x1="230" y1="70" x2="278" y2="70"/>
<line x1="230" y1="175" x2="278" y2="175"/>
<line x1="540" y1="90" x2="573" y2="90"/>
<line x1="410" y1="250" x2="410" y2="212"/>
- <line x1="657" y1="170" x2="657" y2="203"/>
- <polyline points="657,330 657,365 125,365 125,252"/>
+ <line x1="728" y1="162" x2="728" y2="203"/>
+ <polyline points="728,360 728,390 125,390 125,252"/>
</g>
<g fill="#5d6675" font-size="12">
<text x="32" y="52" font-weight="bold" font-size="13">PCR 11</text>
@@ -37,7 +37,7 @@
<text x="292" y="74">PolicyOR of two branches:</text>
<text x="304" y="94">written: PolicyNvWritten(YES)</text>
<text x="304" y="114">init: PolicyNvWritten(NO)</text>
- <text x="304" y="132">and PolicyPCR(9, 11)</text>
+ <text x="332" y="132">and PolicyPCR(9, 11)</text>
<text x="292" y="156">then PolicySigned(writer key)</text>
<text x="292" y="176">then PolicyCommandCode(NV_Extend)</text>
<text x="292" y="198" font-size="11">digest = the index's authPolicy</text>
@@ -47,36 +47,40 @@
<text x="292" y="310">signs nonce and command hash</text>
<text x="587" y="52" font-weight="bold" font-size="13">NV index</text>
- <text x="587" y="72">0x01818E00</text>
- <text x="587" y="92" font-size="11">TPM_NT_EXTEND</text>
- <text x="587" y="108" font-size="11">POLICYWRITE</text>
- <text x="587" y="124" font-size="11">ORDERLY</text>
- <text x="587" y="140" font-size="11">CLEAR_STCLEAR</text>
- <text x="587" y="160" font-size="11">Name = H(public area)</text>
+ <text x="587" y="72" font-size="11"><tspan font-weight="bold">Handle:</tspan> 0x01818E00</text>
+ <text x="587" y="90" font-size="11"><tspan font-weight="bold">Type:</tspan> TPM_NT_EXTEND</text>
+ <text x="587" y="108" font-weight="bold" font-size="11">Attributes</text>
+ <text x="599" y="123" font-size="11">POLICYWRITE</text>
+ <text x="599" y="136" font-size="11">ORDERLY</text>
+ <text x="599" y="149" font-size="11">CLEAR_STCLEAR</text>
<text x="587" y="227" font-weight="bold" font-size="13">Anchor</text>
- <text x="587" y="247">nvpcr-init:shirudo:</text>
- <text x="587" y="263">0x1818e00:&lt;written</text>
- <text x="587" y="279">Name&gt;</text>
- <text x="587" y="303" font-size="11">its SHA-256 extends</text>
- <text x="587" y="319" font-size="11">PCR 9</text>
+ <g font-family="monospace" font-size="11">
+ <text x="587" y="249">SHA-256(</text>
+ <text x="599" y="265">"nvpcr-init:shirudo:0x1818e00:"</text>
+ <text x="599" y="281">|| hex(0x000B || SHA-256(</text>
+ <text x="611" y="297">handle || hash algorithm ID</text>
+ <text x="611" y="313">|| written attributes || 0x0020</text>
+ <text x="611" y="329">|| policy digest || size</text>
+ <text x="599" y="345">)))</text>
+ </g>
</g>
<g fill="none" stroke="#8a93a0" stroke-width="1.2">
<circle cx="254" cy="58" r="9"/>
<circle cx="254" cy="163" r="9"/>
<circle cx="557" cy="76" r="9"/>
- <circle cx="672" cy="187" r="9"/>
- <circle cx="390" cy="350" r="9"/>
+ <circle cx="743" cy="183" r="9"/>
+ <circle cx="390" cy="375" r="9"/>
</g>
<g fill="#5d6675" font-size="11" text-anchor="middle">
<text x="254" y="62">1</text>
<text x="254" y="167">1</text>
<text x="557" y="80">2</text>
- <text x="672" y="191">3</text>
- <text x="390" y="354">4</text>
+ <text x="743" y="187">3</text>
+ <text x="390" y="379">4</text>
</g>
<g fill="#5d6675" font-size="11">
<text x="418" y="236">signs</text>
- <text x="406" y="388" text-anchor="middle">PCR_Extend(9, SHA-256(anchor)) closes the init branch</text>
+ <text x="450" y="418" text-anchor="middle">PCR_Extend(9, anchor) closes the init branch</text>
</g>
</svg>