// Duplicate tid. gettid(2) bug? Seeing this would be very upsetting.
ASSERT_FALSE(tids.contains(tid));
// Uninitialized guard. Our bug. Note this is potentially flaky; we _could_ // get four random zero bytes, but it should be vanishingly unlikely.
ASSERT_NE(guard, nullptr);
#ifdefined(__BIONIC__) // bionic always has the global too.
ASSERT_EQ(__stack_chk_guard, reinterpret_cast<uintptr_t>(guard)); #endif
tids.insert(tid);
guards.insert(guard);
}
};
TEST(stack_protector, same_guard_per_thread) { // Everyone has the TLS slot set, even if their stack protector // implementation doesn't yet use it.
stack_protector_checker checker;
// Check the main thread.
ASSERT_EQ(getpid(), gettid()); // We are the main thread, right?
checker.Check();
// Both bionic and glibc use the same guard for every thread.
ASSERT_EQ(1U, checker.guards.size());
}
TEST(stack_protector, global_guard) { #ifdefined(__BIONIC__) // Bionic always has a global, even if it's using TLS.
ASSERT_NE(0, gettid());
ASSERT_NE(0U, __stack_chk_guard); #else
GTEST_SKIP() << "glibc doesn't have a global __stack_chk_guard"; #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;
}
using stack_protector_DeathTest = SilentDeathTest;
TEST_F(stack_protector_DeathTest, modify_stack_protector) { // In another file to prevent inlining, which removes stack protection. externvoid modify_stack_protector_test();
if (stack_mte_enabled()) {
GTEST_SKIP() << "Stack MTE is enabled, stack protector is not available";
} elseif (hwasan_enabled()) {
GTEST_SKIP() << "HWASan is enabled, stack protector is not testable";
} else {
ASSERT_EXIT(modify_stack_protector_test(), testing::KilledBySignal(SIGABRT), "stack corruption detected");
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.