1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00

Invert and rename config option

Replace MBEDTLS_PSA_COPY_CALLER_BUFFERS with inverse:
!MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS. This ensures that buffer
protection is enabled by default without any change to the Mbed TLS
config file.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann
2024-03-13 15:42:31 +00:00
parent b596eb644f
commit 4201533196
4 changed files with 34 additions and 30 deletions

View File

@@ -1571,20 +1571,24 @@
//#define MBEDTLS_PSA_INJECT_ENTROPY
/**
* \def MBEDTLS_PSA_COPY_CALLER_BUFFERS
* \def MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
*
* Make local copies of buffers supplied by the callers of PSA functions.
* Assume all buffers passed to PSA functions are owned exclusively by the
* PSA function and are not stored in shared memory.
*
* This should be enabled whenever caller-supplied buffers are owned by
* an untrusted party, for example where arguments to PSA calls are passed
* This option may be enabled if all buffers passed to any PSA function reside
* in memory that is accessible only to the PSA function during its execution.
*
* This option MUST be disabled whenever buffer arguments are in memory shared
* with an untrusted party, for example where arguments to PSA calls are passed
* across a trust boundary.
*
* \note Enabling this option increases memory usage and code size.
* \note Enabling this option reduces memory usage and code size.
*
* \note Disabling this option causes overlap of input and output buffers
* \note Enabling this option causes overlap of input and output buffers
* not to be supported by PSA functions.
*/
#define MBEDTLS_PSA_COPY_CALLER_BUFFERS
//#define MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
/**
* \def MBEDTLS_RSA_NO_CRT

View File

@@ -106,7 +106,7 @@ mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state =
if (global_data.initialized == 0) \
return PSA_ERROR_BAD_STATE;
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
/* Declare a local copy of an input buffer and a variable that will be used
* to store a pointer to the start of the buffer.
@@ -202,7 +202,7 @@ mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state =
status = local_output_status; \
} \
} while (0)
#else /* MBEDTLS_PSA_COPY_CALLER_BUFFERS */
#else /* !MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS */
#define LOCAL_INPUT_DECLARE(input, input_copy_name) \
const uint8_t *input_copy_name = NULL;
#define LOCAL_INPUT_ALLOC(input, length, input_copy) \
@@ -215,7 +215,7 @@ mbedtls_psa_drbg_context_t *const mbedtls_psa_random_state =
output_copy = output;
#define LOCAL_OUTPUT_FREE(output, output_copy) \
output_copy = NULL;
#endif /* MBEDTLS_PSA_COPY_CALLER_BUFFERS */
#endif /* !MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS */
psa_status_t mbedtls_to_psa_error(int ret)
{
@@ -1506,7 +1506,7 @@ psa_status_t psa_export_key(mbedtls_svc_key_id_t key,
slot->key.data, slot->key.bytes,
data, data_size, data_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
unlock_status = psa_unlock_key_slot(slot);
@@ -2362,7 +2362,7 @@ psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
LOCAL_OUTPUT_ALLOC(hash_external, hash_size, hash);
status = psa_hash_finish_internal(operation, hash, hash_size, hash_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_OUTPUT_FREE(hash_external, hash);
@@ -2425,7 +2425,7 @@ psa_status_t psa_hash_compute(psa_algorithm_t alg,
status = psa_driver_wrapper_hash_compute(alg, input, input_length,
hash, hash_size, hash_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(input_external, input);
@@ -2667,7 +2667,7 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation,
psa_mac_abort(operation);
}
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(input_external, input);
@@ -2852,7 +2852,7 @@ psa_status_t psa_mac_compute(mbedtls_svc_key_id_t key,
input, input_length,
mac, mac_size, mac_length, 1);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(input_external, input);
@@ -3110,7 +3110,7 @@ psa_status_t psa_sign_message(mbedtls_svc_key_id_t key,
status = psa_sign_internal(key, 1, alg, input, input_length, signature,
signature_size, signature_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(input_external, input);
@@ -3168,7 +3168,7 @@ psa_status_t psa_verify_message(mbedtls_svc_key_id_t key,
status = psa_verify_internal(key, 1, alg, input, input_length, signature,
signature_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(input_external, input);
@@ -3242,7 +3242,7 @@ psa_status_t psa_sign_hash(mbedtls_svc_key_id_t key,
status = psa_sign_internal(key, 0, alg, hash, hash_length, signature,
signature_size, signature_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(hash_external, hash);
@@ -3314,7 +3314,7 @@ psa_status_t psa_verify_hash(mbedtls_svc_key_id_t key,
status = psa_verify_internal(key, 0, alg, hash, hash_length, signature,
signature_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(hash_external, hash);
@@ -4106,7 +4106,7 @@ psa_status_t psa_aead_encrypt(mbedtls_svc_key_id_t key,
}
/* Exit label is only used for buffer copying, prevent unused warnings. */
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(nonce_external, nonce);
@@ -4174,7 +4174,7 @@ psa_status_t psa_aead_decrypt(mbedtls_svc_key_id_t key,
}
/* Exit label is only used for buffer copying, prevent unused warnings. */
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(nonce_external, nonce);
@@ -5232,7 +5232,7 @@ psa_status_t psa_key_derivation_input_bytes(
status = psa_key_derivation_input_internal(operation, step,
PSA_KEY_TYPE_NONE,
data, data_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_INPUT_FREE(data_external, data);
@@ -5450,7 +5450,7 @@ psa_status_t psa_key_derivation_key_agreement(psa_key_derivation_operation_t *op
slot,
peer_key, peer_key_length);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
if (status != PSA_SUCCESS) {
@@ -5622,7 +5622,7 @@ psa_status_t psa_generate_random(uint8_t *output_external,
status = psa_generate_random_internal(output, output_size);
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
#if !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS)
exit:
#endif
LOCAL_OUTPUT_FREE(output_external, output);

View File

@@ -947,14 +947,14 @@ component_test_psa_crypto_key_id_encodes_owner () {
make test
}
component_test_no_psa_copy_caller_buffers () {
msg "build: full config - MBEDTLS_PSA_COPY_CALLER_BUFFERS, cmake, gcc, ASan"
component_test_psa_assume_exclusive_buffers () {
msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
scripts/config.py full
scripts/config.py unset MBEDTLS_PSA_COPY_CALLER_BUFFERS
scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
make
msg "test: full config - MBEDTLS_PSA_COPY_CALLER_BUFFERS, cmake, gcc, ASan"
msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
make test
}

View File

@@ -51,7 +51,7 @@ int mbedtls_test_platform_setup(void)
int ret = 0;
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \
&& defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) \
&& !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) \
&& defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
mbedtls_poison_test_hooks_setup();
#endif
@@ -77,7 +77,7 @@ int mbedtls_test_platform_setup(void)
void mbedtls_test_platform_teardown(void)
{
#if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_PSA_CRYPTO_C) \
&& defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS) \
&& !defined(MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS) \
&& defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
mbedtls_poison_test_hooks_teardown();
#endif