1*50a43b0fSManish V BadarkheDRTM Proof of Concept 2*50a43b0fSManish V Badarkhe===================== 3*50a43b0fSManish V Badarkhe 4*50a43b0fSManish V BadarkheDynamic Root of Trust for Measurement (DRTM) begins a new trust environment 5*50a43b0fSManish V Badarkheby measuring and executing a protected payload. 6*50a43b0fSManish V Badarkhe 7*50a43b0fSManish V BadarkheStatic Root of Trust for Measurement (SRTM)/Measured Boot implementation, 8*50a43b0fSManish V Badarkhecurrently used by TF-A covers all firmwares, from the boot ROM to the normal 9*50a43b0fSManish V Badarkheworld bootloader. As a whole, they make up the system's TCB. These boot 10*50a43b0fSManish V Badarkhemeasurements allow attesting to what software is running on the system and 11*50a43b0fSManish V Badarkheenable enforcing security policies. 12*50a43b0fSManish V Badarkhe 13*50a43b0fSManish V BadarkheAs the boot chain grows or firmware becomes dynamically extensible, 14*50a43b0fSManish V Badarkheestablishing an attestable TCB becomes more challenging. DRTM provides a 15*50a43b0fSManish V Badarkhesolution to this problem by allowing measurement chains to be started at 16*50a43b0fSManish V Badarkheany time. As these measurements are stored separately from the boot-time 17*50a43b0fSManish V Badarkhemeasurements, they reduce the size of the TCB, which helps reduce the attack 18*50a43b0fSManish V Badarkhesurface and the risk of untrusted code executing, which could compromise 19*50a43b0fSManish V Badarkhethe security of the system. 20*50a43b0fSManish V Badarkhe 21*50a43b0fSManish V BadarkheComponents 22*50a43b0fSManish V Badarkhe~~~~~~~~~~ 23*50a43b0fSManish V Badarkhe 24*50a43b0fSManish V Badarkhe - **DCE-Preamble**: The DCE Preamble prepares the platform for DRTM by 25*50a43b0fSManish V Badarkhe doing any needed configuration, loading the target payload image(DLME), 26*50a43b0fSManish V Badarkhe and preparing input parameters needed by DRTM. Finally, it invokes the 27*50a43b0fSManish V Badarkhe DL Event to start the dynamic launch. 28*50a43b0fSManish V Badarkhe 29*50a43b0fSManish V Badarkhe - **D-CRTM**: The D-CRTM is the trust anchor (or root of trust) for the 30*50a43b0fSManish V Badarkhe DRTM boot sequence and is where the dynamic launch starts. The D-CRTM 31*50a43b0fSManish V Badarkhe must be implemented as a trusted agent in the system. The D-CRTM 32*50a43b0fSManish V Badarkhe initializes the TPM for DRTM and prepares the environment for the next 33*50a43b0fSManish V Badarkhe stage of DRTM, the DCE. The D-CRTM measures the DCE, verifies its 34*50a43b0fSManish V Badarkhe signature, and transfers control to it. 35*50a43b0fSManish V Badarkhe 36*50a43b0fSManish V Badarkhe - **DCE**: The DCE executes on an application core. The DCE verifies the 37*50a43b0fSManish V Badarkhe system’s state, measures security-critical attributes of the system, 38*50a43b0fSManish V Badarkhe prepares the memory region for the target payload, measures the payload, 39*50a43b0fSManish V Badarkhe and finally transfers control to the payload. 40*50a43b0fSManish V Badarkhe 41*50a43b0fSManish V Badarkhe - **DLME**: The protected payload is referred to as the Dynamically Launched 42*50a43b0fSManish V Badarkhe Measured Environment, or DLME. The DLME begins execution in a safe state, 43*50a43b0fSManish V Badarkhe with a single thread of execution, DMA protections, and interrupts 44*50a43b0fSManish V Badarkhe disabled. The DCE provides data to the DLME that it can use to verify the 45*50a43b0fSManish V Badarkhe configuration of the system. 46*50a43b0fSManish V Badarkhe 47*50a43b0fSManish V BadarkheIn this proof of concept, DCE and D-CRTM are implemented in BL31 and 48*50a43b0fSManish V BadarkheDCE-Preamble and DLME are implemented in UEFI application. A DL Event is 49*50a43b0fSManish V Badarkhetriggered as a SMC by DCE-Preamble and handled by D-CRTM, which launches the 50*50a43b0fSManish V BadarkheDLME via DCE. 51*50a43b0fSManish V Badarkhe 52*50a43b0fSManish V BadarkheThis manual provides instructions to build TF-A code with pre-buit EDK2 53*50a43b0fSManish V Badarkheand DRTM UEFI application. 54*50a43b0fSManish V Badarkhe 55*50a43b0fSManish V BadarkheBuilding the PoC for the Arm FVP platform 56*50a43b0fSManish V Badarkhe~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 57*50a43b0fSManish V Badarkhe 58*50a43b0fSManish V Badarkhe(1) Use the below command to clone TF-A source code - 59*50a43b0fSManish V Badarkhe 60*50a43b0fSManish V Badarkhe.. code:: shell 61*50a43b0fSManish V Badarkhe 62*50a43b0fSManish V Badarkhe $ git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git 63*50a43b0fSManish V Badarkhe 64*50a43b0fSManish V Badarkhe(2) There are prebuilt binaries required to execute the DRTM implementation 65*50a43b0fSManish V Badarkhe in the `prebuilts-drtm-bins`_. 66*50a43b0fSManish V Badarkhe Download EDK2 *FVP_AARCH64_EFI.fd* and UEFI DRTM application *test-disk.img* 67*50a43b0fSManish V Badarkhe binary from `prebuilts-drtm-bins`_. 68*50a43b0fSManish V Badarkhe 69*50a43b0fSManish V Badarkhe(3) Build the TF-A code using below command 70*50a43b0fSManish V Badarkhe 71*50a43b0fSManish V Badarkhe.. code:: shell 72*50a43b0fSManish V Badarkhe 73*50a43b0fSManish V Badarkhe $ make CROSS_COMPILE=aarch64-none-elf- ARM_ROTPK_LOCATION=devel_rsa 74*50a43b0fSManish V Badarkhe DEBUG=1 V=1 BL33=</path/to/FVP_AARCH64_EFI.fd> DRTM_SUPPORT=1 75*50a43b0fSManish V Badarkhe MBEDTLS_DIR=</path/to/mbedTLS-source> USE_ROMLIB=1 all fip 76*50a43b0fSManish V Badarkhe 77*50a43b0fSManish V BadarkheRunning DRTM UEFI application on the Armv8-A AEM FVP 78*50a43b0fSManish V Badarkhe~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 79*50a43b0fSManish V BadarkheTo run the DRTM test application along with DRTM implementation in BL31, 80*50a43b0fSManish V Badarkheyou need an FVP model. Please use the version of FVP_Base_RevC-2xAEMvA model 81*50a43b0fSManish V Badarkheadvertised in the TF-A documentation. 82*50a43b0fSManish V Badarkhe 83*50a43b0fSManish V Badarkhe.. code:: shell 84*50a43b0fSManish V Badarkhe 85*50a43b0fSManish V Badarkhe FVP_Base_RevC-2xAEMvA \ 86*50a43b0fSManish V Badarkhe --data cluster0.cpu0=</path/to/romlib.bin>@0x03ff2000 \ 87*50a43b0fSManish V Badarkhe --stat \ 88*50a43b0fSManish V Badarkhe -C bp.flashloader0.fname=<path/to/fip.bin> \ 89*50a43b0fSManish V Badarkhe -C bp.secureflashloader.fname=<path/to/bl1.bin> \ 90*50a43b0fSManish V Badarkhe -C bp.ve_sysregs.exit_on_shutdown=1 \ 91*50a43b0fSManish V Badarkhe -C bp.virtioblockdevice.image_path=<path/to/test-disk.img> \ 92*50a43b0fSManish V Badarkhe -C cache_state_modelled=1 \ 93*50a43b0fSManish V Badarkhe -C cluster0.check_memory_attributes=0 \ 94*50a43b0fSManish V Badarkhe -C cluster0.cpu0.etm-present=0 \ 95*50a43b0fSManish V Badarkhe -C cluster0.cpu1.etm-present=0 \ 96*50a43b0fSManish V Badarkhe -C cluster0.cpu2.etm-present=0 \ 97*50a43b0fSManish V Badarkhe -C cluster0.cpu3.etm-present=0 \ 98*50a43b0fSManish V Badarkhe -C cluster0.stage12_tlb_size=1024 \ 99*50a43b0fSManish V Badarkhe -C cluster1.check_memory_attributes=0 \ 100*50a43b0fSManish V Badarkhe -C cluster1.cpu0.etm-present=0 \ 101*50a43b0fSManish V Badarkhe -C cluster1.cpu1.etm-present=0 \ 102*50a43b0fSManish V Badarkhe -C cluster1.cpu2.etm-present=0 \ 103*50a43b0fSManish V Badarkhe -C cluster1.cpu3.etm-present=0 \ 104*50a43b0fSManish V Badarkhe -C cluster1.stage12_tlb_size=1024 \ 105*50a43b0fSManish V Badarkhe -C pctl.startup=0.0.0.0 \ 106*50a43b0fSManish V Badarkhe -Q 1000 \ 107*50a43b0fSManish V Badarkhe "$@" 108*50a43b0fSManish V Badarkhe 109*50a43b0fSManish V BadarkheThe bottom of the output from *uart1* should look something like the 110*50a43b0fSManish V Badarkhefollowing to indicate that the last SMC to unprotect memory has been fired 111*50a43b0fSManish V Badarkhesuccessfully. 112*50a43b0fSManish V Badarkhe 113*50a43b0fSManish V Badarkhe.. code-block:: shell 114*50a43b0fSManish V Badarkhe 115*50a43b0fSManish V Badarkhe ... 116*50a43b0fSManish V Badarkhe 117*50a43b0fSManish V Badarkhe INFO: DRTM service handler: version 118*50a43b0fSManish V Badarkhe INFO: ++ DRTM service handler: TPM features 119*50a43b0fSManish V Badarkhe INFO: ++ DRTM service handler: Min. mem. requirement features 120*50a43b0fSManish V Badarkhe INFO: ++ DRTM service handler: DMA protection features 121*50a43b0fSManish V Badarkhe INFO: ++ DRTM service handler: Boot PE ID features 122*50a43b0fSManish V Badarkhe INFO: ++ DRTM service handler: TCB-hashes features 123*50a43b0fSManish V Badarkhe INFO: DRTM service handler: dynamic launch 124*50a43b0fSManish V Badarkhe WARNING: DRTM service handler: close locality is not supported 125*50a43b0fSManish V Badarkhe INFO: DRTM service handler: unprotect mem 126*50a43b0fSManish V Badarkhe 127*50a43b0fSManish V Badarkhe-------------- 128*50a43b0fSManish V Badarkhe 129*50a43b0fSManish V Badarkhe*Copyright (c) 2022, Arm Limited. All rights reserved.* 130*50a43b0fSManish V Badarkhe 131*50a43b0fSManish V Badarkhe.. _prebuilts-drtm-bins: https://downloads.trustedfirmware.org/tf-a/drtm 132*50a43b0fSManish V Badarkhe.. _DRTM-specification: https://developer.arm.com/documentation/den0113/a 133