-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Make LlvmLibcStackChkFail.Smash test compatible with asan, hwasan #125763
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
Conversation
Previously this test was entirely disabled under asan, but not hwasan. Instead of disabling the test, make the test compatible with both asan and hwasan by disabling sanitizers only on the subroutine that does the stack-smashing.
This makes it possible to start using this test in Fuchsia, where we support hwasan builds. |
@llvm/pr-subscribers-libc Author: Roland McGrath (frobtech) ChangesPreviously this test was entirely disabled under asan, but not Full diff: https://github.com/llvm/llvm-project/pull/125763.diff 1 Files Affected:
diff --git a/libc/test/src/compiler/stack_chk_guard_test.cpp b/libc/test/src/compiler/stack_chk_guard_test.cpp
index 4ec8398c9fc95d..5d5723adcf0241 100644
--- a/libc/test/src/compiler/stack_chk_guard_test.cpp
+++ b/libc/test/src/compiler/stack_chk_guard_test.cpp
@@ -12,19 +12,30 @@
#include "src/string/memset.h"
#include "test/UnitTest/Test.h"
+namespace {
+
TEST(LlvmLibcStackChkFail, Death) {
EXPECT_DEATH([] { __stack_chk_fail(); }, WITH_SIGNAL(SIGABRT));
}
-// Disable the test when asan is enabled so that it doesn't immediately fail
-// after the memset, but before the stack canary is re-checked.
-#ifndef LIBC_HAS_ADDRESS_SANITIZER
+// When https://github.com/llvm/llvm-project/issues/125760 is fixed,
+// this can use the `gnu::` spelling unconditionally.
+#ifdef __clang__
+#define SANITIZER_ATTR_NS clang
+#else
+#define SANITIZER_ATTR_NS gnu
+#endif
+
+// Disable sanitizers such as asan and hwasan that would catch the buffer
+// overrun before it clobbered the stack canary word. Function attributes
+// can't be applied to lambdas before C++23, so this has to be separate.
+[[SANITIZER_ATTR_NS::no_sanitize("all")]] void smash_stack() {
+ int arr[20];
+ LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
+}
+
TEST(LlvmLibcStackChkFail, Smash) {
- EXPECT_DEATH(
- [] {
- int arr[20];
- LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
- },
- WITH_SIGNAL(SIGABRT));
+ EXPECT_DEATH(smash_stack, WITH_SIGNAL(SIGABRT));
}
-#endif // LIBC_HAS_ADDRESS_SANITIZER
+
+} // namespace
|
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.
LGTM pending current comment
Looks like the test is now failing in postsubmit for fullbuild mode with ASAN enabled. https://lab.llvm.org/buildbot/#/builders/171/builds/15242/steps/4/logs/stdio Mind reverting unless it's straightforward to fix forward relatively quickly? |
…ible with asan, hwasan" (#125785) Reverts llvm/llvm-project#125763 This causes failures in asan. More thought is needed.
…san (llvm#125763) Previously this test was entirely disabled under asan, but not hwasan. Instead of disabling the test, make the test compatible with both asan and hwasan by disabling sanitizers only on the subroutine that does the stack-smashing.
…san, hwasan" (llvm#125785) Reverts llvm#125763 This causes failures in asan. More thought is needed.
Previously this test was entirely disabled under asan, but not
hwasan. Instead of disabling the test, make the test compatible
with both asan and hwasan by disabling sanitizers only on the
subroutine that does the stack-smashing.