[PATCH] D84351: [MSAN] Never allow checking calls to __sanitizer_unaligned_{load,store}

Gui Andrade via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 22 11:20:18 PDT 2020


guiand created this revision.
guiand added reviewers: eugenis, vitalybuka.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

These functions expect the caller to always pass shadows over TLS.

Split off of https://reviews.llvm.org/D83427.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84351

Files:
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -3585,6 +3585,12 @@
       maybeMarkSanitizerLibraryCallNoBuiltin(Call, TLI);
     }
     IRBuilder<> IRB(&CB);
+    bool MayCheckCall = ClEagerChecks;
+    if (Function *Func = CB.getCalledFunction()) {
+      // __sanitizer_unaligned_{load,store} functions may be called by users
+      // and always expects shadows in the TLS. So don't check them.
+      MayCheckCall &= !Func->getName().startswith("__sanitizer_unaligned");
+    }
 
     unsigned ArgOffset = 0;
     LLVM_DEBUG(dbgs() << "  CallSite: " << CB << "\n");
@@ -3610,7 +3616,7 @@
 
       bool ByVal = CB.paramHasAttr(i, Attribute::ByVal);
       bool NoUndef = CB.paramHasAttr(i, Attribute::NoUndef);
-      bool EagerCheck = ClEagerChecks && !ByVal && NoUndef;
+      bool EagerCheck = MayCheckCall && !ByVal && NoUndef;
 
       if (EagerCheck) {
         insertShadowCheck(A, &CB);
@@ -3666,7 +3672,7 @@
     if (isa<CallInst>(CB) && cast<CallInst>(CB).isMustTailCall())
       return;
 
-    if (ClEagerChecks && CB.hasRetAttr(Attribute::NoUndef)) {
+    if (MayCheckCall && CB.hasRetAttr(Attribute::NoUndef)) {
       setShadow(&CB, getCleanShadow(&CB));
       setOrigin(&CB, getCleanOrigin());
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84351.279893.patch
Type: text/x-patch
Size: 1437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200722/08e30ef8/attachment.bin>


More information about the llvm-commits mailing list