summaryrefslogtreecommitdiff
path: root/lib/hwasan/hwasan.h
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2018-01-11 22:53:30 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2018-01-11 22:53:30 +0000
commit9ebd4e4b00d76d6744709de26f9707723a96905c (patch)
treef4ed4b226390d1202d56a7c081354cdad28b376f /lib/hwasan/hwasan.h
parent37d0708903e4474aed7de5c2c600297f9e89402e (diff)
downloadcompiler-rt-9ebd4e4b00d76d6744709de26f9707723a96905c.tar.gz
[hwasan] Stack instrumentation.
Summary: Very basic stack instrumentation using tagged pointers. Tag for N'th alloca in a function is built as XOR of: * base tag for the function, which is just some bits of SP (poor man's random) * small constant which is a function of N. Allocas are aligned to 16 bytes. On every ReturnInst allocas are re-tagged to catch use-after-return. This implementation has a bunch of issues that will be taken care of later: 1. lifetime intrinsics referring to tagged pointers are not recognized in SDAG. This effectively disables stack coloring. 2. Generated code is quite inefficient. There is one extra instruction at each memory access that adds the base tag to the untagged alloca address. It would be better to keep tagged SP in a callee-saved register and address allocas as an offset of that XOR retag, but that needs better coordination between hwasan instrumentation pass and prologue/epilogue insertion. 3. Lifetime instrinsics are ignored and use-after-scope is not implemented. This would be harder to do than in ASan, because we need to use a differently tagged pointer depending on which lifetime.start / lifetime.end the current instruction is dominated / post-dominated. Reviewers: kcc, alekseyshl Subscribers: srhines, kubamracek, javed.absar, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D41602 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@322324 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan/hwasan.h')
-rw-r--r--lib/hwasan/hwasan.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/hwasan/hwasan.h b/lib/hwasan/hwasan.h
index bcf5282dc..30fc947b6 100644
--- a/lib/hwasan/hwasan.h
+++ b/lib/hwasan/hwasan.h
@@ -40,7 +40,7 @@ const uptr kShadowAlignment = 1UL << kShadowScale;
#define MEM_TO_SHADOW(mem) ((uptr)(mem) >> kShadowScale)
#define SHADOW_TO_MEM(shadow) ((uptr)(shadow) << kShadowScale)
-#define MEM_IS_APP(mem) true
+#define MEM_IS_APP(mem) MemIsApp((uptr)(mem))
// TBI (Top Byte Ignore) feature of AArch64: bits [63:56] are ignored in address
// translation and can be used to store a tag.
@@ -69,6 +69,8 @@ extern int hwasan_inited;
extern bool hwasan_init_is_running;
extern int hwasan_report_count;
+bool MemIsApp(uptr p);
+
bool ProtectRange(uptr beg, uptr end);
bool InitShadow();
char *GetProcSelfMaps();