From 573bbc1b4e744080fb9735e5e7c30298cd9b31b4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 23 Jul 2019 19:59:23 +0200 Subject: [PATCH] Error out if a driver tries to store more than ITS can handle Cast explicitly for the sake of MSVC which otherwise (usefully!) warns about the truncation. --- library/psa_crypto_se.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/psa_crypto_se.c b/library/psa_crypto_se.c index bae44fa04..714a03904 100644 --- a/library/psa_crypto_se.c +++ b/library/psa_crypto_se.c @@ -127,6 +127,13 @@ static psa_status_t psa_get_se_driver_its_file_uid( { if( driver->lifetime > PSA_MAX_SE_LIFETIME ) return( PSA_ERROR_NOT_SUPPORTED ); + +#if SIZE_MAX > UINT32_MAX + /* ITS file sizes are limited to 32 bits. */ + if( driver->internal.persistent_data_size > UINT32_MAX ) + return( PSA_ERROR_NOT_SUPPORTED ); +#endif + *uid = PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE + driver->lifetime; return( PSA_SUCCESS ); } @@ -141,7 +148,8 @@ psa_status_t psa_load_se_persistent_data( if( status != PSA_SUCCESS ) return( status ); - return( psa_its_get( uid, 0, driver->internal.persistent_data_size, + return( psa_its_get( uid, 0, + (uint32_t) driver->internal.persistent_data_size, driver->internal.persistent_data ) ); } @@ -155,7 +163,8 @@ psa_status_t psa_save_se_persistent_data( if( status != PSA_SUCCESS ) return( status ); - return( psa_its_set( uid, driver->internal.persistent_data_size, + return( psa_its_set( uid, + (uint32_t) driver->internal.persistent_data_size, driver->internal.persistent_data, 0 ) ); }