summaryrefslogtreecommitdiff
path: root/libc/malloc_debug/malloc_debug.cpp
diff options
context:
space:
mode:
authorMitch Phillips <mitchp@google.com>2020-01-07 15:47:47 -0800
committerMitch Phillips <mitchp@google.com>2020-01-15 15:03:00 -0800
commit43d5f9d4dd83d15a859d9be1359c4a4a47381fea (patch)
tree95339c5cb5d055b8fd2b216b46e6264180c4fc36 /libc/malloc_debug/malloc_debug.cpp
parentd2b8149ddad8b21ce535fb02ff752c85c7aa9d43 (diff)
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
Diffstat (limited to 'libc/malloc_debug/malloc_debug.cpp')
-rw-r--r--libc/malloc_debug/malloc_debug.cpp2
1 files changed, 2 insertions, 0 deletions
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 <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
+#include <bionic/malloc_tagged_pointers.h>
#include <private/bionic_malloc_dispatch.h>
#include <private/MallocXmlElem.h>
@@ -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);
}