diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2018-04-04 20:44:59 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2018-04-04 20:44:59 +0000 |
commit | 1f1a7a719d9ead1baa9bc38398cae166a0a30b2e (patch) | |
tree | 00b32657a5256899ea083696396ce8834001d4b2 /llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | |
parent | 05f0bae318545adbfa80bb36fcdf2076ff743864 (diff) | |
download | bcm5719-llvm-1f1a7a719d9ead1baa9bc38398cae166a0a30b2e.tar.gz bcm5719-llvm-1f1a7a719d9ead1baa9bc38398cae166a0a30b2e.zip |
hwasan: add -hwasan-match-all-tag flag
Sometimes instead of storing addresses as is, the kernel stores the address of
a page and an offset within that page, and then computes the actual address
when it needs to make an access. Because of this the pointer tag gets lost
(gets set to 0xff). The solution is to ignore all accesses tagged with 0xff.
This patch adds a -hwasan-match-all-tag flag to hwasan, which allows to ignore
accesses through pointers with a particular pointer tag value for validity.
Patch by Andrey Konovalov.
Differential Revision: https://reviews.llvm.org/D44827
llvm-svn: 329228
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 6365806d1f1..781aaa23841 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -101,6 +101,11 @@ static cl::opt<unsigned long long> ClMappingOffset( cl::desc("offset of hwasan shadow mapping [EXPERIMENTAL]"), cl::Hidden, cl::init(0)); +static cl::opt<int> ClMatchAllTag( + "hwasan-match-all-tag", + cl::desc("don't report bad accesses via pointers with this tag"), cl::Hidden, + cl::init(-1)); + static cl::opt<bool> ClEnableKhwasan( "hwasan-kernel", cl::desc("Enable KernelHWAddressSanitizer instrumentation"), cl::Hidden, cl::init(false)); @@ -330,6 +335,12 @@ void HWAddressSanitizer::instrumentMemAccessInline(Value *PtrLong, bool IsWrite, IRB.CreateLoad(IRB.CreateIntToPtr(ShadowLong, IRB.getInt8PtrTy())); Value *TagMismatch = IRB.CreateICmpNE(PtrTag, MemTag); + if (ClMatchAllTag != -1) { + Value *TagNotIgnored = IRB.CreateICmpNE(PtrTag, + ConstantInt::get(PtrTag->getType(), ClMatchAllTag)); + TagMismatch = IRB.CreateAnd(TagMismatch, TagNotIgnored); + } + TerminatorInst *CheckTerm = SplitBlockAndInsertIfThen(TagMismatch, InsertBefore, !Recover, MDBuilder(*C).createBranchWeights(1, 100000)); |