// Disables debuggerd stack traces to speed up death tests, make them less // noisy in logcat, and avoid expected deaths from showing up in stability // metrics. // We don't use the usual libbase class because (a) we don't care about most // of the signals it blocks but (b) we do need to block SIGILL, which normal // death tests shouldn't ever hit. (It's possible that a design where a // deathtest always declares its expected signals up front is a better one, // and maybe that's an interesting future direction for libbase.) // // We include SIGSEGV because there's a test that passes heap addresses to // __cfi_slowpath and we only map the executable code shadow as readable. // We don't always get SIGSEGV there though: if the heap allocation happens // to be close enough to an executable mapping that its shadow is in the // same page as the executable shadow, we'll get SIGILL/SIGTRAP. class cfi_test_DeathTest : public testing::Test { protected: void SetUp() override { struct sigaction64 action = {.sa_handler = SIG_DFL};
sigaction64(SIGILL, &action, &previous_sigill_);
sigaction64(SIGSEGV, &action, &previous_sigsegv_);
sigaction64(SIGTRAP, &action, &previous_sigtrap_);
}
// CFI check for code inside the DSO. Can't use just any function address - this is only // guaranteed to work for code addresses above __cfi_check. void* code_ptr = reinterpret_cast<char*>(__cfi_check) + 1234; void* diag_ptr = reinterpret_cast<void*>(5678);
__cfi_slowpath_diag(42, code_ptr, diag_ptr);
EXPECT_EQ(42U, get_last_type_id());
EXPECT_EQ(code_ptr, get_last_address());
EXPECT_EQ(diag_ptr, get_last_diag());
EXPECT_EQ(++c, get_count());
// __cfi_slowpath passes nullptr for the Diag argument.
__cfi_slowpath(42, code_ptr);
EXPECT_EQ(42U, get_last_type_id());
EXPECT_EQ(code_ptr, get_last_address());
EXPECT_EQ(nullptr, get_last_diag());
EXPECT_EQ(++c, get_count());
// CFI check for a data address inside the DSO.
__cfi_slowpath(43, get_global_address());
EXPECT_EQ(43U, get_last_type_id());
EXPECT_EQ(get_global_address(), get_last_address());
EXPECT_EQ(++c, get_count());
// CFI check for a function inside _this_ DSO. It either goes to this DSO's __cfi_check, // or (if missing) is simply ignored. Any way, it does not affect the test lib's counters.
__cfi_slowpath(44, reinterpret_cast<void*>(&f));
EXPECT_EQ(43U, get_last_type_id());
EXPECT_EQ(get_global_address(), get_last_address());
EXPECT_EQ(c, get_count());
// Check all the addresses. const size_t bss_size = 1024 * 1024;
static_assert(bss_size >= kLibraryAlignment * 2, "test range not big enough"); for (size_t i = 0; i < bss_size; ++i) {
__cfi_slowpath(47, bss + i);
EXPECT_EQ(++c, get_count());
}
// Load the same library again. void* handle2 = dlopen("libcfi-test.so", RTLD_NOW | RTLD_LOCAL);
ASSERT_TRUE(handle2 != nullptr) << dlerror();
EXPECT_EQ(handle2, handle);
// Check that it is still there.
__cfi_slowpath(43, get_global_address());
EXPECT_EQ(43U, get_last_type_id());
EXPECT_EQ(get_global_address(), get_last_address());
EXPECT_EQ(++c, get_count());
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.