8 Commits

Author SHA1 Message Date
David Horstmann
d3efb92922 Add underflow check to UNPOISON counter decrement
Make sure that extra UNPOISON calls do not cause the poisoning counter
to underflow and wrap around.

Memory that is unpoisoned multiple times should remain unpoisoned.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-17 15:27:50 +00:00
David Horstmann
fad038c501 Change memory poisoning flag to a count
This allows unusually-nested memory poisoning to work correctly, since
it keeps track of whether any buffers are still poisoned, rather than
just disabling poisoning at the first call to the UNPOISON() macro.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-17 14:23:20 +00:00
David Horstmann
8174478f82 Use thread-local flag to enable memory poisoning
Allow memory poisoning to be enabled and disabled at runtime using a
thread-local flag. This allows poisoning to be disabled whenever a PSA
function is called but not through the test wrappers, removing false
positive use-after-poisons.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-01-12 15:13:54 +00:00
Gilles Peskine
81f8132bd5 Avoid unused variable warnings in some plausible usage
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:42:36 +01:00
Gilles Peskine
abfad78655 Use the existing definition of MBEDTLS_TEST_HAVE_ASAN
A definition now exists in tests/helpers.h, which is a better place.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:41:58 +01:00
Gilles Peskine
0bdb6dc079 Fix memory poisoning with Asan on arbitrary byte boundaries
Asan poisons memory with an 8-byte granularity. We want to make sure that
the whole specified region is poisoned (our typical use case is a
heap-allocated object, and we want to poison the whole object, and we don't
care about the bytes after the end of the object and up to the beginning of
the next object). So align the start and end of the region to (un)poison to
an 8-byte boundary.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +01:00
Gilles Peskine
d29cce91d0 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>
2023-11-29 19:22:03 +01:00
Gilles Peskine
3fd3d05196 New files for memory-related test functions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-11-29 19:22:03 +01:00