aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2023-04-25 23:35:20 -0700
committerVitaly Buka <vitalybuka@google.com>2023-04-26 18:55:44 -0700
commit66f162a667bcb9b4a8940eb04083082f1d030ead (patch)
treea71eb3a0b5ca9a5394650086ef35147e08de1fe6
parent533b7c1f6c696817df332cc7c9acbe3b454eadf2 (diff)
downloadllvm-66f162a667bcb9b4a8940eb04083082f1d030ead.zip
llvm-66f162a667bcb9b4a8940eb04083082f1d030ead.tar.gz
llvm-66f162a667bcb9b4a8940eb04083082f1d030ead.tar.bz2
[HWASAN] Fix __sanitizer_get_allocated_{begin,size}
HWASAN_ALIASING_MODE needs to untag only primary allocator pointers. Reviewed By: kstoimenov, thurston Differential Revision: https://reviews.llvm.org/D149238
-rw-r--r--compiler-rt/lib/hwasan/hwasan_allocator.cpp13
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/Linux/malloc_usable_size.c3
-rw-r--r--compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp3
3 files changed, 8 insertions, 11 deletions
diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index a21de0e5..ae9ffe8 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -416,7 +416,8 @@ HwasanChunkView FindHeapChunkByAddress(uptr address) {
}
static const void *AllocationBegin(const void *p) {
- const void *untagged_ptr = UntagPtr(p);
+ const void *untagged_ptr =
+ __hwasan::InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
if (!untagged_ptr)
return nullptr;
@@ -432,12 +433,14 @@ static const void *AllocationBegin(const void *p) {
return (const void *)AddTagToPointer((uptr)beg, tag);
}
-static uptr AllocationSize(const void *tagged_ptr) {
- const void *untagged_ptr = UntagPtr(tagged_ptr);
+static uptr AllocationSize(const void *p) {
+ const void *untagged_ptr =
+ __hwasan::InTaggableRegion(reinterpret_cast<uptr>(p)) ? UntagPtr(p) : p;
if (!untagged_ptr) return 0;
const void *beg = allocator.GetBlockBegin(untagged_ptr);
- Metadata *b = (Metadata *)allocator.GetMetaData(untagged_ptr);
- if (beg != untagged_ptr) return 0;
+ if (!beg)
+ return 0;
+ Metadata *b = (Metadata *)allocator.GetMetaData(beg);
return b->GetRequestedSize();
}
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/malloc_usable_size.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/malloc_usable_size.c
index 318c12a..07abb1f 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Linux/malloc_usable_size.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/malloc_usable_size.c
@@ -3,9 +3,6 @@
// Must not be implemented, no other reason to install interceptors.
// XFAIL: ubsan
-// FIXME: Implement.
-// XFAIL: hwasan-aliasing
-
#include <assert.h>
#include <malloc.h>
#include <sanitizer/allocator_interface.h>
diff --git a/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp b/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp
index 943baaf..5d757ee 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/get_allocated_begin.cpp
@@ -3,9 +3,6 @@
// Must not be implemented, no other reason to install interceptors.
// XFAIL: ubsan
-// FIXME: Implement.
-// XFAIL: hwasan-aliasing
-
#include <assert.h>
#include <sanitizer/allocator_interface.h>
#include <stdio.h>