mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge pull request #1141 from davidhorstmann-arm/memory-poisoning-runtime-enable
Enable and disable memory poisoning at runtime
This commit is contained in:
@ -22,9 +22,12 @@
|
||||
* memory as poisoned, which can be used to enforce some memory access
|
||||
* policies.
|
||||
*
|
||||
* Support for the C11 thread_local keyword is also required.
|
||||
*
|
||||
* Currently, only Asan (Address Sanitizer) is supported.
|
||||
*/
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN)
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN) && \
|
||||
(__STDC_VERSION__ >= 201112L)
|
||||
# define MBEDTLS_TEST_MEMORY_CAN_POISON
|
||||
#endif
|
||||
|
||||
@ -62,6 +65,12 @@
|
||||
|
||||
#if defined(MBEDTLS_TEST_MEMORY_CAN_POISON)
|
||||
|
||||
/** Thread-local variable used to enable memory poisoning. This is set and
|
||||
* unset in the test wrappers so that calls to PSA functions from the library
|
||||
* do not poison memory.
|
||||
*/
|
||||
extern _Thread_local unsigned int mbedtls_test_memory_poisoning_count;
|
||||
|
||||
/** Poison a memory area so that any attempt to read or write from it will
|
||||
* cause a runtime failure.
|
||||
*
|
||||
@ -69,7 +78,10 @@
|
||||
*/
|
||||
void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size);
|
||||
#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) \
|
||||
mbedtls_test_memory_poison(ptr, size)
|
||||
do { \
|
||||
mbedtls_test_memory_poisoning_count++; \
|
||||
mbedtls_test_memory_poison(ptr, size); \
|
||||
} while (0)
|
||||
|
||||
/** Undo the effect of mbedtls_test_memory_poison().
|
||||
*
|
||||
@ -80,7 +92,12 @@ void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size);
|
||||
*/
|
||||
void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size);
|
||||
#define MBEDTLS_TEST_MEMORY_UNPOISON(ptr, size) \
|
||||
mbedtls_test_memory_unpoison(ptr, size)
|
||||
do { \
|
||||
mbedtls_test_memory_unpoison(ptr, size); \
|
||||
if (mbedtls_test_memory_poisoning_count != 0) { \
|
||||
mbedtls_test_memory_poisoning_count--; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#else /* MBEDTLS_TEST_MEMORY_CAN_POISON */
|
||||
#define MBEDTLS_TEST_MEMORY_POISON(ptr, size) ((void) (ptr), (void) (size))
|
||||
|
Reference in New Issue
Block a user