mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-10 04:13:45 +00:00
Protect against compiler optimizations
GCC 5.4 optimized the write after poisoning (the surprising thing is that 11.4 doesn't). Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
ef0f01fee6
commit
895ebc30f0
@ -66,6 +66,15 @@ static void set_to_zero_but_the_compiler_does_not_know(volatile void *p, size_t
|
||||
memset((void *) p, false_but_the_compiler_does_not_know, n);
|
||||
}
|
||||
|
||||
/* Simulate an access to the given object, to avoid compiler optimizations
|
||||
* in code that prepares or consumes the object. */
|
||||
static void do_nothing_with_object(void *p)
|
||||
{
|
||||
(void) p;
|
||||
}
|
||||
void(*volatile do_nothing_with_object_but_the_compiler_does_not_know)(void *) =
|
||||
do_nothing_with_object;
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
/* Test framework features */
|
||||
@ -202,7 +211,9 @@ void test_memory_poison(const char *name)
|
||||
|
||||
if (direction == 'w') {
|
||||
aligned.buf[start + offset] = 'b';
|
||||
do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
|
||||
} else {
|
||||
do_nothing_with_object_but_the_compiler_does_not_know(aligned.buf);
|
||||
mbedtls_printf("%u\n", (unsigned) aligned.buf[start + offset]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user