-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWASAN] Prevent SEGV in report near inaccessible memory (#66861)
We can't use IsAccessibleMemoryRange on short granule check because of performance impact. However we can prevent crashing if report prints out "Tags for short granules around the buggy address".
- Loading branch information
1 parent
e764ec6
commit 2613c77
Showing
2 changed files
with
42 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: %clangxx_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
|
||
#include <sanitizer/hwasan_interface.h> | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/mman.h> | ||
#include <unistd.h> | ||
|
||
int main(int argc, char **argv) { | ||
const size_t kPS = sysconf(_SC_PAGESIZE); | ||
|
||
void *r = nullptr; | ||
int res = posix_memalign(&r, kPS, 2 * kPS); | ||
if (res) { | ||
perror("Failed to mmap: "); | ||
abort(); | ||
} | ||
|
||
r = __hwasan_tag_pointer(r, 0); | ||
__hwasan_tag_memory(r, 1, 2 * kPS); | ||
|
||
// Disable access to the page just after tag-mismatch report address. | ||
res = mprotect((char*)r + kPS, kPS, PROT_NONE); | ||
if (res) { | ||
perror("Failed to mprotect: "); | ||
abort(); | ||
} | ||
|
||
// Trigger tag-mismatch report. | ||
return *((char*)r + kPS - 1); | ||
} | ||
|
||
// CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address | ||
// CHECK: Memory tags around the buggy address | ||
// CHECK: Tags for short granules around | ||
|
||
// Check that report is complete. | ||
// CHECK: SUMMARY: HWAddressSanitizer |