-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HWASAN] Don't instrument loads from global if globals are not tagged #86774
Merged
vitalybuka
merged 10 commits into
main
from
users/vitalybuka/spr/hwasan-dont-instrument-loads-from-global-if-globals-are-not-tagged
Mar 27, 2024
Merged
[HWASAN] Don't instrument loads from global if globals are not tagged #86774
vitalybuka
merged 10 commits into
main
from
users/vitalybuka/spr/hwasan-dont-instrument-loads-from-global-if-globals-are-not-tagged
Mar 27, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) ChangesFull diff: https://github.com/llvm/llvm-project/pull/86774.diff 3 Files Affected:
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 96fd530be33318..f89a22d951a9f7 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -790,6 +790,14 @@ bool HWAddressSanitizer::ignoreAccess(Instruction *Inst, Value *Ptr) {
if (SSI && SSI->stackAccessIsSafe(*Inst))
return true;
}
+
+ GlobalVariable *G = dyn_cast<GlobalVariable>(getUnderlyingObject(Ptr));
+ if (G) {
+ if (!InstrumentGlobals)
+ return true;
+ // TODO: Optimize inbound global accesses, like Asan `instrumentMop`.
+ }
+
return false;
}
diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll b/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll
index e59701253d8bc1..11ac88c40c2ed6 100644
--- a/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll
+++ b/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll
@@ -13,22 +13,6 @@ define dso_local noundef i32 @_Z3tmpv() sanitize_hwaddress {
; OFF-LABEL: define dso_local noundef i32 @_Z3tmpv(
; OFF-SAME: ) #[[ATTR0:[0-9]+]] {
; OFF-NEXT: entry:
-; OFF-NEXT: [[TMP12:%.*]] = load i64, ptr @__hwasan_tls, align 8
-; OFF-NEXT: [[TMP1:%.*]] = or i64 [[TMP12]], 4294967295
-; OFF-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP1]], 1
-; OFF-NEXT: [[TMP2:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr
-; OFF-NEXT: [[TMP3:%.*]] = lshr i64 ptrtoint (ptr @x to i64), 56
-; OFF-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i8
-; OFF-NEXT: [[TMP5:%.*]] = and i64 ptrtoint (ptr @x to i64), 72057594037927935
-; OFF-NEXT: [[TMP6:%.*]] = lshr i64 [[TMP5]], 4
-; OFF-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP6]]
-; OFF-NEXT: [[TMP8:%.*]] = load i8, ptr [[TMP7]], align 1
-; OFF-NEXT: [[TMP9:%.*]] = icmp ne i8 [[TMP4]], [[TMP8]]
-; OFF-NEXT: br i1 [[TMP9]], label [[TMP10:%.*]], label [[TMP11:%.*]], !prof [[PROF1:![0-9]+]]
-; OFF: 10:
-; OFF-NEXT: call void @llvm.hwasan.check.memaccess.shortgranules(ptr [[TMP2]], ptr @x, i32 2)
-; OFF-NEXT: br label [[TMP11]]
-; OFF: 11:
; OFF-NEXT: [[TMP0:%.*]] = load i32, ptr @x, align 4
; OFF-NEXT: ret i32 [[TMP0]]
;
diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll
index 079d7224128301..62fd7a16715693 100644
--- a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll
+++ b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll
@@ -54,7 +54,6 @@ define dso_local noundef i1 @_Z6targetv() sanitize_hwaddress {
; CHECK: sw.bb1:
; CHECK-NEXT: br label [[RETURN]]
; CHECK: while.body:
-; CHECK-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[TMP16]], ptr @stackbuf, i32 19)
; CHECK-NEXT: store ptr [[BUF_HWASAN]], ptr @stackbuf, align 8
; CHECK-NEXT: call void @may_jump()
; CHECK-NEXT: br label [[RETURN]]
|
Created using spr 1.3.4 [skip ci]
Created using spr 1.3.4 [skip ci]
thurstond
approved these changes
Mar 27, 2024
Created using spr 1.3.4 [skip ci]
fmayer
approved these changes
Mar 27, 2024
Created using spr 1.3.4 [skip ci]
vitalybuka
changed the base branch from
users/vitalybuka/spr/main.hwasan-dont-instrument-loads-from-global-if-globals-are-not-tagged
to
main
March 27, 2024 20:42
vitalybuka
deleted the
users/vitalybuka/spr/hwasan-dont-instrument-loads-from-global-if-globals-are-not-tagged
branch
March 27, 2024 20:43
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.