-
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] Use ErrorAction::Recover in interceptors #74000
[hwasan] Use ErrorAction::Recover in interceptors #74000
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) ChangesFull diff: https://github.com/llvm/llvm-project/pull/74000.diff 2 Files Affected:
diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index d9237cf9b8e3bf9..ee7166c942bbe9a 100644
--- a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
@@ -36,10 +36,10 @@ struct HWAsanInterceptorContext {
const char *interceptor_name;
};
-# define ACCESS_MEMORY_RANGE(ctx, offset, size, access) \
- do { \
- __hwasan::CheckAddressSized<ErrorAction::Abort, access>((uptr)offset, \
- size); \
+# define ACCESS_MEMORY_RANGE(ctx, offset, size, access) \
+ do { \
+ __hwasan::CheckAddressSized<ErrorAction::Recover, access>((uptr)offset, \
+ size); \
} while (0)
# define HWASAN_READ_RANGE(ctx, offset, size) \
diff --git a/compiler-rt/test/hwasan/TestCases/memset-recover.cpp b/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
new file mode 100644
index 000000000000000..e29e7c412033e2b
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
@@ -0,0 +1,32 @@
+// RUN: %clangxx_hwasan %s -o %t
+// RUN: %env_hwasan_opts=halt_on_error=0 not %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST --check-prefixes=CHECK,RECOVER
+// RUN: %env_hwasan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST
+
+#include <sanitizer/hwasan_interface.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+
+__attribute__((no_sanitize("hwaddress"))) void
+ForceCallInterceptor(void *p, int c, size_t size) {
+ memset(p, c, size) == nullptr;
+}
+
+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);
+ void *volatile p2 = p;
+ for (int i = 0; p2 == p; p2 = __hwasan_tag_pointer(p, ++i)) {
+ }
+ ForceCallInterceptor(p2, 0, size);
+ free(p);
+ fprintf(stderr, "RETURN_FROM_TEST\n");
+ return 0;
+ // CHECK: HWAddressSanitizer: tag-mismatch on address
+ // CHECK: WRITE of size 4
+ // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memset-recover.cpp:[[@LINE-28]]
+ // RECOVER: RETURN_FROM_TEST
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
I believe a similar change should also be made to the |
Compiler suppose to generate noreturn calls for them. |
I misread what you asked. |
@vitalybuka I'm trying to backport the fixes to the GCC branches. Do I just need to backport these 4 commits? |
This cherry-picks and squashes the differences between commits d3e5c20ab846303874a2a25e5877c72271fc798b..76e1e45922e6709392fb82aac44bebe3dbc2ea63 from LLVM upstream from compiler-rt/lib/hwasan/ to GCC on the changes relevant for GCC. This is required to fix the linked PR. As mentioned in the PR the last sync brought in a bug from upstream[1] where operations became non-recoverable and as such the tests in AArch64 started failing. This cherry picks the fix and there are minor updates needed to GCC after this to fix the cases. [1] llvm/llvm-project#74000 PR sanitizer/112644 Cherry-pick llvm-project revision 672b71cc1003533460a82f06b7d24fbdc02ffd58, 5fcf3bbb1acfe226572474636714ede86fffcce8, 3bded112d02632209bd55fb28c6c5c234c23dec3 and 76e1e45922e6709392fb82aac44bebe3dbc2ea63.
This cherry-picks and squashes the differences between commits d3e5c20ab846303874a2a25e5877c72271fc798b..76e1e45922e6709392fb82aac44bebe3dbc2ea63 from LLVM upstream from compiler-rt/lib/hwasan/ to GCC on the changes relevant for GCC. This is required to fix the linked PR. As mentioned in the PR the last sync brought in a bug from upstream[1] where operations became non-recoverable and as such the tests in AArch64 started failing. This cherry picks the fix and there are minor updates needed to GCC after this to fix the cases. [1] llvm/llvm-project#74000 PR sanitizer/112644 Cherry-pick llvm-project revision 672b71cc1003533460a82f06b7d24fbdc02ffd58, 5fcf3bbb1acfe226572474636714ede86fffcce8, 3bded112d02632209bd55fb28c6c5c234c23dec3 and 76e1e45922e6709392fb82aac44bebe3dbc2ea63.
This cherry-picks and squashes the differences between commits d3e5c20ab846303874a2a25e5877c72271fc798b..76e1e45922e6709392fb82aac44bebe3dbc2ea63 from LLVM upstream from compiler-rt/lib/hwasan/ to GCC on the changes relevant for GCC. This is required to fix the linked PR. As mentioned in the PR the last sync brought in a bug from upstream[1] where operations became non-recoverable and as such the tests in AArch64 started failing. This cherry picks the fix and there are minor updates needed to GCC after this to fix the cases. [1] llvm/llvm-project#74000 PR sanitizer/112644 Cherry-pick llvm-project revision 672b71cc1003533460a82f06b7d24fbdc02ffd58, 5fcf3bbb1acfe226572474636714ede86fffcce8, 3bded112d02632209bd55fb28c6c5c234c23dec3 and 76e1e45922e6709392fb82aac44bebe3dbc2ea63.
This cherry-picks and squashes the differences between commits d3e5c20ab846303874a2a25e5877c72271fc798b..76e1e45922e6709392fb82aac44bebe3dbc2ea63 from LLVM upstream from compiler-rt/lib/hwasan/ to GCC on the changes relevant for GCC. This is required to fix the linked PR. As mentioned in the PR the last sync brought in a bug from upstream[1] where operations became non-recoverable and as such the tests in AArch64 started failing. This cherry picks the fix and there are minor updates needed to GCC after this to fix the cases. [1] llvm/llvm-project#74000 PR sanitizer/112644 Cherry-pick llvm-project revision 672b71cc1003533460a82f06b7d24fbdc02ffd58, 5fcf3bbb1acfe226572474636714ede86fffcce8, 3bded112d02632209bd55fb28c6c5c234c23dec3 and 76e1e45922e6709392fb82aac44bebe3dbc2ea63.
This cherry-picks and squashes the differences between commits d3e5c20ab846303874a2a25e5877c72271fc798b..76e1e45922e6709392fb82aac44bebe3dbc2ea63 from LLVM upstream from compiler-rt/lib/hwasan/ to GCC on the changes relevant for GCC. This is required to fix the linked PR. As mentioned in the PR the last sync brought in a bug from upstream[1] where operations became non-recoverable and as such the tests in AArch64 started failing. This cherry picks the fix and there are minor updates needed to GCC after this to fix the cases. [1] llvm/llvm-project#74000 PR sanitizer/112644 Cherry-pick llvm-project revision 672b71cc1003533460a82f06b7d24fbdc02ffd58, 5fcf3bbb1acfe226572474636714ede86fffcce8, 3bded112d02632209bd55fb28c6c5c234c23dec3 and 76e1e45922e6709392fb82aac44bebe3dbc2ea63.
No description provided.