forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWASAN] Enable memcpy and memmove interceptors (llvm#71217)
- Loading branch information
1 parent
fd887a3
commit 3cf9bf3
Showing
4 changed files
with
69 additions
and
22 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
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,32 @@ | ||
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
|
||
#include <sanitizer/hwasan_interface.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
__attribute__((no_sanitize("hwaddress"))) void | ||
ForceCallInterceptor(void *p, const void *a, size_t size) { | ||
memcpy(p, a, size); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
__hwasan_enable_allocator_tagging(); | ||
char a[] = {static_cast<char>(argc), 2, 3, 4}; | ||
int size = sizeof(a); | ||
char *volatile p = (char *)malloc(size); | ||
free(p); | ||
ForceCallInterceptor(p, a, size); | ||
return 0; | ||
// CHECK: HWAddressSanitizer: tag-mismatch on address | ||
// CHECK: WRITE of size 4 | ||
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcpy.cpp:[[@LINE-4]] | ||
// CHECK: Cause: use-after-free | ||
// CHECK: freed by thread | ||
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcpy.cpp:[[@LINE-8]] | ||
// CHECK: previously allocated by thread | ||
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcpy.cpp:[[@LINE-11]] | ||
} |
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,32 @@ | ||
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s | ||
|
||
#include <sanitizer/hwasan_interface.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
__attribute__((no_sanitize("hwaddress"))) void | ||
ForceCallInterceptor(void *p, const void *a, size_t size) { | ||
memmove(p, a, size); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
__hwasan_enable_allocator_tagging(); | ||
char a[] = {static_cast<char>(argc), 2, 3, 4}; | ||
int size = sizeof(a); | ||
char *volatile p = (char *)malloc(size); | ||
free(p); | ||
ForceCallInterceptor(p, a, size); | ||
return 0; | ||
// CHECK: HWAddressSanitizer: tag-mismatch on address | ||
// CHECK: WRITE of size 4 | ||
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memmove.cpp:[[@LINE-4]] | ||
// CHECK: Cause: use-after-free | ||
// CHECK: freed by thread | ||
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memmove.cpp:[[@LINE-8]] | ||
// CHECK: previously allocated by thread | ||
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memmove.cpp:[[@LINE-11]] | ||
} |