-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[sanitizer-common][Darwin] Improve mach_vm_region_recurse error handling #158670
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
33 changes: 33 additions & 0 deletions
33
compiler-rt/test/asan/TestCases/Darwin/sandbox-vm-region-recurse.cpp
This file contains hidden or 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,33 @@ | ||
// Check that if mach_vm_region_recurse is disallowed by sandbox, we report a message saying so. | ||
|
||
// RUN: %clangxx_asan -O0 %s -o %t | ||
// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny syscall-mig (kernel-mig-routine mach_vm_region_recurse))' %t 2>&1 | FileCheck --check-prefix=CHECK-DENY %s | ||
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ALLOW %s | ||
// RUN: %clangxx_asan -O3 %s -o %t | ||
// RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny syscall-mig (kernel-mig-routine mach_vm_region_recurse))' %t 2>&1 | FileCheck --check-prefix=CHECK-DENY %s | ||
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ALLOW %s | ||
|
||
// sandbox-exec isn't available on iOS | ||
// UNSUPPORTED: ios | ||
|
||
// x86_64 does not use ASAN_SHADOW_OFFSET_DYNAMIC | ||
// UNSUPPORTED: x86_64-darwin || x86_64h-darwin | ||
|
||
#include <stdlib.h> | ||
|
||
int main() { | ||
char *x = (char *)malloc(10 * sizeof(char)); | ||
free(x); | ||
return x[5]; | ||
// CHECK-ALLOW: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} | ||
// CHECK-DENY-NOT: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}} | ||
// CHECK-ALLOW: {{READ of size 1 at 0x.* thread T0}} | ||
// CHECK-ALLOW: {{ #0 0x.* in main}} | ||
// CHECK-ALLOW: {{freed by thread T0 here:}} | ||
// CHECK-ALLOW: {{ #0 0x.* in free}} | ||
// CHECK-ALLOW: {{ #1 0x.* in main}} | ||
// CHECK-ALLOW: {{previously allocated by thread T0 here:}} | ||
// CHECK-ALLOW: {{ #0 0x.* in malloc}} | ||
// CHECK-ALLOW: {{ #1 0x.* in main}} | ||
// CHECK-DENY: {{.*HINT: Ensure mach_vm_region_recurse is allowed under sandbox}} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.
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 would move this part up, to follow the 'early return/exit/Die' principle, otherwise I find it a bit harder to read (else as applied to what condition(s)? Once KERN_DENIED handling is out of the way, the following happy path logic has less variables (i.e. there's one less
} else if () {
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 knew I saw it somewhere but only found it now, in Dan's comments to your other PR:
https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
Uh oh!
There was an error while loading. Please reload this page.
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.
Let's see what @DanBlackwell thinks, but I sort of prefer it the way it is right now since all of the branches are
kr == <something>
(it's basically a switch: but we can't do that here easily because of thebreak
...). IMO it would be worse to try to move both of the early exits aboveThere 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 agree this feels a little clunky, but the point about the
else
here being equivalent to thedefault
case of a switch is why I think the current layout is fine. And there are enough comments here to understand why we're setting the different variables.