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
committerEvgenii Stepanov <eugenis@google.com>2020-01-23 10:37:24 -0800
commit3b21ada5f1bd98b337143ee5d5baba7373bfdbb1 (patch)
tree7e5bf3c1ae9008eccc61f7f6eefef9b0039af1b5 /libc/malloc_debug/malloc_debug.cpp
parent73e9f242ed07631798433df4e35f5f73443cb9f9 (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: Ie424325ba1e3c4443040ac265aeaa28d9e405d28
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);
}