Skip to content

[nrf noup] bootutil: Locking KMU keys #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions boot/bootutil/src/ed25519_psa.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,32 @@ int exec_revoke(void)
return ret;
}
#endif /* CONFIG_BOOT_KMU_KEYS_REVOCATION */

void nrf_crypto_keys_housekeeping(void)
{
psa_status_t status;

/* We will continue through all keys, even if we have error while
* processing any of it. Only doing BOOT_LOG_DBG, as we do not
* really want to inform on failures to lock.
*/
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; ++i) {
psa_key_attributes_t attr;

status = psa_get_key_attributes(kmu_key_ids[i], &attr);
BOOT_LOG_DBG("KMU key 0x%x(%d) attr query status == %d",
kmu_key_ids[i], i, status);

if (status == PSA_SUCCESS) {
status = cracen_kmu_block(&attr);
BOOT_LOG_DBG("KMU key lock status == %d", status);
}

status = psa_purge_key(kmu_key_ids[i]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting here as we have merged an API that is irrelevant for KMU support
https://arm-software.github.io/psa-api/crypto/1.1/api/keys/management.html#c.psa_purge_key

This type of API is only required when PSA_KEY_USAGE_CACHE is in use, which is not the case for NSIB or MCUboot

There is no key caching functionality forwarded to PSA crypto driver wrappers (psa_crypto_driver_wrapper_purge-key doesn't exists). Likewise there is nothing in the thin PSA core used by bl2

BOOT_LOG_DBG("KMU key 0x%x(%d) purge status == %d",
kmu_key_ids[i], i, status);

}
}

#endif
11 changes: 11 additions & 0 deletions boot/zephyr/include/nrf_cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ void nrf_cleanup_peripheral(void);
*/
void nrf_cleanup_ns_ram(void);

/**
* Crypto key storage housekeeping. Intended to clean up key objects from
* crypto backend and apply key policies that should take effect after
* MCUboot no longer needs access to keys.
*/
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
extern void nrf_crypto_keys_housekeeping(void);
#else
#define nrf_crypto_keys_housekeeping() do {} while (0)
#endif

#endif
7 changes: 7 additions & 0 deletions boot/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,13 @@ int main(void)

mcuboot_status_change(MCUBOOT_STATUS_BOOTABLE_IMAGE_FOUND);

/* From this point MCUboot does not need access to crypto keys.
* Clean up backend key objects and apply key access policies that
* will take effect from now through entire boot session and application
* run.
*/
nrf_crypto_keys_housekeeping();

#if USE_PARTITION_MANAGER && CONFIG_FPROTECT

#ifdef PM_S1_ADDRESS
Expand Down