1
0
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:
Gilles Peskine
2023-11-02 20:49:34 +01:00
parent 3fd3d05196
commit d29cce91d0
3 changed files with 138 additions and 0 deletions

View File

@@ -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 */