xref: /rk3399_ARM-atf/docs/design_documents/measured_boot.rst (revision 97653189bccb71d6890a8c665013eb7384ae93af)
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
945038f1f9SManish V Badarkhe#. RSS
955038f1f9SManish V Badarkhe
965038f1f9SManish V Badarkhe   It is one of physical backend to extend the measurements. Please refer this
975038f1f9SManish V Badarkhe   document :ref:`Runtime Security Subsystem (RSS)` for more details.
985038f1f9SManish V Badarkhe
995038f1f9SManish V BadarkhePlatform Interface
1005038f1f9SManish V Badarkhe------------------
1015038f1f9SManish V Badarkhe
1025038f1f9SManish V BadarkheEvery image which gets successfully loaded in memory (and authenticated, if
1035038f1f9SManish V Badarkhetrusted boot is enabled) then gets measured. In addition to that, platforms
1045038f1f9SManish V Badarkhecan measure any relevant piece of critical data at any point during the boot.
1055038f1f9SManish V BadarkheThe following diagram outlines the call sequence for Measured Boot platform
1065038f1f9SManish V Badarkheinterfaces invoked from generic code:
1075038f1f9SManish V Badarkhe
1085038f1f9SManish V Badarkhe.. image:: ../resources/diagrams/measured_boot_design.png
1095038f1f9SManish V Badarkhe
1105038f1f9SManish V BadarkheThese platform interfaces are used by BL1 and BL2 only, and are declared in
1115038f1f9SManish V Badarkhe``include/plat/common/platform.h``.
1125038f1f9SManish V BadarkheBL31 does not load and thus does not measure any image.
1135038f1f9SManish V Badarkhe
1145038f1f9SManish V BadarkheResponsibilities of these platform interfaces are -
1155038f1f9SManish V Badarkhe
1165038f1f9SManish V Badarkhe#. **Function : blx_plat_mboot_init()**
1175038f1f9SManish V Badarkhe
1185038f1f9SManish V Badarkhe   .. code-block:: c
1195038f1f9SManish V Badarkhe
1205038f1f9SManish V Badarkhe      void bl1_plat_mboot_init(void);
1215038f1f9SManish V Badarkhe      void bl2_plat_mboot_init(void);
1225038f1f9SManish V Badarkhe
1235038f1f9SManish V Badarkhe   Initialise all Measured Boot backends supported by the platform
1245038f1f9SManish V Badarkhe   (e.g. Event Log buffer, RSS). As these functions do not return any value,
1255038f1f9SManish V Badarkhe   the platform should deal with error management, such as logging the error
1265038f1f9SManish V Badarkhe   somewhere, or panicking the system if this is considered a fatal error.
1275038f1f9SManish V Badarkhe
1285038f1f9SManish V Badarkhe   - On the Arm FVP port -
1295038f1f9SManish V Badarkhe
1305038f1f9SManish V Badarkhe     - In BL1, this function is used to initialize the Event Log backend
1315038f1f9SManish V Badarkhe       driver, and also to write header information in the Event Log
1325038f1f9SManish V Badarkhe       buffer.
1335038f1f9SManish V Badarkhe     - In BL2, this function is used to initialize the Event Log buffer with
1345038f1f9SManish V Badarkhe       the information received from the BL1. It results in panic on
1355038f1f9SManish V Badarkhe       error.
1365038f1f9SManish V Badarkhe
1375038f1f9SManish V Badarkhe#. **Function : plat_mboot_measure_image()**
1385038f1f9SManish V Badarkhe
1395038f1f9SManish V Badarkhe   .. code-block:: c
1405038f1f9SManish V Badarkhe
1415038f1f9SManish V Badarkhe      int plat_mboot_measure_image(unsigned int image_id,
1425038f1f9SManish V Badarkhe                                   image_info_t *image_data);
1435038f1f9SManish V Badarkhe
1445038f1f9SManish V Badarkhe   - Measure the image using a hash function of the crypto module.
1455038f1f9SManish V Badarkhe
1465038f1f9SManish V Badarkhe   - Record the measurement in the corresponding backend -
1475038f1f9SManish V Badarkhe
1485038f1f9SManish V Badarkhe     - If it is Event Log backend, then record the measurement in TCG Event Log
1495038f1f9SManish V Badarkhe       format.
1505038f1f9SManish V Badarkhe     - If it is a secure crypto-processor (like RSS), then extend the designated
1515038f1f9SManish V Badarkhe       PCR (or slot) with the given measurement.
1525038f1f9SManish V Badarkhe   - This function must return 0 on success, a signed integer error code
1535038f1f9SManish V Badarkhe     otherwise.
1545038f1f9SManish V Badarkhe   - On the Arm FVP port, this function measures the given image and then
1555038f1f9SManish V Badarkhe     records that measurement in the Event Log buffer.
1565038f1f9SManish V Badarkhe     The passed id is used to retrieve information about on how to measure
1575038f1f9SManish V Badarkhe     the image (e.g. PCR number).
1585038f1f9SManish V Badarkhe
1595038f1f9SManish V Badarkhe#. **Function : blx_plat_mboot_finish()**
1605038f1f9SManish V Badarkhe
1615038f1f9SManish V Badarkhe   .. code-block:: c
1625038f1f9SManish V Badarkhe
1635038f1f9SManish V Badarkhe      void bl1_plat_mboot_finish(void);
1645038f1f9SManish V Badarkhe      void bl2_plat_mboot_finish(void);
1655038f1f9SManish V Badarkhe
1665038f1f9SManish V Badarkhe   - Do all teardown operations with respect to initialised Measured Boot backends.
1675038f1f9SManish V Badarkhe     This could be -
1685038f1f9SManish V Badarkhe
1695038f1f9SManish V Badarkhe     - Pass the Event Log details (start address and size) to Normal world or to
1705038f1f9SManish V Badarkhe       Secure World using any platform implementation way.
1715038f1f9SManish V Badarkhe     - Measure all critical data if any.
1725038f1f9SManish V Badarkhe     - As these functions do not return any value, the platform should deal with
1735038f1f9SManish V Badarkhe       error management, such as logging the error somewhere, or panicking the
1745038f1f9SManish V Badarkhe       system if this is considered a fatal error.
1755038f1f9SManish V Badarkhe
1765038f1f9SManish V Badarkhe   - On the Arm FVP port -
1775038f1f9SManish V Badarkhe
1785038f1f9SManish V Badarkhe     - In BL1, this function is used to pass the base address of
1795038f1f9SManish V Badarkhe       the Event Log buffer and its size to BL2 via tb_fw_config to extend the
1805038f1f9SManish V Badarkhe       Event Log buffer with the measurement of various images loaded by BL2.
1815038f1f9SManish V Badarkhe       It results in panic on error.
1825038f1f9SManish V Badarkhe     - In BL2, this function is used to pass the Event Log buffer information
1835038f1f9SManish V Badarkhe       (base address and size) to non-secure(BL33) and trusted OS(BL32) via
1845038f1f9SManish V Badarkhe       nt_fw and tos_fw config respectively.
1855038f1f9SManish V Badarkhe       See :ref:`DTB binding for Event Log properties` for a description of the
1865038f1f9SManish V Badarkhe       bindings used for Event Log properties.
1875038f1f9SManish V Badarkhe
1885038f1f9SManish V Badarkhe#. **Function : plat_mboot_measure_critical_data()**
1895038f1f9SManish V Badarkhe
1905038f1f9SManish V Badarkhe   .. code-block:: c
1915038f1f9SManish V Badarkhe
1925038f1f9SManish V Badarkhe      int plat_mboot_measure_critical_data(unsigned int critical_data_id,
1935038f1f9SManish V Badarkhe                                           const void *base,
1945038f1f9SManish V Badarkhe                                           size_t size);
1955038f1f9SManish V Badarkhe
1965038f1f9SManish V Badarkhe   This interface is not invoked by the generic code and it is up to the
1975038f1f9SManish V Badarkhe   platform layer to call it where appropriate.
1985038f1f9SManish V Badarkhe
1995038f1f9SManish V Badarkhe   This function measures the given critical data structure and records its
2005038f1f9SManish V Badarkhe   measurement using the Measured Boot backend driver.
2015038f1f9SManish V Badarkhe   This function must return 0 on success, a signed integer error code
2025038f1f9SManish V Badarkhe   otherwise.
2035038f1f9SManish V Badarkhe
2045038f1f9SManish V Badarkhe   In FVP, Non volatile counters get measured and recorded as Critical data
2055038f1f9SManish V Badarkhe   using the backend via this interface.
2065038f1f9SManish V Badarkhe
207*97653189SManish V Badarkhe#. **Function : plat_mboot_measure_key()**
208*97653189SManish V Badarkhe
209*97653189SManish V Badarkhe   .. code-block:: c
210*97653189SManish V Badarkhe
211*97653189SManish V Badarkhe      int plat_mboot_measure_key(const void *pk_oid, const void *pk_ptr,
212*97653189SManish V Badarkhe                                 size_t pk_len);
213*97653189SManish V Badarkhe
214*97653189SManish V Badarkhe   - This function is used by the platform to measure the passed key and
215*97653189SManish V Badarkhe     publicise it using any of the supported backends.
216*97653189SManish V Badarkhe   - The authentication module within the trusted boot framework calls this
217*97653189SManish V Badarkhe     function for every ROTPK involved in verifying the signature of a root
218*97653189SManish V Badarkhe     certificate and for every subsidiary key that gets extracted from a key
219*97653189SManish V Badarkhe     certificate for later authentication of a content certificate.
220*97653189SManish V Badarkhe   - A cookie, passed as the first argument, serves as a key-OID pointer
221*97653189SManish V Badarkhe     associated with the public key data, passed as the second argument.
222*97653189SManish V Badarkhe   - Public key data size is passed as the third argument to this function.
223*97653189SManish V Badarkhe   - This function must return 0 on success, a signed integer error code
224*97653189SManish V Badarkhe     otherwise.
225*97653189SManish V Badarkhe   - In FVP platform, this function is used to calculate the hash of the given
226*97653189SManish V Badarkhe     key and forward this hash to RSS alongside the measurement of the image
227*97653189SManish V Badarkhe     which the key signs.
228*97653189SManish V Badarkhe
2295038f1f9SManish V Badarkhe--------------
2305038f1f9SManish V Badarkhe
2315038f1f9SManish V Badarkhe*Copyright (c) 2023, Arm Limited. All rights reserved.*
2325038f1f9SManish V Badarkhe
2335038f1f9SManish V Badarkhe.. _Arm® Server Base Security Guide: https://developer.arm.com/documentation/den0086/latest
2345038f1f9SManish V Badarkhe.. _TCG EFI Protocol Specification: https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
235