xref: /rk3399_ARM-atf/docs/design_documents/measured_boot.rst (revision c76da4ecabce719c321ba27b323d04de4878894f)
15038f1f9SManish V BadarkheMeasured Boot Design
25038f1f9SManish V Badarkhe====================
35038f1f9SManish V Badarkhe
45038f1f9SManish V BadarkheThis document briefly explains the Measured-Boot design implementation
55038f1f9SManish V Badarkhein |TF-A|.
65038f1f9SManish V Badarkhe
75038f1f9SManish V BadarkheIntroduction
85038f1f9SManish V Badarkhe------------
95038f1f9SManish V Badarkhe
105038f1f9SManish V BadarkheMeasured Boot is the process of computing and securely recording hashes of code
115038f1f9SManish V Badarkheand critical data at each stage in the boot chain before the code/data is used.
125038f1f9SManish V Badarkhe
135038f1f9SManish V BadarkheThese measurements can be leveraged by other components in the system to
145038f1f9SManish V Badarkheimplement a complete attestation system. For example, they could be used to
155038f1f9SManish V Badarkheenforce local attestation policies (such as releasing certain platform keys or
165038f1f9SManish V Badarkhenot), or they could be securely sent to a remote challenger a.k.a. `verifier`
175038f1f9SManish V Badarkheafter boot to attest to the state of the code and critical-data.
185038f1f9SManish V Badarkhe
195038f1f9SManish V BadarkheMeasured Boot does not authenticate the code or critical-data, but simply
205038f1f9SManish V Badarkherecords what code/critical-data was present on the system during boot.
215038f1f9SManish V Badarkhe
225038f1f9SManish V BadarkheIt is assumed that BL1 is implicitly trusted (by virtue of immutability) and
235038f1f9SManish V Badarkheacts as the root of trust for measurement hence it is not measured.
245038f1f9SManish V Badarkhe
255038f1f9SManish V BadarkheThe Measured Boot implementation in TF-A supports multiple backends to securely
265038f1f9SManish V Badarkhestore measurements mentioned below in the :ref:`Measured Boot Backends` section.
275038f1f9SManish V Badarkhe
285038f1f9SManish V BadarkheCritical data
295038f1f9SManish V Badarkhe-------------
305038f1f9SManish V Badarkhe
315038f1f9SManish V BadarkheAll firmware images - i.e. BLx images and their corresponding configuration
325038f1f9SManish V Badarkhefiles, if any - must be measured. In addition to that, there might be specific
335038f1f9SManish V Badarkhepieces of data which needs to be measured as well. These are typically different
345038f1f9SManish V Badarkheon each platform. They are referred to as *critical data*.
355038f1f9SManish V Badarkhe
365038f1f9SManish V BadarkheCritical data for the platform can be determined using the following criteria:
375038f1f9SManish V Badarkhe
385038f1f9SManish V Badarkhe#. Data that influence boot flow behaviour such as -
395038f1f9SManish V Badarkhe
405038f1f9SManish V Badarkhe   - Configuration parameters that alter the boot flow path.
415038f1f9SManish V Badarkhe   - Parameters that determine which firmware to load from NV-Storage to
425038f1f9SManish V Badarkhe     SRAM/DRAM to pass the boot process successfully.
435038f1f9SManish V Badarkhe
445038f1f9SManish V Badarkhe#. Hardware configurations settings, debug settings and security policies
455038f1f9SManish V Badarkhe   that need to be in a valid state for a device to maintain its security
465038f1f9SManish V Badarkhe   posture during boot and runtime.
475038f1f9SManish V Badarkhe#. Security-sensitive data that is being updated by hardware.
485038f1f9SManish V Badarkhe
495038f1f9SManish V BadarkheExamples of Critical data:
505038f1f9SManish V Badarkhe
515038f1f9SManish V Badarkhe#. The list of errata workarounds being applied at reset.
525038f1f9SManish V Badarkhe#. State of fuses such as whether an SoC is in secure mode.
535038f1f9SManish V Badarkhe#. NV counters that determine whether firmware is up-to-date and secure.
545038f1f9SManish V Badarkhe
555038f1f9SManish V BadarkheMeasurement slot
565038f1f9SManish V Badarkhe----------------
575038f1f9SManish V Badarkhe
585038f1f9SManish V BadarkheThe measurement slot resides in a Trusted Module and can be either a secure
595038f1f9SManish V Badarkheregister or memory.
605038f1f9SManish V BadarkheThe measurement slot is used to provide a method to cryptographically record
615038f1f9SManish V Badarkhe(measure) images and critical data on a platform.
625038f1f9SManish V BadarkheThe measurement slot update calculation, called an **extend** operation, is
635038f1f9SManish V Badarkhea one-way hash of all the previous measurements and the new measurement. It
645038f1f9SManish V Badarkheis the only way to change the slot value, thus no measurements can ever be
655038f1f9SManish V Badarkheremoved or overwritten.
665038f1f9SManish V Badarkhe
675038f1f9SManish V Badarkhe.. _Measured Boot Backends:
685038f1f9SManish V Badarkhe
695038f1f9SManish V BadarkheMeasured Boot Backends
705038f1f9SManish V Badarkhe----------------------
715038f1f9SManish V Badarkhe
725038f1f9SManish V BadarkheThe Measured Boot implementation in TF-A supports:
735038f1f9SManish V Badarkhe
745038f1f9SManish V Badarkhe#. Event Log
755038f1f9SManish V Badarkhe
765038f1f9SManish V Badarkhe   The TCG Event Log holds a record of measurements made into the Measurement
775038f1f9SManish V Badarkhe   Slot aka PCR (Platform Configuration Register).
785038f1f9SManish V Badarkhe
795038f1f9SManish V Badarkhe   The `TCG EFI Protocol Specification`_ provides details on how to measure
805038f1f9SManish V Badarkhe   components. The Arm document
815038f1f9SManish V Badarkhe   `Arm® Server Base Security Guide`_ provides specific guidance for
825038f1f9SManish V Badarkhe   measurements on an SBSA/SBBR server system. By considering these
835038f1f9SManish V Badarkhe   specifications it is decided that -
845038f1f9SManish V Badarkhe
855038f1f9SManish V Badarkhe   #. Use PCR0 for images measurements.
865038f1f9SManish V Badarkhe   #. Use PCR1 for Critical data measurements.
875038f1f9SManish V Badarkhe
885038f1f9SManish V Badarkhe   TCG has specified the architecture for the structure of this log in the
895038f1f9SManish V Badarkhe   `TCG EFI Protocol Specification`_. The specification describes two event
905038f1f9SManish V Badarkhe   log event records—the legacy, fixed size SHA1 structure called TCG_PCR_EVENT
915038f1f9SManish V Badarkhe   and the variable length crypto agile structure called TCG_PCR_EVENT2. Event
925038f1f9SManish V Badarkhe   Log driver implemented in TF-A covers later part.
935038f1f9SManish V Badarkhe
94a2dd13caSAbhi Singh#. Discrete TPM
95a2dd13caSAbhi Singh
96a2dd13caSAbhi Singh   A Discrete TPM (Trusted Platform Module) can be used alongside Event Log to
97a2dd13caSAbhi Singh   extend measurements and validate Measured Boot functionality. The use of a
98a2dd13caSAbhi Singh   Discrete TPM in TF-A to extend measurements of images and other critical data
99a2dd13caSAbhi Singh   allows for an additional layer of security. The TPM can be used to attest the
100a2dd13caSAbhi Singh   integrity of the Event Log.
101a2dd13caSAbhi Singh
102e4582e42STamas Ban#. |RSE|
1035038f1f9SManish V Badarkhe
104e4582e42STamas Ban   It is one of the physical backends to extend the measurements. Please refer
105e4582e42STamas Ban   this document :ref:`Runtime Security Engine (RSE)` for more details.
1065038f1f9SManish V Badarkhe
1075038f1f9SManish V BadarkhePlatform Interface
1085038f1f9SManish V Badarkhe------------------
1095038f1f9SManish V Badarkhe
1105038f1f9SManish V BadarkheEvery image which gets successfully loaded in memory (and authenticated, if
1115038f1f9SManish V Badarkhetrusted boot is enabled) then gets measured. In addition to that, platforms
1125038f1f9SManish V Badarkhecan measure any relevant piece of critical data at any point during the boot.
1135038f1f9SManish V BadarkheThe following diagram outlines the call sequence for Measured Boot platform
1145038f1f9SManish V Badarkheinterfaces invoked from generic code:
1155038f1f9SManish V Badarkhe
1165038f1f9SManish V Badarkhe.. image:: ../resources/diagrams/measured_boot_design.png
1175038f1f9SManish V Badarkhe
1185038f1f9SManish V BadarkheThese platform interfaces are used by BL1 and BL2 only, and are declared in
1195038f1f9SManish V Badarkhe``include/plat/common/platform.h``.
1205038f1f9SManish V BadarkheBL31 does not load and thus does not measure any image.
1215038f1f9SManish V Badarkhe
1225038f1f9SManish V BadarkheResponsibilities of these platform interfaces are -
1235038f1f9SManish V Badarkhe
1245038f1f9SManish V Badarkhe#. **Function : blx_plat_mboot_init()**
1255038f1f9SManish V Badarkhe
1265038f1f9SManish V Badarkhe   .. code-block:: c
1275038f1f9SManish V Badarkhe
1285038f1f9SManish V Badarkhe      void bl1_plat_mboot_init(void);
1295038f1f9SManish V Badarkhe      void bl2_plat_mboot_init(void);
1305038f1f9SManish V Badarkhe
1315038f1f9SManish V Badarkhe   Initialise all Measured Boot backends supported by the platform
132e4582e42STamas Ban   (e.g. Event Log buffer, |RSE|). As these functions do not return any value,
1335038f1f9SManish V Badarkhe   the platform should deal with error management, such as logging the error
1345038f1f9SManish V Badarkhe   somewhere, or panicking the system if this is considered a fatal error.
1355038f1f9SManish V Badarkhe
1365038f1f9SManish V Badarkhe   - On the Arm FVP port -
1375038f1f9SManish V Badarkhe
1385038f1f9SManish V Badarkhe     - In BL1, this function is used to initialize the Event Log backend
1395038f1f9SManish V Badarkhe       driver, and also to write header information in the Event Log
1405038f1f9SManish V Badarkhe       buffer.
1415038f1f9SManish V Badarkhe     - In BL2, this function is used to initialize the Event Log buffer with
1425038f1f9SManish V Badarkhe       the information received from the BL1. It results in panic on
1435038f1f9SManish V Badarkhe       error.
1445038f1f9SManish V Badarkhe
1455038f1f9SManish V Badarkhe#. **Function : plat_mboot_measure_image()**
1465038f1f9SManish V Badarkhe
1475038f1f9SManish V Badarkhe   .. code-block:: c
1485038f1f9SManish V Badarkhe
1495038f1f9SManish V Badarkhe      int plat_mboot_measure_image(unsigned int image_id,
1505038f1f9SManish V Badarkhe                                   image_info_t *image_data);
1515038f1f9SManish V Badarkhe
1525038f1f9SManish V Badarkhe   - Measure the image using a hash function of the crypto module.
1535038f1f9SManish V Badarkhe
1545038f1f9SManish V Badarkhe   - Record the measurement in the corresponding backend -
1555038f1f9SManish V Badarkhe
1565038f1f9SManish V Badarkhe     - If it is Event Log backend, then record the measurement in TCG Event Log
1575038f1f9SManish V Badarkhe       format.
158e4582e42STamas Ban     - If it is a secure crypto-processor (like |RSE|), then extend the
159e4582e42STamas Ban       designated PCR (or store it in secure on-chip memory) with the given
160e4582e42STamas Ban       measurement.
1615038f1f9SManish V Badarkhe   - This function must return 0 on success, a signed integer error code
1625038f1f9SManish V Badarkhe     otherwise.
1635038f1f9SManish V Badarkhe   - On the Arm FVP port, this function measures the given image and then
1645038f1f9SManish V Badarkhe     records that measurement in the Event Log buffer.
1655038f1f9SManish V Badarkhe     The passed id is used to retrieve information about on how to measure
1665038f1f9SManish V Badarkhe     the image (e.g. PCR number).
1675038f1f9SManish V Badarkhe
1685038f1f9SManish V Badarkhe#. **Function : blx_plat_mboot_finish()**
1695038f1f9SManish V Badarkhe
1705038f1f9SManish V Badarkhe   .. code-block:: c
1715038f1f9SManish V Badarkhe
1725038f1f9SManish V Badarkhe      void bl1_plat_mboot_finish(void);
1735038f1f9SManish V Badarkhe      void bl2_plat_mboot_finish(void);
1745038f1f9SManish V Badarkhe
1755038f1f9SManish V Badarkhe   - Do all teardown operations with respect to initialised Measured Boot backends.
1765038f1f9SManish V Badarkhe     This could be -
1775038f1f9SManish V Badarkhe
1785038f1f9SManish V Badarkhe     - Pass the Event Log details (start address and size) to Normal world or to
1795038f1f9SManish V Badarkhe       Secure World using any platform implementation way.
1805038f1f9SManish V Badarkhe     - Measure all critical data if any.
1815038f1f9SManish V Badarkhe     - As these functions do not return any value, the platform should deal with
1825038f1f9SManish V Badarkhe       error management, such as logging the error somewhere, or panicking the
1835038f1f9SManish V Badarkhe       system if this is considered a fatal error.
1845038f1f9SManish V Badarkhe
1855038f1f9SManish V Badarkhe   - On the Arm FVP port -
1865038f1f9SManish V Badarkhe
1875038f1f9SManish V Badarkhe     - In BL1, this function is used to pass the base address of
1885038f1f9SManish V Badarkhe       the Event Log buffer and its size to BL2 via tb_fw_config to extend the
1895038f1f9SManish V Badarkhe       Event Log buffer with the measurement of various images loaded by BL2.
1905038f1f9SManish V Badarkhe       It results in panic on error.
1915038f1f9SManish V Badarkhe     - In BL2, this function is used to pass the Event Log buffer information
1925038f1f9SManish V Badarkhe       (base address and size) to non-secure(BL33) and trusted OS(BL32) via
1935038f1f9SManish V Badarkhe       nt_fw and tos_fw config respectively.
1945038f1f9SManish V Badarkhe       See :ref:`DTB binding for Event Log properties` for a description of the
1955038f1f9SManish V Badarkhe       bindings used for Event Log properties.
1965038f1f9SManish V Badarkhe
1975038f1f9SManish V Badarkhe#. **Function : plat_mboot_measure_critical_data()**
1985038f1f9SManish V Badarkhe
1995038f1f9SManish V Badarkhe   .. code-block:: c
2005038f1f9SManish V Badarkhe
2015038f1f9SManish V Badarkhe      int plat_mboot_measure_critical_data(unsigned int critical_data_id,
2025038f1f9SManish V Badarkhe                                           const void *base,
2035038f1f9SManish V Badarkhe                                           size_t size);
2045038f1f9SManish V Badarkhe
2055038f1f9SManish V Badarkhe   This interface is not invoked by the generic code and it is up to the
2065038f1f9SManish V Badarkhe   platform layer to call it where appropriate.
2075038f1f9SManish V Badarkhe
2085038f1f9SManish V Badarkhe   This function measures the given critical data structure and records its
2095038f1f9SManish V Badarkhe   measurement using the Measured Boot backend driver.
2105038f1f9SManish V Badarkhe   This function must return 0 on success, a signed integer error code
2115038f1f9SManish V Badarkhe   otherwise.
2125038f1f9SManish V Badarkhe
2135038f1f9SManish V Badarkhe   In FVP, Non volatile counters get measured and recorded as Critical data
2145038f1f9SManish V Badarkhe   using the backend via this interface.
2155038f1f9SManish V Badarkhe
21697653189SManish V Badarkhe#. **Function : plat_mboot_measure_key()**
21797653189SManish V Badarkhe
21897653189SManish V Badarkhe   .. code-block:: c
21997653189SManish V Badarkhe
22097653189SManish V Badarkhe      int plat_mboot_measure_key(const void *pk_oid, const void *pk_ptr,
22197653189SManish V Badarkhe                                 size_t pk_len);
22297653189SManish V Badarkhe
22397653189SManish V Badarkhe   - This function is used by the platform to measure the passed key and
22497653189SManish V Badarkhe     publicise it using any of the supported backends.
22597653189SManish V Badarkhe   - The authentication module within the trusted boot framework calls this
22697653189SManish V Badarkhe     function for every ROTPK involved in verifying the signature of a root
22797653189SManish V Badarkhe     certificate and for every subsidiary key that gets extracted from a key
22897653189SManish V Badarkhe     certificate for later authentication of a content certificate.
22997653189SManish V Badarkhe   - A cookie, passed as the first argument, serves as a key-OID pointer
23097653189SManish V Badarkhe     associated with the public key data, passed as the second argument.
23197653189SManish V Badarkhe   - Public key data size is passed as the third argument to this function.
23297653189SManish V Badarkhe   - This function must return 0 on success, a signed integer error code
23397653189SManish V Badarkhe     otherwise.
234*f036ddafSManish V Badarkhe   - In Total Compute platform, this function is used to calculate the hash
235*f036ddafSManish V Badarkhe     of the given key and forward this hash to |RSE| alongside the measurement
236*f036ddafSManish V Badarkhe     of the image which the key signs.
23797653189SManish V Badarkhe
2385038f1f9SManish V Badarkhe--------------
2395038f1f9SManish V Badarkhe
240a2dd13caSAbhi Singh*Copyright (c) 2023-2025, Arm Limited. All rights reserved.*
2415038f1f9SManish V Badarkhe
2425038f1f9SManish V Badarkhe.. _Arm® Server Base Security Guide: https://developer.arm.com/documentation/den0086/latest
2435038f1f9SManish V Badarkhe.. _TCG EFI Protocol Specification: https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
244