Skip to content

Commit 2394b5b

Browse files
sigvartmhde-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 <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit ff95e7b) (cherry picked from commit d584ea0)
1 parent 05405d4 commit 2394b5b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

boot/zephyr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ zephyr_library_sources(
344344
)
345345
endif()
346346

347-
if(CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL)
347+
if(CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL OR CONFIG_MCUBOOT_CLEANUP_NONSECURE_RAM)
348348
zephyr_library_sources(
349349
${BOOT_DIR}/zephyr/nrf_cleanup.c
350350
)

boot/zephyr/include/nrf_cleanup.h

Lines changed: 5 additions & 0 deletions
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ K_SEM_DEFINE(boot_log_sem, 1, 1);
123123
#include <pm_config.h>
124124
#endif
125125

126-
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
126+
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL || CONFIG_MCUBOOT_NRF_CLEANUP_NONSECURE_RAM
127127
#include <nrf_cleanup.h>
128128
#endif
129129

@@ -249,6 +249,9 @@ static void do_boot(struct boot_rsp *rsp)
249249
#if CONFIG_MCUBOOT_NRF_CLEANUP_PERIPHERAL
250250
nrf_cleanup_peripheral();
251251
#endif
252+
#if CONFIG_MCUBOOT_NRF_CLEANUP_NONSECURE_RAM && defined(PM_SRAM_NONSECURE_NAME)
253+
nrf_cleanup_ns_ram();
254+
#endif
252255
#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
253256
cleanup_arm_nvic(); /* cleanup NVIC registers */
254257

boot/zephyr/nrf_cleanup.c

Lines changed: 13 additions & 0 deletions
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)