diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-20 07:45:24 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-20 07:45:24 +0000 |
commit | cd2c7a528d2cce03800e2d526df2cc7d5eadebdb (patch) | |
tree | ff9761ab0001c64f72c657e2010e19029528fc15 | |
parent | 38a5084dc09bef680af38be4c68ce429ab3f5d72 (diff) | |
parent | 4994552198faf64cdce1f083df943b791a1d575b (diff) | |
download | bionic-cd2c7a528d2cce03800e2d526df2cc7d5eadebdb.tar.gz |
release-request-42a2a3ad-8c90-4c84-a0ad-5d067beb8e30-for-git_oc-mr1-release-4349323 snap-temp-L16100000104414353
Change-Id: Ie947e51a6314ac95a62b9da8e7b0c63b64269681
-rw-r--r-- | libc/bionic/pthread_internal.cpp | 10 | ||||
-rw-r--r-- | tests/cfi_test.cpp | 17 | ||||
-rw-r--r-- | tests/libs/cfi_test_lib.cpp | 7 |
3 files changed, 27 insertions, 7 deletions
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp index abd403bd4..829194cc7 100644 --- a/libc/bionic/pthread_internal.cpp +++ b/libc/bionic/pthread_internal.cpp @@ -104,9 +104,13 @@ pthread_internal_t* __pthread_internal_find(pthread_t thread_id) { // Check if we're looking for ourselves before acquiring the lock. if (thread == __get_thread()) return thread; - ScopedReadLock locker(&g_thread_list_lock); - for (pthread_internal_t* t = g_thread_list; t != nullptr; t = t->next) { - if (t == thread) return thread; + { + // Make sure to release the lock before the abort below. Otherwise, + // some apps might deadlock in their own crash handlers (see b/6565627). + ScopedReadLock locker(&g_thread_list_lock); + for (pthread_internal_t* t = g_thread_list; t != nullptr; t = t->next) { + if (t == thread) return thread; + } } // Historically we'd return null, but diff --git a/tests/cfi_test.cpp b/tests/cfi_test.cpp index 088dda603..5e2518f07 100644 --- a/tests/cfi_test.cpp +++ b/tests/cfi_test.cpp @@ -22,6 +22,10 @@ #include "gtest_globals.h" #include "utils.h" +#if defined(__BIONIC__) +#include "private/CFIShadow.h" +#endif + // Private libdl interface. extern "C" { void __cfi_slowpath(uint64_t CallSiteTypeId, void* Ptr); @@ -40,15 +44,16 @@ TEST(cfi_test, basic) { EXPECT_NE(0U, __cfi_shadow_size()); #define SYM(type, name) auto name = reinterpret_cast<type>(dlsym(handle, #name)) - SYM(int (*)(), get_count); + SYM(size_t (*)(), get_count); SYM(uint64_t(*)(), get_last_type_id); SYM(void* (*)(), get_last_address); SYM(void* (*)(), get_last_diag); SYM(void* (*)(), get_global_address); SYM(void (*)(uint64_t, void*, void*), __cfi_check); + SYM(char*, bss); #undef SYM - int c = get_count(); + size_t c = get_count(); // 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. @@ -88,6 +93,14 @@ TEST(cfi_test, basic) { EXPECT_DEATH(__cfi_slowpath(46, p), ""); free(p); + // 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(); diff --git a/tests/libs/cfi_test_lib.cpp b/tests/libs/cfi_test_lib.cpp index 959b1020f..9f456d39b 100644 --- a/tests/libs/cfi_test_lib.cpp +++ b/tests/libs/cfi_test_lib.cpp @@ -22,13 +22,16 @@ // present. But it is only used in the bionic loader tests. extern "C" __attribute__((weak)) void __cfi_slowpath(uint64_t, void*); -static int g_count; +static size_t g_count; static uint64_t g_last_type_id; static void* g_last_address; static void* g_last_diag; extern "C" { +// Make sure the library crosses at least one kLibraryAlignment(=256KB) boundary. +char bss[1024 * 1024]; + // Mock a CFI-enabled library without relying on the compiler. __attribute__((aligned(4096))) void __cfi_check(uint64_t CallSiteTypeId, void* TargetAddr, void* Diag) { @@ -38,7 +41,7 @@ __attribute__((aligned(4096))) void __cfi_check(uint64_t CallSiteTypeId, void* T g_last_diag = Diag; } -int get_count() { +size_t get_count() { return g_count; } |