Skip to content

Commit a6b2f60

Browse files
Fix double free in psa_generate_key when psa_generate_random fails
When psa_generate_random fails, psa_generate_key_internal frees the key buffer but a the pointer to the now-freed buffer in the slot. Then psa_generate_key calls psa_fail_key_creation which sees the pointer and calls free() again. This bug was introduced by ff5f0e7 "Implement atomic-creation psa_{generate,generator_import}_key" which changed how psa_generate_key() cleans up on errors. I went through the code and could not find a similar bug in cleanup on an error during key creation. Fix #207
1 parent b1f6c5f commit a6b2f60

File tree

1 file changed

+0
-3
lines changed

1 file changed

+0
-3
lines changed

library/psa_crypto.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5718,10 +5718,7 @@ static psa_status_t psa_generate_key_internal(
57185718
status = psa_generate_random( slot->data.raw.data,
57195719
slot->data.raw.bytes );
57205720
if( status != PSA_SUCCESS )
5721-
{
5722-
mbedtls_free( slot->data.raw.data );
57235721
return( status );
5724-
}
57255722
#if defined(MBEDTLS_DES_C)
57265723
if( type == PSA_KEY_TYPE_DES )
57275724
psa_des_set_key_parity( slot->data.raw.data,

0 commit comments

Comments
 (0)