TBB: authenticate BL2 image and certificate
authorJuan Castillo <juan.castillo@arm.com>
Wed, 7 Jan 2015 13:49:59 +0000 (13:49 +0000)
committerDan Handley <dan.handley@arm.com>
Wed, 28 Jan 2015 18:27:54 +0000 (18:27 +0000)
This patch adds support to authenticate the BL2 content certificate
and image using the authentication module in BL1.

The FIP driver has been extended to include the BL2 certificate
UUID.

FVP and Juno ports include the BL2 certificate FIP file
definition.

Change-Id: I32680e9bd123c8db4a4193c14448c9b32b0e9325

bl1/bl1_main.c
drivers/io/io_fip.c
plat/fvp/fvp_io_storage.c
plat/fvp/include/platform_def.h
plat/juno/include/platform_def.h
plat/juno/plat_io_storage.c

index a5bd648c08a9767912ee77504c4761687ceb9b51..491fd5cfcd27d8533b3555c3156cd921b7aa61fd 100644 (file)
@@ -31,6 +31,7 @@
 #include <arch.h>
 #include <arch_helpers.h>
 #include <assert.h>
+#include <auth.h>
 #include <bl_common.h>
 #include <debug.h>
 #include <platform.h>
@@ -141,6 +142,34 @@ void bl1_main(void)
        /* Find out how much free trusted ram remains after BL1 load */
        bl1_tzram_layout = bl1_plat_sec_mem_layout();
 
+#if TRUSTED_BOARD_BOOT
+       /* Initialize authentication module */
+       auth_init();
+
+       /*
+        * Load the BL2 certificate into the BL2 region. This region will be
+        * overwritten by the image, so the authentication module is responsible
+        * for storing the relevant data from the certificate (keys, hashes,
+        * etc.) so it can be used later.
+        */
+       err = load_image(bl1_tzram_layout,
+                        BL2_CERT_NAME,
+                        BL2_BASE,
+                        &bl2_image_info,
+                        NULL);
+       if (err) {
+               ERROR("Failed to load BL2 certificate.\n");
+               panic();
+       }
+
+       err = auth_verify_obj(AUTH_BL2_IMG_CERT, bl2_image_info.image_base,
+                       bl2_image_info.image_size);
+       if (err) {
+               ERROR("Failed to validate BL2 certificate.\n");
+               panic();
+       }
+#endif /* TRUSTED_BOARD_BOOT */
+
        /* Load the BL2 image */
        err = load_image(bl1_tzram_layout,
                         BL2_IMAGE_NAME,
@@ -155,6 +184,20 @@ void bl1_main(void)
                ERROR("Failed to load BL2 firmware.\n");
                panic();
        }
+
+#if TRUSTED_BOARD_BOOT
+       err = auth_verify_obj(AUTH_BL2_IMG, bl2_image_info.image_base,
+                               bl2_image_info.image_size);
+       if (err) {
+               ERROR("Failed to validate BL2 image.\n");
+               panic();
+       }
+
+       /* After working with data, invalidate the data cache */
+       inv_dcache_range(bl2_image_info.image_base,
+                       (size_t)bl2_image_info.image_size);
+#endif /* TRUSTED_BOARD_BOOT */
+
        /*
         * Create a new layout of memory for BL2 as seen by BL1 i.e.
         * tell it the amount of total and free memory available.
index 4262a9de4f44b2f4d4bd3c46fe5e5c3d18b6bf69..7d2059076905b52153074f005acc82e38bdf4dff 100644 (file)
@@ -76,6 +76,10 @@ static const plat_fip_name_uuid_t name_uuid[] = {
        {BL32_IMAGE_NAME, UUID_SECURE_PAYLOAD_BL32},
 #endif /* BL32_IMAGE_NAME */
        {BL33_IMAGE_NAME, UUID_NON_TRUSTED_FIRMWARE_BL33},
