Skip to content

Commit d97046e

Browse files
sigvartmhtmon-nordic
authored andcommitted
[nrf noup] zephyr: Clean up non-secure RAM if enabled
To ensure that MCUBoot does not leak keys or other material through memory to non-secure side we clear the memory before jumping to the next image. Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
1 parent 6242c86 commit d97046e

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

boot/zephyr/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ zephyr_library_sources(
360360
)
361361
endif()
362362

363-
if(CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL)
363+
if(CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL OR CONFIG_MCUBOOT_CLEANUP_NONSECURE_RAM)
364364
zephyr_library_sources(
365365
${BOOT_DIR}/zephyr/nrf_cleanup.c
366366
)

boot/zephyr/include/nrf_cleanup.h

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
*/
1717
void nrf_cleanup_peripheral(void);
1818

19+
/**
20+
* Perform cleanup of non-secure RAM that may have been used by MCUBoot.
21+
*/
22+
void nrf_cleanup_ns_ram(void);
23+
1924
#endif

boot/zephyr/main.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
115115
#include <pm_config.h>
116116
#endif
117117

118-
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
118+
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL || CONFIG_MCUBOOT_NRF_CLEANUP_NONSECURE_RAM
119119
#include <nrf_cleanup.h>
120120
#endif
121121

@@ -230,6 +230,9 @@ static void do_boot(struct boot_rsp *rsp)
230230
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
231231
nrf_cleanup_peripheral();
232232
#endif
233+
#if CONFIG_MCUBOOT_NRF_CLEANUP_NONSECURE_RAM && defined(PM_SRAM_NONSECURE_NAME)
234+
nrf_cleanup_ns_ram();
235+
#endif
233236
#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
234237
cleanup_arm_nvic(); /* cleanup NVIC registers */
235238

boot/zephyr/nrf_cleanup.c

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
#include <string.h>
2222

23+
#if defined(USE_PARTITION_MANAGER)
24+
#include <pm_config.h>
25+
#endif
26+
2327
#define NRF_UARTE_SUBSCRIBE_CONF_OFFS offsetof(NRF_UARTE_Type, SUBSCRIBE_STARTRX)
2428
#define NRF_UARTE_SUBSCRIBE_CONF_SIZE (offsetof(NRF_UARTE_Type, EVENTS_CTS) -\
2529
NRF_UARTE_SUBSCRIBE_CONF_OFFS)
@@ -81,3 +85,12 @@ void nrf_cleanup_peripheral(void)
8185
#endif
8286
nrf_cleanup_clock();
8387
}
88+
89+
#if defined(USE_PARTITION_MANAGER) \
90+
&& defined(CONFIG_ARM_TRUSTZONE_M) \
91+
&& defined(PM_SRAM_NONSECURE_NAME)
92+
void nrf_cleanup_ns_ram(void)
93+
{
94+
memset((void *) PM_SRAM_NONSECURE_ADDRESS, 0, PM_SRAM_NONSECURE_SIZE);
95+
}
96+
#endif

0 commit comments

Comments
 (0)