From 43d5f9d4dd83d15a859d9be1359c4a4a47381fea Mon Sep 17 00:00:00 2001 From: Mitch Phillips Date: Tue, 7 Jan 2020 15:47:47 -0800 Subject: Add tagged pointers to bionic. This patch introduces tagged pointers to bionic. We add a static tag to all pointers on arm64 compatible platforms (needs requisite top-byte-ignore hardware feature and relevant kernel patches). We dynamically detect TBI-compatible devices (a device with the TBI feature and kernel support) at process start time, and insert an implementation-dependent tag into the top byte of the pointer for all heap allocations. We then check that the tag has not been truncated when deallocating the memory. If an application incorrectly writes to the top byte of the pointer, we terminate the process at time of detection. This will allow MTE-incompatible applications to be caught early. Bug: 135754954 Bug: 147147490 Test: cd bionic && atest . Change-Id: I6e5b809fc81f55dd517f845eaf20f3c0ebd4d86e --- libc/malloc_debug/malloc_debug.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libc/malloc_debug/malloc_debug.cpp') diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp index c0765a983..6eaac7de8 100644 --- a/libc/malloc_debug/malloc_debug.cpp +++ b/libc/malloc_debug/malloc_debug.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -883,6 +884,7 @@ ssize_t debug_malloc_backtrace(void* pointer, uintptr_t* frames, size_t max_fram if (!(g_debug->config().options() & BACKTRACE)) { return 0; } + pointer = UntagPointer(pointer); return PointerData::GetFrames(pointer, frames, max_frames); } -- cgit v1.2.3