-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Add AddressSanitizer support to fibers. #2975
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Submodule druntime
updated
3 files
+47 −0 | src/core/thread.d | |
+36 −0 | src/ldc/sanitizer_common.d | |
+119 −0 | src/ldc/sanitizers_optionally_linked.d |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// AddressSanitizer: Test stack overflow detection of an array on a fiber's local stack. | ||
|
||
// REQUIRES: ASan, RTSupportsSanitizers | ||
|
||
// RUN: %ldc -g -fsanitize=address %s -of=%t%exe && not %t%exe 2>&1 | FileCheck %s | ||
// RUN: %ldc -g -fsanitize=address %s -of=%t%exe -d-version=BAD_AFTER_YIELD && not %t%exe 2>&1 | FileCheck %s | ||
|
||
import core.thread; | ||
|
||
// Note: the ordering of `foo` and `prefoo` is intentional to ease FileCheck checking line numbers, | ||
// because of the order in which ASan reports the stack buffer overflow. | ||
|
||
void foo(int* ptr) | ||
{ | ||
version (BAD_AFTER_YIELD) | ||
Fiber.yield(); | ||
|
||
// CHECK: stack-buffer-overflow | ||
// CHECK: WRITE of size 4 | ||
// CHECK-NEXT: #0 {{.*}} in {{.*foo.*}} {{.*}}asan_fiber.d:[[@LINE+1]] | ||
ptr[10] = 1; | ||
|
||
} | ||
|
||
// CHECK-NOT: wild pointer | ||
// CHECK: Address {{.*}} is located in stack of | ||
// CHECK-NEXT: #0 {{.*}} in {{.*prefoo.*}} {{.*}}asan_fiber.d:[[@LINE+1]] | ||
void prefoo() | ||
{ | ||
int[10] a; | ||
foo(&a[0]); | ||
} | ||
|
||
void main() | ||
{ | ||
auto fib = new Fiber(&prefoo); | ||
fib.call(); | ||
version (BAD_AFTER_YIELD) | ||
fib.call(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// AddressSanitizer: Test stack overflow detection inside a fiber of an array on main's stack. | ||
|
||
// REQUIRES: ASan, RTSupportsSanitizers | ||
|
||
// RUN: %ldc -g -fsanitize=address %s -of=%t1%exe && not %t1%exe 2>&1 | FileCheck %s | ||
// RUN: %ldc -g -fsanitize=address %s -of=%t22%exe -d-version=BAD_AFTER_YIELD && not %t22%exe 2>&1 | FileCheck %s | ||
|
||
// Test with fake stack enabled | ||
// RUN: env %env_asan_opts=detect_stack_use_after_return=true not %t1%exe 2>&1 | FileCheck %s --check-prefix=FAKESTACK | ||
// RUN: env %env_asan_opts=detect_stack_use_after_return=true not %t22%exe 2>&1 | FileCheck %s --check-prefix=FAKESTACK | ||
|
||
import core.thread; | ||
|
||
void foo(int* arr) | ||
{ | ||
version (BAD_AFTER_YIELD) | ||
Fiber.yield(); | ||
|
||
// CHECK: stack-buffer-overflow | ||
// CHECK: WRITE of size 4 | ||
// CHECK-NEXT: #0 {{.*}} in {{.*foo.*}} {{.*}}asan_fiber_main.d:[[@LINE+1]] | ||
arr[10] = 1; // out-of-bounds write | ||
} | ||
|
||
// Without fake stack, ASan only keeps track of the current stack and thus reports | ||
// the bad memory location as a "wild pointer". | ||
// But with fake stack enabled we get something much better: | ||
// FAKESTACK: Address {{.*}} is located in stack of | ||
// FAKESTACK: #0 {{.*}} in {{.*main.*}} {{.*}}asan_fiber_main.d:[[@LINE+1]] | ||
void main() | ||
{ | ||
int[10] a; | ||
int b; | ||
|
||
// Use an extra variable instead of passing `&a[0]` directly to `foo`. | ||
// This is to keep `a` on the stack: `ptr` may be heap allocated because | ||
// it is used in the lambda (delegate). | ||
int* ptr = &a[0]; | ||
auto fib = new Fiber(() => foo(ptr)); | ||
fib.call(); | ||
version (BAD_AFTER_YIELD) | ||
fib.call(); | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but a cached
RT_SUPPORT_SANITIZERS
CMake variable might be1
instead ofON
. I think that's why I addedldc/CMakeLists.txt
Lines 483 to 488 in 4b101ba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge anyway in order to move forward.