diff options
author | Vitaly Buka <vitalybuka@google.com> | 2023-04-25 17:48:24 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2023-04-26 19:27:19 -0700 |
commit | b5595836bc2636eab4b4902e7e589bdd14615318 (patch) | |
tree | 937250f0dc4fbfc14f455bc19b57b9fd9a602cb3 /llvm/lib | |
parent | 7ac72cea0ee9f676e79f16521c7e3f0d2ce3a678 (diff) | |
download | llvm-b5595836bc2636eab4b4902e7e589bdd14615318.zip llvm-b5595836bc2636eab4b4902e7e589bdd14615318.tar.gz llvm-b5595836bc2636eab4b4902e7e589bdd14615318.tar.bz2 |
[HWASAN] Support tagged stack pointer
If stack was allocated using regular allocator, it may be tagged
and it will make memToShadow calculate invalid offset.
Also when UAR tag should be the tag of the stack frame pointer.
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D149228
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index a12a4c0..e6e570e 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -994,7 +994,8 @@ void HWAddressSanitizer::tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag, ConstantInt::get(IntptrTy, AlignedSize)}); } else { size_t ShadowSize = Size >> Mapping.Scale; - Value *ShadowPtr = memToShadow(IRB.CreatePointerCast(AI, IntptrTy), IRB); + Value *AddrLong = untagPointer(IRB, IRB.CreatePointerCast(AI, IntptrTy)); + Value *ShadowPtr = memToShadow(AddrLong, IRB); // If this memset is not inlined, it will be intercepted in the hwasan // runtime library. That's OK, because the interceptor skips the checks if // the address is in the shadow region. @@ -1070,7 +1071,12 @@ Value *HWAddressSanitizer::getAllocaTag(IRBuilder<> &IRB, Value *StackTag, } Value *HWAddressSanitizer::getUARTag(IRBuilder<> &IRB) { - return ConstantInt::get(IntptrTy, 0); + Value *StackPointerLong = getSP(IRB); + Value *UARTag = + applyTagMask(IRB, IRB.CreateLShr(StackPointerLong, PointerTagShift)); + + UARTag->setName("hwasan.uar.tag"); + return UARTag; } // Add a tag to an address. |