Skip to content

Commit 4eb29ff

Browse files
degjorvarlubos
authored andcommitted
nrf_security: CRACEN: Fix KMU key BLOCK can end up in an invalid state
If a blocked key is attempted to be destroyed the provisioning slot is not cleared. To avoid this an attempt to push the key is done before destroying the key. This allows us to return an error while provisioning can still happen for other slots. Signed-off-by: Dag Erik Gjørvad <[email protected]>
1 parent 0dcfa2d commit 4eb29ff

File tree

1 file changed

+21
-0
lines changed
  • subsys/nrf_security/src/drivers/cracen/cracenpsa/src

1 file changed

+21
-0
lines changed

subsys/nrf_security/src/drivers/cracen/cracenpsa/src/kmu.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,27 @@ psa_status_t cracen_kmu_destroy_key(const psa_key_attributes_t *attributes)
514514
return psa_status;
515515
}
516516

517+
/* If the slot we attempt to destroy is blocked we will get a hardware failure, and
518+
* there is no way in hardware to distingush between an actual failure and the slot
519+
* being blocked. Therefore we attempt to push the key here to verify if the key is
520+
* blocked or not.
521+
*/
522+
for (size_t i = 0; i < slot_count; i++) {
523+
if (lib_kmu_push_slot(slot_id + i) != 0) {
524+
return PSA_ERROR_NOT_PERMITTED;
525+
}
526+
}
527+
528+
/* Clean the key data from the push area and protected ram to ensure it's not
529+
* exposed. We use the protected scheme since the key type is not known at
530+
* this point and that clears both.
531+
*/
532+
kmu_opaque_key_buffer temp_key_buffer = {
533+
.key_usage_scheme = CRACEN_KMU_KEY_USAGE_SCHEME_PROTECTED,
534+
.number_of_slots = slot_count,
535+
.slot_id = slot_id};
536+
cracen_kmu_clean_key((const uint8_t *)&temp_key_buffer);
537+
517538
psa_status = set_provisioning_in_progress(slot_id, slot_count);
518539
if (psa_status != PSA_SUCCESS) {
519540
return psa_status;

0 commit comments

Comments
 (0)