Skip to content

Commit 1e7624c

Browse files
authored
[libc] Make LlvmLibcStackChkFail.Smash test compatible with asan, hwasan (#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.
1 parent 7043895 commit 1e7624c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

libc/test/src/compiler/stack_chk_guard_test.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@
1212
#include "src/string/memset.h"
1313
#include "test/UnitTest/Test.h"
1414

15+
namespace {
16+
1517
TEST(LlvmLibcStackChkFail, Death) {
1618
EXPECT_DEATH([] { __stack_chk_fail(); }, WITH_SIGNAL(SIGABRT));
1719
}
1820

19-
// Disable the test when asan is enabled so that it doesn't immediately fail
20-
// after the memset, but before the stack canary is re-checked.
21-
#ifndef LIBC_HAS_ADDRESS_SANITIZER
21+
// Disable sanitizers such as asan and hwasan that would catch the buffer
22+
// overrun before it clobbered the stack canary word. Function attributes
23+
// can't be applied to lambdas before C++23, so this has to be separate. When
24+
// https://github.com/llvm/llvm-project/issues/125760 is fixed, this can use
25+
// the modern spelling [[gnu::no_sanitize(...)]] without conditionalization.
26+
__attribute__((no_sanitize("all"))) void smash_stack() {
27+
int arr[20];
28+
LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
29+
}
30+
2231
TEST(LlvmLibcStackChkFail, Smash) {
23-
EXPECT_DEATH(
24-
[] {
25-
int arr[20];
26-
LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
27-
},
28-
WITH_SIGNAL(SIGABRT));
32+
EXPECT_DEATH(smash_stack, WITH_SIGNAL(SIGABRT));
2933
}
30-
#endif // LIBC_HAS_ADDRESS_SANITIZER
34+
35+
} // namespace

0 commit comments

Comments
 (0)