Skip to content

Commit 023f18b

Browse files
committed
[hwasan] do not check if freed pointer belonged to allocator.
In that case it is very likely that there will be a tag mismatch anyway. We handle the case that the pointer belongs to neither of the allocators by getting a nullptr from allocator.GetBlockBegin. Reviewed By: hctim, eugenis Differential Revision: https://reviews.llvm.org/D108383
1 parent 4b4bc1e commit 023f18b

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

compiler-rt/lib/hwasan/hwasan_allocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static bool PointerAndMemoryTagsMatch(void *tagged_ptr) {
211211
static bool CheckInvalidFree(StackTrace *stack, void *untagged_ptr,
212212
void *tagged_ptr) {
213213
// This function can return true if halt_on_error is false.
214-
if (!allocator.PointerIsMine(untagged_ptr) ||
214+
if (!MemIsApp(reinterpret_cast<uptr>(untagged_ptr)) ||
215215
!PointerAndMemoryTagsMatch(tagged_ptr)) {
216216
ReportInvalidFree(stack, reinterpret_cast<uptr>(tagged_ptr));
217217
return true;

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ bool MemIsApp(uptr p) {
241241
CHECK(GetTagFromPointer(p) == 0);
242242
# endif
243243

244-
return p >= kHighMemStart || (p >= kLowMemStart && p <= kLowMemEnd);
244+
return (p >= kHighMemStart && p <= kHighMemEnd) ||
245+
(p >= kLowMemStart && p <= kLowMemEnd);
245246
}
246247

247248
void InstallAtExitHandler() { atexit(HwasanAtExit); }

compiler-rt/test/hwasan/TestCases/wild-free-realloc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// RUN: %clang_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s
22

3+
#include <sanitizer/hwasan_interface.h>
34
#include <stdlib.h>
45

56
int main() {
7+
__hwasan_enable_allocator_tagging();
68
char *p = (char *)malloc(1);
79
realloc(p + 0x10000000000, 2);
810
// CHECK: ERROR: HWAddressSanitizer: invalid-free on address {{.*}} at pc {{[0x]+}}[[PC:.*]] on thread T{{[0-9]+}}

compiler-rt/test/hwasan/TestCases/wild-free.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// RUN: %clang_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s
22

3+
#include <sanitizer/hwasan_interface.h>
34
#include <stdlib.h>
45

56
int main() {
7+
__hwasan_enable_allocator_tagging();
68
char *p = (char *)malloc(1);
79
free(p + 0x10000000000);
810
// CHECK: ERROR: HWAddressSanitizer: invalid-free on address {{.*}} at pc {{[0x]+}}[[PC:.*]] on thread T{{[0-9]+}}

0 commit comments

Comments
 (0)