+#if TRUSTED_BOARD_BOOT
+       /* Certificates */
+       {BL2_CERT_NAME, UUID_TRUSTED_BOOT_FIRMWARE_BL2_CERT},
+#endif /* TRUSTED_BOARD_BOOT */
 };
 
 static const uuid_t uuid_null = {0};
index b4a04f19c8cdb6778b7b97a28a424d2303c4a0f7..b1e033ee46aba31fe51ce05fab18ae5188bad33b 100644 (file)
@@ -77,6 +77,13 @@ static const io_file_spec_t bl33_file_spec = {
        .mode = FOPEN_MODE_RB
 };
 
+#if TRUSTED_BOARD_BOOT
+static const io_file_spec_t bl2_cert_file_spec = {
+       .path = BL2_CERT_NAME,
+       .mode = FOPEN_MODE_RB
+};
+#endif /* TRUSTED_BOARD_BOOT */
+
 static int open_fip(const uintptr_t spec);
 static int open_memmap(const uintptr_t spec);
 
@@ -114,6 +121,13 @@ static const struct plat_io_policy policies[] = {
                (uintptr_t)&bl33_file_spec,
                open_fip
        }, {
+#if TRUSTED_BOARD_BOOT
+               BL2_CERT_NAME,
+               &fip_dev_handle,
+               (uintptr_t)&bl2_cert_file_spec,
+               open_fip
+       }, {
+#endif /* TRUSTED_BOARD_BOOT */
                0, 0, 0
        }
 };
index bd53bc7b76cbb8f2b736ad9d6165a8d38de5c7e4..edbbdf31aa69021cd8e9ae1f0545097f988a4097 100644 (file)
 /* Non-Trusted Firmware BL33 */
 #define BL33_IMAGE_NAME                        "bl33.bin" /* e.g. UEFI */
 
+#if TRUSTED_BOARD_BOOT
+/* Certificates */
+# define BL2_CERT_NAME                 "bl2.crt"
+#endif /* TRUSTED_BOARD_BOOT */
+
 #define PLATFORM_CACHE_LINE_SIZE       64
 #define PLATFORM_CLUSTER_COUNT         2ull
 #define PLATFORM_CLUSTER0_CORE_COUNT   4
index c64b68297e112445641823a285fa988127fc6a24..748b32d9ff12d93dfc2dcab9fcaf8b2ae478a24a 100644 (file)
 /* Firmware Image Package */
 #define FIP_IMAGE_NAME                 "fip.bin"
 
+#if TRUSTED_BOARD_BOOT
+/* Certificates */
+# define BL2_CERT_NAME                 "bl2.crt"
+#endif /* TRUSTED_BOARD_BOOT */
+
 #define PLATFORM_CACHE_LINE_SIZE       64
 #define PLATFORM_CLUSTER_COUNT         2
 #define PLATFORM_CORE_COUNT             6
index 83d7e43bab96275c7a0e8581ef319950db0fbed0..dd9f048af6c8b38188da3dae71cc28f373b15caa 100644 (file)
@@ -77,6 +77,13 @@ static const io_file_spec_t bl33_file_spec = {
        .mode = FOPEN_MODE_RB
 };
 
+#if TRUSTED_BOARD_BOOT
+static const io_file_spec_t bl2_cert_file_spec = {
+       .path = BL2_CERT_NAME,
+       .mode = FOPEN_MODE_RB
+};
+#endif /* TRUSTED_BOARD_BOOT */
+
 static int open_fip(const uintptr_t spec);
 static int open_memmap(const uintptr_t spec);
 
@@ -119,6 +126,13 @@ static const struct plat_io_policy policies[] = {
                (uintptr_t)&bl33_file_spec,
                open_fip
        }, {
+#if TRUSTED_BOARD_BOOT
+               BL2_CERT_NAME,
+               &fip_dev_handle,
+               (uintptr_t)&bl2_cert_file_spec,
+               open_fip
+       }, {
+#endif /* TRUSTED_BOARD_BOOT */
                0, 0, 0
        }
 };