[compiler-rt] 8c60e0b - [HWASan] Print short tags in __hwasan_print_shadow.
Matt Morehouse via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 2 07:59:46 PDT 2021
Author: Matt Morehouse
Date: 2021-11-02T07:59:25-07:00
New Revision: 8c60e0b632437f0a4b74864999128c994109ea6e
URL: https://github.com/llvm/llvm-project/commit/8c60e0b632437f0a4b74864999128c994109ea6e
DIFF: https://github.com/llvm/llvm-project/commit/8c60e0b632437f0a4b74864999128c994109ea6e.diff
LOG: [HWASan] Print short tags in __hwasan_print_shadow.
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D112959
Added:
Modified:
compiler-rt/lib/hwasan/hwasan.cpp
compiler-rt/test/hwasan/TestCases/hwasan-print-shadow.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp
index e8ffbbd6f48de..c2863400d9d90 100644
--- a/compiler-rt/lib/hwasan/hwasan.cpp
+++ b/compiler-rt/lib/hwasan/hwasan.cpp
@@ -16,6 +16,7 @@
#include "hwasan_checks.h"
#include "hwasan_dynamic_shadow.h"
#include "hwasan_globals.h"
+#include "hwasan_mapping.h"
#include "hwasan_poisoning.h"
#include "hwasan_report.h"
#include "hwasan_thread.h"
@@ -391,8 +392,15 @@ void __hwasan_print_shadow(const void *p, uptr sz) {
uptr shadow_last = MemToShadow(ptr_raw + sz - 1);
Printf("HWASan shadow map for %zx .. %zx (pointer tag %x)\n", ptr_raw,
ptr_raw + sz, GetTagFromPointer((uptr)p));
- for (uptr s = shadow_first; s <= shadow_last; ++s)
- Printf(" %zx: %x\n", ShadowToMem(s), *(tag_t *)s);
+ for (uptr s = shadow_first; s <= shadow_last; ++s) {
+ tag_t mem_tag = *reinterpret_cast<tag_t *>(s);
+ uptr granule_addr = ShadowToMem(s);
+ if (mem_tag && mem_tag < kShadowAlignment)
+ Printf(" %zx: %02x(%02x)\n", granule_addr, mem_tag,
+ *reinterpret_cast<tag_t *>(granule_addr + kShadowAlignment - 1));
+ else
+ Printf(" %zx: %02x\n", granule_addr, mem_tag);
+ }
}
sptr __hwasan_test_shadow(const void *p, uptr sz) {
diff --git a/compiler-rt/test/hwasan/TestCases/hwasan-print-shadow.cpp b/compiler-rt/test/hwasan/TestCases/hwasan-print-shadow.cpp
index 285a321c1f2eb..2be0a0591693c 100644
--- a/compiler-rt/test/hwasan/TestCases/hwasan-print-shadow.cpp
+++ b/compiler-rt/test/hwasan/TestCases/hwasan-print-shadow.cpp
@@ -8,26 +8,35 @@
#include <sanitizer/hwasan_interface.h>
int main() {
- void *alloc = malloc(4096);
+ char *alloc = (char *)malloc(4096);
+
+ // Simulate short granule tags.
+ alloc[15] = 0x00;
+ alloc[31] = 0xbb;
+ alloc[47] = 0xcc;
+ alloc[63] = 0xdd;
+ alloc[79] = 0xee;
+ alloc[95] = 0xff;
// __hwasan_tag_memory expects untagged pointers.
char *p = (char *)__hwasan_tag_pointer(alloc, 0);
assert(p);
+ // Write tags to shadow.
__hwasan_tag_memory(p, 1, 32);
- __hwasan_tag_memory(p + 32, 3, 16);
+ __hwasan_tag_memory(p + 32, 16, 16);
__hwasan_tag_memory(p + 48, 0, 32);
__hwasan_tag_memory(p + 80, 4, 16);
char *q = (char *)__hwasan_tag_pointer(p, 7);
__hwasan_print_shadow(q + 5, 89 - 5);
// CHECK: HWASan shadow map for {{.*}}5 .. {{.*}}9 (pointer tag 7)
- // CHECK-NEXT: {{.*}}0: 1
- // CHECK-NEXT: {{.*}}0: 1
- // CHECK-NEXT: {{.*}}0: 3
- // CHECK-NEXT: {{.*}}0: 0
- // CHECK-NEXT: {{.*}}0: 0
- // CHECK-NEXT: {{.*}}0: 4
+ // CHECK-NEXT: {{.*}}0: 01(00)
+ // CHECK-NEXT: {{.*}}0: 01(bb)
+ // CHECK-NEXT: {{.*}}0: 10
+ // CHECK-NEXT: {{.*}}0: 00
+ // CHECK-NEXT: {{.*}}0: 00
+ // CHECK-NEXT: {{.*}}0: 04(ff)
free(alloc);
}
More information about the llvm-commits
mailing list