Disable stack protector test with stack MTE
Obviously stack MTE conflates with the stack protector test. It doesn't
conflate with heap MTE (which we're expecting to push more broadly as
part of the -eng build), and so we want to keep this test working under
heap-mte scenarios as well.
Hence, the check-if-stack-variable-is-tagged test, and only under that
case, we skip.
Test: atest bionic-unit-tests on a fullmte device (with stack MTE turned
back on and the new compiler).
Bug: 320448268
Change-Id: I2ecee8a7c46416883235bf5c4ee2de9408047829
diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp
index a95e037..c4be78c 100644
--- a/tests/stack_protector_test.cpp
+++ b/tests/stack_protector_test.cpp
@@ -28,6 +28,7 @@
#include <android-base/silent_death_test.h>
+#include "platform/bionic/mte.h"
#include "private/bionic_tls.h"
extern "C" pid_t gettid(); // glibc defines this but doesn't declare it anywhere.
@@ -100,16 +101,44 @@
#endif
}
+// Make sure that a stack variable (`*p`) is tagged under MTE, by forcing the
+// stack safety analysis to fail.
+int z;
+__attribute__((noinline)) void escape_stack_safety_analysis(int* p) {
+ *p = z;
+}
+
+bool stack_mte_enabled() {
+ if (!mte_supported()) return false;
+ int stack_variable;
+ escape_stack_safety_analysis(&stack_variable);
+#if defined(__aarch64__)
+ return reinterpret_cast<uintptr_t>(&stack_variable) & (0xfull << 56);
+#else // !defined(__aarch64__)
+ return false;
+#endif // defined(__aarch64__)
+}
+
+bool hwasan_enabled() {
+#if __has_feature(hwaddress_sanitizer)
+ return true;
+#else
+ return false;
+#endif // __has_feature(hwaddress_sanitizer)
+}
+
using stack_protector_DeathTest = SilentDeathTest;
TEST_F(stack_protector_DeathTest, modify_stack_protector) {
// In another file to prevent inlining, which removes stack protection.
extern void modify_stack_protector_test();
-#if __has_feature(hwaddress_sanitizer)
- ASSERT_EXIT(modify_stack_protector_test(),
- testing::KilledBySignal(SIGABRT), "tag-mismatch");
-#else
- ASSERT_EXIT(modify_stack_protector_test(),
- testing::KilledBySignal(SIGABRT), "stack corruption detected");
-#endif
+
+ if (stack_mte_enabled()) {
+ GTEST_SKIP() << "Stack MTE is enabled, stack protector is not available";
+ } else if (hwasan_enabled()) {
+ ASSERT_EXIT(modify_stack_protector_test(), testing::KilledBySignal(SIGABRT), "tag-mismatch");
+ } else {
+ ASSERT_EXIT(modify_stack_protector_test(), testing::KilledBySignal(SIGABRT),
+ "stack corruption detected");
+ }
}