From 763971f32ec317c5c8c6248f39d2f30cee3a93b5 Mon Sep 17 00:00:00 2001 From: Ryan Everett Date: Mon, 29 Jan 2024 17:13:36 +0000 Subject: [PATCH] Comment on locking strategy in psa_destroy_key Signed-off-by: Ryan Everett --- library/psa_crypto.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index c81666818..9d7b72f87 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1072,6 +1072,10 @@ psa_status_t psa_destroy_key(mbedtls_svc_key_id_t key) } #if defined(MBEDTLS_THREADING_C) + /* We cannot unlock between setting the state to PENDING_DELETION + * and destroying the key in storage, as otherwise another thread + * could load the key into a new slot and the key will not be + * fully destroyed. */ PSA_THREADING_CHK_GOTO_EXIT(mbedtls_mutex_lock( &mbedtls_threading_key_slot_mutex)); #endif