measured_boot.rst 9.5 KB

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