1*5038f1f9SManish V BadarkheMeasured Boot Design 2*5038f1f9SManish V Badarkhe==================== 3*5038f1f9SManish V Badarkhe 4*5038f1f9SManish V BadarkheThis document briefly explains the Measured-Boot design implementation 5*5038f1f9SManish V Badarkhein |TF-A|. 6*5038f1f9SManish V Badarkhe 7*5038f1f9SManish V BadarkheIntroduction 8*5038f1f9SManish V Badarkhe------------ 9*5038f1f9SManish V Badarkhe 10*5038f1f9SManish V BadarkheMeasured Boot is the process of computing and securely recording hashes of code 11*5038f1f9SManish V Badarkheand critical data at each stage in the boot chain before the code/data is used. 12*5038f1f9SManish V Badarkhe 13*5038f1f9SManish V BadarkheThese measurements can be leveraged by other components in the system to 14*5038f1f9SManish V Badarkheimplement a complete attestation system. For example, they could be used to 15*5038f1f9SManish V Badarkheenforce local attestation policies (such as releasing certain platform keys or 16*5038f1f9SManish V Badarkhenot), or they could be securely sent to a remote challenger a.k.a. `verifier` 17*5038f1f9SManish V Badarkheafter boot to attest to the state of the code and critical-data. 18*5038f1f9SManish V Badarkhe 19*5038f1f9SManish V BadarkheMeasured Boot does not authenticate the code or critical-data, but simply 20*5038f1f9SManish V Badarkherecords what code/critical-data was present on the system during boot. 21*5038f1f9SManish V Badarkhe 22*5038f1f9SManish V BadarkheIt is assumed that BL1 is implicitly trusted (by virtue of immutability) and 23*5038f1f9SManish V Badarkheacts as the root of trust for measurement hence it is not measured. 24*5038f1f9SManish V Badarkhe 25*5038f1f9SManish V BadarkheThe Measured Boot implementation in TF-A supports multiple backends to securely 26*5038f1f9SManish V Badarkhestore measurements mentioned below in the :ref:`Measured Boot Backends` section. 27*5038f1f9SManish V Badarkhe 28*5038f1f9SManish V BadarkheCritical data 29*5038f1f9SManish V Badarkhe------------- 30*5038f1f9SManish V Badarkhe 31*5038f1f9SManish V BadarkheAll firmware images - i.e. BLx images and their corresponding configuration 32*5038f1f9SManish V Badarkhefiles, if any - must be measured. In addition to that, there might be specific 33*5038f1f9SManish V Badarkhepieces of data which needs to be measured as well. These are typically different 34*5038f1f9SManish V Badarkheon each platform. They are referred to as *critical data*. 35*5038f1f9SManish V Badarkhe 36*5038f1f9SManish V BadarkheCritical data for the platform can be determined using the following criteria: 37*5038f1f9SManish V Badarkhe 38*5038f1f9SManish V Badarkhe#. Data that influence boot flow behaviour such as - 39*5038f1f9SManish V Badarkhe 40*5038f1f9SManish V Badarkhe - Configuration parameters that alter the boot flow path. 41*5038f1f9SManish V Badarkhe - Parameters that determine which firmware to load from NV-Storage to 42*5038f1f9SManish V Badarkhe SRAM/DRAM to pass the boot process successfully. 43*5038f1f9SManish V Badarkhe 44*5038f1f9SManish V Badarkhe#. Hardware configurations settings, debug settings and security policies 45*5038f1f9SManish V Badarkhe that need to be in a valid state for a device to maintain its security 46*5038f1f9SManish V Badarkhe posture during boot and runtime. 47*5038f1f9SManish V Badarkhe#. Security-sensitive data that is being updated by hardware. 48*5038f1f9SManish V Badarkhe 49*5038f1f9SManish V BadarkheExamples of Critical data: 50*5038f1f9SManish V Badarkhe 51*5038f1f9SManish V Badarkhe#. The list of errata workarounds being applied at reset. 52*5038f1f9SManish V Badarkhe#. State of fuses such as whether an SoC is in secure mode. 53*5038f1f9SManish V Badarkhe#. NV counters that determine whether firmware is up-to-date and secure. 54*5038f1f9SManish V Badarkhe 55*5038f1f9SManish V BadarkheMeasurement slot 56*5038f1f9SManish V Badarkhe---------------- 57*5038f1f9SManish V Badarkhe 58*5038f1f9SManish V BadarkheThe measurement slot resides in a Trusted Module and can be either a secure 59*5038f1f9SManish V Badarkheregister or memory. 60*5038f1f9SManish V BadarkheThe measurement slot is used to provide a method to cryptographically record 61*5038f1f9SManish V Badarkhe(measure) images and critical data on a platform. 62*5038f1f9SManish V BadarkheThe measurement slot update calculation, called an **extend** operation, is 63*5038f1f9SManish V Badarkhea one-way hash of all the previous measurements and the new measurement. It 64*5038f1f9SManish V Badarkheis the only way to change the slot value, thus no measurements can ever be 65*5038f1f9SManish V Badarkheremoved or overwritten. 66*5038f1f9SManish V Badarkhe 67*5038f1f9SManish V Badarkhe.. _Measured Boot Backends: 68*5038f1f9SManish V Badarkhe 69*5038f1f9SManish V BadarkheMeasured Boot Backends 70*5038f1f9SManish V Badarkhe---------------------- 71*5038f1f9SManish V Badarkhe 72*5038f1f9SManish V BadarkheThe Measured Boot implementation in TF-A supports: 73*5038f1f9SManish V Badarkhe 74*5038f1f9SManish V Badarkhe#. Event Log 75*5038f1f9SManish V Badarkhe 76*5038f1f9SManish V Badarkhe The TCG Event Log holds a record of measurements made into the Measurement 77*5038f1f9SManish V Badarkhe Slot aka PCR (Platform Configuration Register). 78*5038f1f9SManish V Badarkhe 79*5038f1f9SManish V Badarkhe The `TCG EFI Protocol Specification`_ provides details on how to measure 80*5038f1f9SManish V Badarkhe components. The Arm document 81*5038f1f9SManish V Badarkhe `Arm® Server Base Security Guide`_ provides specific guidance for 82*5038f1f9SManish V Badarkhe measurements on an SBSA/SBBR server system. By considering these 83*5038f1f9SManish V Badarkhe specifications it is decided that - 84*5038f1f9SManish V Badarkhe 85*5038f1f9SManish V Badarkhe #. Use PCR0 for images measurements. 86*5038f1f9SManish V Badarkhe #. Use PCR1 for Critical data measurements. 87*5038f1f9SManish V Badarkhe 88*5038f1f9SManish V Badarkhe TCG has specified the architecture for the structure of this log in the 89*5038f1f9SManish V Badarkhe `TCG EFI Protocol Specification`_. The specification describes two event 90*5038f1f9SManish V Badarkhe log event records—the legacy, fixed size SHA1 structure called TCG_PCR_EVENT 91*5038f1f9SManish V Badarkhe and the variable length crypto agile structure called TCG_PCR_EVENT2. Event 92*5038f1f9SManish V Badarkhe Log driver implemented in TF-A covers later part. 93*5038f1f9SManish V Badarkhe 94*5038f1f9SManish V Badarkhe#. RSS 95*5038f1f9SManish V Badarkhe 96*5038f1f9SManish V Badarkhe It is one of physical backend to extend the measurements. Please refer this 97*5038f1f9SManish V Badarkhe document :ref:`Runtime Security Subsystem (RSS)` for more details. 98*5038f1f9SManish V Badarkhe 99*5038f1f9SManish V BadarkhePlatform Interface 100*5038f1f9SManish V Badarkhe------------------ 101*5038f1f9SManish V Badarkhe 102*5038f1f9SManish V BadarkheEvery image which gets successfully loaded in memory (and authenticated, if 103*5038f1f9SManish V Badarkhetrusted boot is enabled) then gets measured. In addition to that, platforms 104*5038f1f9SManish V Badarkhecan measure any relevant piece of critical data at any point during the boot. 105*5038f1f9SManish V BadarkheThe following diagram outlines the call sequence for Measured Boot platform 106*5038f1f9SManish V Badarkheinterfaces invoked from generic code: 107*5038f1f9SManish V Badarkhe 108*5038f1f9SManish V Badarkhe.. image:: ../resources/diagrams/measured_boot_design.png 109*5038f1f9SManish V Badarkhe 110*5038f1f9SManish V BadarkheThese platform interfaces are used by BL1 and BL2 only, and are declared in 111*5038f1f9SManish V Badarkhe``include/plat/common/platform.h``. 112*5038f1f9SManish V BadarkheBL31 does not load and thus does not measure any image. 113*5038f1f9SManish V Badarkhe 114*5038f1f9SManish V BadarkheResponsibilities of these platform interfaces are - 115*5038f1f9SManish V Badarkhe 116*5038f1f9SManish V Badarkhe#. **Function : blx_plat_mboot_init()** 117*5038f1f9SManish V Badarkhe 118*5038f1f9SManish V Badarkhe .. code-block:: c 119*5038f1f9SManish V Badarkhe 120*5038f1f9SManish V Badarkhe void bl1_plat_mboot_init(void); 121*5038f1f9SManish V Badarkhe void bl2_plat_mboot_init(void); 122*5038f1f9SManish V Badarkhe 123*5038f1f9SManish V Badarkhe Initialise all Measured Boot backends supported by the platform 124*5038f1f9SManish V Badarkhe (e.g. Event Log buffer, RSS). As these functions do not return any value, 125*5038f1f9SManish V Badarkhe the platform should deal with error management, such as logging the error 126*5038f1f9SManish V Badarkhe somewhere, or panicking the system if this is considered a fatal error. 127*5038f1f9SManish V Badarkhe 128*5038f1f9SManish V Badarkhe - On the Arm FVP port - 129*5038f1f9SManish V Badarkhe 130*5038f1f9SManish V Badarkhe - In BL1, this function is used to initialize the Event Log backend 131*5038f1f9SManish V Badarkhe driver, and also to write header information in the Event Log 132*5038f1f9SManish V Badarkhe buffer. 133*5038f1f9SManish V Badarkhe - In BL2, this function is used to initialize the Event Log buffer with 134*5038f1f9SManish V Badarkhe the information received from the BL1. It results in panic on 135*5038f1f9SManish V Badarkhe error. 136*5038f1f9SManish V Badarkhe 137*5038f1f9SManish V Badarkhe#. **Function : plat_mboot_measure_image()** 138*5038f1f9SManish V Badarkhe 139*5038f1f9SManish V Badarkhe .. code-block:: c 140*5038f1f9SManish V Badarkhe 141*5038f1f9SManish V Badarkhe int plat_mboot_measure_image(unsigned int image_id, 142*5038f1f9SManish V Badarkhe image_info_t *image_data); 143*5038f1f9SManish V Badarkhe 144*5038f1f9SManish V Badarkhe - Measure the image using a hash function of the crypto module. 145*5038f1f9SManish V Badarkhe 146*5038f1f9SManish V Badarkhe - Record the measurement in the corresponding backend - 147*5038f1f9SManish V Badarkhe 148*5038f1f9SManish V Badarkhe - If it is Event Log backend, then record the measurement in TCG Event Log 149*5038f1f9SManish V Badarkhe format. 150*5038f1f9SManish V Badarkhe - If it is a secure crypto-processor (like RSS), then extend the designated 151*5038f1f9SManish V Badarkhe PCR (or slot) with the given measurement. 152*5038f1f9SManish V Badarkhe - This function must return 0 on success, a signed integer error code 153*5038f1f9SManish V Badarkhe otherwise. 154*5038f1f9SManish V Badarkhe - On the Arm FVP port, this function measures the given image and then 155*5038f1f9SManish V Badarkhe records that measurement in the Event Log buffer. 156*5038f1f9SManish V Badarkhe The passed id is used to retrieve information about on how to measure 157*5038f1f9SManish V Badarkhe the image (e.g. PCR number). 158*5038f1f9SManish V Badarkhe 159*5038f1f9SManish V Badarkhe#. **Function : blx_plat_mboot_finish()** 160*5038f1f9SManish V Badarkhe 161*5038f1f9SManish V Badarkhe .. code-block:: c 162*5038f1f9SManish V Badarkhe 163*5038f1f9SManish V Badarkhe void bl1_plat_mboot_finish(void); 164*5038f1f9SManish V Badarkhe void bl2_plat_mboot_finish(void); 165*5038f1f9SManish V Badarkhe 166*5038f1f9SManish V Badarkhe - Do all teardown operations with respect to initialised Measured Boot backends. 167*5038f1f9SManish V Badarkhe This could be - 168*5038f1f9SManish V Badarkhe 169*5038f1f9SManish V Badarkhe - Pass the Event Log details (start address and size) to Normal world or to 170*5038f1f9SManish V Badarkhe Secure World using any platform implementation way. 171*5038f1f9SManish V Badarkhe - Measure all critical data if any. 172*5038f1f9SManish V Badarkhe - As these functions do not return any value, the platform should deal with 173*5038f1f9SManish V Badarkhe error management, such as logging the error somewhere, or panicking the 174*5038f1f9SManish V Badarkhe system if this is considered a fatal error. 175*5038f1f9SManish V Badarkhe 176*5038f1f9SManish V Badarkhe - On the Arm FVP port - 177*5038f1f9SManish V Badarkhe 178*5038f1f9SManish V Badarkhe - In BL1, this function is used to pass the base address of 179*5038f1f9SManish V Badarkhe the Event Log buffer and its size to BL2 via tb_fw_config to extend the 180*5038f1f9SManish V Badarkhe Event Log buffer with the measurement of various images loaded by BL2. 181*5038f1f9SManish V Badarkhe It results in panic on error. 182*5038f1f9SManish V Badarkhe - In BL2, this function is used to pass the Event Log buffer information 183*5038f1f9SManish V Badarkhe (base address and size) to non-secure(BL33) and trusted OS(BL32) via 184*5038f1f9SManish V Badarkhe nt_fw and tos_fw config respectively. 185*5038f1f9SManish V Badarkhe See :ref:`DTB binding for Event Log properties` for a description of the 186*5038f1f9SManish V Badarkhe bindings used for Event Log properties. 187*5038f1f9SManish V Badarkhe 188*5038f1f9SManish V Badarkhe#. **Function : plat_mboot_measure_critical_data()** 189*5038f1f9SManish V Badarkhe 190*5038f1f9SManish V Badarkhe .. code-block:: c 191*5038f1f9SManish V Badarkhe 192*5038f1f9SManish V Badarkhe int plat_mboot_measure_critical_data(unsigned int critical_data_id, 193*5038f1f9SManish V Badarkhe const void *base, 194*5038f1f9SManish V Badarkhe size_t size); 195*5038f1f9SManish V Badarkhe 196*5038f1f9SManish V Badarkhe This interface is not invoked by the generic code and it is up to the 197*5038f1f9SManish V Badarkhe platform layer to call it where appropriate. 198*5038f1f9SManish V Badarkhe 199*5038f1f9SManish V Badarkhe This function measures the given critical data structure and records its 200*5038f1f9SManish V Badarkhe measurement using the Measured Boot backend driver. 201*5038f1f9SManish V Badarkhe This function must return 0 on success, a signed integer error code 202*5038f1f9SManish V Badarkhe otherwise. 203*5038f1f9SManish V Badarkhe 204*5038f1f9SManish V Badarkhe In FVP, Non volatile counters get measured and recorded as Critical data 205*5038f1f9SManish V Badarkhe using the backend via this interface. 206*5038f1f9SManish V Badarkhe 207*5038f1f9SManish V Badarkhe-------------- 208*5038f1f9SManish V Badarkhe 209*5038f1f9SManish V Badarkhe*Copyright (c) 2023, Arm Limited. All rights reserved.* 210*5038f1f9SManish V Badarkhe 211*5038f1f9SManish V Badarkhe.. _Arm® Server Base Security Guide: https://developer.arm.com/documentation/den0086/latest 212*5038f1f9SManish V Badarkhe.. _TCG EFI Protocol Specification: https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf 213