Skip to content

Commit b6b46a7

Browse files
de-nordicnvlsianpu
authored andcommitted
[nrf noup] bootutil: Locking KMU keys
Lock KMU keys before passing execution to application. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 26d9f6e commit b6b46a7

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

boot/bootutil/src/ed25519_psa.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,31 @@ int exec_revoke(void)
177177
return ret;
178178
}
179179
#endif /* CONFIG_BOOT_KMU_KEYS_REVOCATION */
180+
181+
void nrf_crypto_keys_housekeeping(void)
182+
{
183+
psa_status_t status;
184+
185+
/* We will continue through all keys, even if we have error while
186+
* processing any of it. Only doing BOOT_LOG_DBG, as we do not
187+
* really want to inform on failures to lock.
188+
*/
189+
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; ++i) {
190+
psa_key_attributes_t attr;
191+
192+
status = psa_get_key_attributes(key_ids[i], &attr);
193+
BOOT_LOG_DBG("KMU key 0x%x(%d) attr query status == %d",
194+
key_ids[i], i, status);
195+
196+
if (status == PSA_SUCCESS) {
197+
status = cracen_kmu_block(&attr);
198+
BOOT_LOG_DBG("KMU key lock status == %d", status);
199+
}
200+
201+
status = psa_purge_key(key_ids[i]);
202+
BOOT_LOG_DBG("KMU key 0x%x(%d) purge status == %d",
203+
key_ids[i], i, status);
204+
}
205+
}
206+
180207
#endif

boot/zephyr/include/nrf_cleanup.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ void nrf_cleanup_peripheral(void);
2121
*/
2222
void nrf_cleanup_ns_ram(void);
2323

24+
/**
25+
* Crypto key storage housekeeping. Intended to clean up key objects from
26+
* crypto backend and apply key policies that should take effect after
27+
* MCUboot no longer needs access to keys.
28+
*/
29+
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
30+
extern void nrf_crypto_keys_housekeeping(void);
31+
#else
32+
#define nrf_crypto_keys_housekeeping() do {} while (0)
33+
#endif
34+
2435
#endif

boot/zephyr/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,13 @@ int main(void)
780780

781781
mcuboot_status_change(MCUBOOT_STATUS_BOOTABLE_IMAGE_FOUND);
782782

783+
/* From this point MCUboot does not need access to crypto keys.
784+
* Clean up backend key objects and apply key access policies that
785+
* will take effect from now through entire boot session and application
786+
* run.
787+
*/
788+
nrf_crypto_keys_housekeeping();
789+
783790
#if USE_PARTITION_MANAGER && CONFIG_FPROTECT
784791

785792
#ifdef PM_S1_ADDRESS

0 commit comments

Comments
 (0)