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