mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-11-03 20:33:16 +03:00
Add memory poisoning framework
While an area of memory is poisoned, reading or writing from it triggers a sanitizer violation. Implemented for ASan. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -13,3 +13,25 @@
|
||||
#include <test/macros.h>
|
||||
#include <test/memory.h>
|
||||
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN)
|
||||
#include <sanitizer/asan_interface.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_TEST_HAVE_ASAN)
|
||||
void mbedtls_test_memory_poison(const unsigned char *ptr, size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
__asan_poison_memory_region(ptr, size);
|
||||
}
|
||||
|
||||
void mbedtls_test_memory_unpoison(const unsigned char *ptr, size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
__asan_unpoison_memory_region(ptr, size);
|
||||
}
|
||||
#endif /* Asan */
|
||||
|
||||
Reference in New Issue
Block a user