diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp --- a/compiler-rt/lib/hwasan/hwasan_report.cpp +++ b/compiler-rt/lib/hwasan/hwasan_report.cpp @@ -624,9 +624,17 @@ Printf("%s of size %zu at %p tags: %02x/%02x (ptr/mem) in thread T%zd\n", is_store ? "WRITE" : "READ", access_size, untagged_addr, ptr_tag, mem_tag, t->unique_id()); + if (mem_tag < kShadowAlignment) { + tag_t *mem_ptr = reinterpret_cast( + (untagged_addr + offset & ~(kShadowAlignment - 1))); + u8 in_granule_offset = (untagged_addr + offset) & (kShadowAlignment - 1); + // The first mismatch was a short granule that matched the ptr_tag. + if (mem_ptr[kShadowAlignment - 1] == ptr_tag) { + offset += mem_tag - in_granule_offset; + } + } if (offset != 0) - Printf("Invalid access starting at offset [%zu, %zu)\n", offset, - Min(access_size, static_cast(offset) + (1 << kShadowScale))); + Printf("Invalid access starting at offset %zu\n", offset); Printf("%s", d.Default()); stack->Print(); diff --git a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c --- a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c +++ b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c @@ -1,5 +1,6 @@ // RUN: %clang_hwasan %s -o %t -// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK +// RUN: not %run %t 5 2>&1 | FileCheck %s --check-prefix=CHECK5 +// RUN: not %run %t 7 2>&1 | FileCheck %s --check-prefix=CHECK7 // REQUIRES: stable-runtime @@ -10,8 +11,12 @@ int main(int argc, char **argv) { __hwasan_enable_allocator_tagging(); + int read_offset = argc < 2 ? 5 : atoi(argv[1]); char *volatile x = (char *)malloc(10); - memset(x + 5, 0, 26); - // CHECK: is located 5 bytes inside 10-byte region + memset(x + read_offset, 0, 26); + // CHECK5: Invalid access starting at offset 5 + // CHECK5: is located 5 bytes inside 10-byte region + // CHECK7: Invalid access starting at offset 3 + // CHECK7: is located 7 bytes inside 10-byte region free(x); }