Additional runtime check for DTB presence in BL2
authorJohn Tsichritzis <john.tsichritzis@arm.com>
Fri, 7 Sep 2018 09:42:37 +0000 (10:42 +0100)
committerJohn Tsichritzis <john.tsichritzis@arm.com>
Fri, 7 Sep 2018 10:44:45 +0000 (11:44 +0100)
In Mbed TLS shared heap code, an additional sanity check is introduced
in BL2. Currently, when BL2 shares heap with BL1, it expects the heap
info to be found in the DTB. If for any reason the DTB is missing, BL2
cannot have the heap address and, hence, Mbed TLS cannot proceed. So,
BL2 cannot continue executing and it will eventually crash.  With this
change we ensure that if the DTB is missing BL2 will panic() instead of
having an unpredictable crash.

Change-Id: I3045ae43e54b7fe53f23e7c2d4d00e3477b6a446
Signed-off-by: John Tsichritzis <john.tsichritzis@arm.com>
plat/arm/common/arm_dyn_cfg.c

index f2570a84ccb9a61aeae35f83450586a2e08c3539..58b0d4876a4497b1020e2869f8be5fcc0fe9c973 100644 (file)
@@ -62,11 +62,15 @@ int arm_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
        int err;
 
        /* If in BL2, retrieve the already allocated heap's info from DTB */
-       err = arm_get_dtb_mbedtls_heap_info(tb_fw_cfg_dtb, heap_addr,
-               heap_size);
-       if (err < 0) {
-               ERROR("BL2: unable to retrieve shared Mbed TLS heap "
-                       "information from DTB\n");
+       if (tb_fw_cfg_dtb != NULL) {
+               err = arm_get_dtb_mbedtls_heap_info(tb_fw_cfg_dtb, heap_addr,
+                       heap_size);
+               if (err < 0) {
+                       ERROR("BL2: unable to retrieve shared Mbed TLS heap information from DTB\n");
+                       panic();
+               }
+       } else {
+               ERROR("BL2: DTB missing, cannot get Mbed TLS heap\n");
                panic();
        }
 #endif
@@ -98,8 +102,7 @@ void arm_bl1_set_mbedtls_heap(void)
                err = arm_set_dtb_mbedtls_heap_info(tb_fw_cfg_dtb,
                        mbedtls_heap_addr, mbedtls_heap_size);
                if (err < 0) {
-                       ERROR("BL1: unable to write shared Mbed TLS heap "
-                               "information to DTB\n");
+                       ERROR("BL1: unable to write shared Mbed TLS heap information to DTB\n");
                        panic();
                }
        }