platform_bionic/libc/private
Adrian-CJ Hung 8c1a14d4f3 Workaround potential access to unmapped stack
Issue:
Process is crashed near the end (startup_handshake_lock.unlock()) in
pthread_create().

The newly created child thread passes this handshake_lock unexpectedly
=> its stack is unmapped & its associated pthread_internal_t data
structure can’t be accessed.

Analysis:
The created child thread should be blocked by startup_handshake_lock.lock()
and enter __futex_wait_ex()

But if the parent thread is in the middle of startup_handshake_lock.unlock():

  void unlock() {
    if (atomic_exchange_explicit(&state, Unlocked, memory_order_seq_cst) == LockedWithWaiter) {  // => the state is modified to Unlocked

    // (a) if the child thread is back to running and pass the while() check in Lock::lock()
    // (b) the child thread executes its start_routine and then pthread_exit
    // (c) the stack of the child thread (where its pthread_internal_t (so the startup_handshake_lock) is located) will be unmapped

     __futex_wake_ex(&state, process_shared, 1);   // => when the parent thread is back to running
                                                   // the “state” & “process_shared” of startup_handshake_lock can’t be accessed (unmapped)
                                                   // so the process will be crashed
    }
  }

Bug: 129744706
Test: Monkey
Change-Id: I55175e8c7ebc2b3b52de8a5602def0667076b974
2019-04-03 11:50:33 +08:00
..
__get_tls.h AArch64: Add initial support for AArch64 2013-12-16 17:00:22 -08:00
bionic_allocator.h Add BionicAllocator::memalign 2019-01-25 15:31:35 -08:00
bionic_arc4random.h Replace TLS_SLOT_BIONIC_PREINIT w/ shared globals 2018-12-04 13:51:56 -08:00
bionic_asm.h Mark __BIONIC_WEAK_FOR_NATIVE_BRIDGE symbols 2017-10-27 10:01:46 +02:00
bionic_asm_arm.h Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
bionic_asm_arm64.h Set __bionic_asm_align to 16 for arm64 2018-06-26 15:58:52 -03:00
bionic_asm_mips.h Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
bionic_asm_tls.h Reassign TLS slot 2 to TLS_SLOT_APP. 2019-01-23 18:48:48 -08:00
bionic_asm_x86.h Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
bionic_asm_x86_64.h Unified sysroot: kill arch-specific include dirs. 2017-10-12 13:19:51 -07:00
bionic_auxv.h Use shared globals so getauxval works earlier 2018-12-04 13:51:46 -08:00
bionic_config.h Use a separate config.h for config like defines. 2014-06-16 23:35:53 -07:00
bionic_constants.h Allocate a small guard region around the shadow call stack. 2018-11-16 14:37:08 -08:00
bionic_ctype.h Use inline ctype functions for ato*/strto* and scanf. 2017-12-19 16:37:01 -08:00
bionic_defs.h Mark __BIONIC_WEAK_FOR_NATIVE_BRIDGE symbols 2017-10-27 10:01:46 +02:00
bionic_elf_tls.h Implement dynamic TLS accesses and allocation 2019-01-25 17:53:01 -08:00
bionic_fdsan.h libc_shared_globals: add a constexpr ctor 2019-01-03 17:11:27 -08:00
bionic_fortify.h bionic_fortify: clarify error message for an out of bounds FD. 2018-03-14 12:37:25 +00:00
bionic_futex.h Modernize codebase by replacing NULL with nullptr 2018-08-02 18:09:44 -07:00
bionic_globals.h Merge "Fix linker self-exec detection" 2019-02-08 22:33:11 +00:00
bionic_ieee.h Fix instances of '#if __LP64__'. 2016-09-15 14:21:28 -07:00
bionic_inline_raise.h Generalize abort's inline_tgkill, use it in fdsan. 2018-08-31 16:39:23 -07:00
bionic_lock.h Workaround potential access to unmapped stack 2019-04-03 11:50:33 +08:00
bionic_macros.h Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00
bionic_malloc.h Allow to reset malloc hooks. 2019-01-28 15:01:50 +00:00
bionic_malloc_dispatch.h Modify malloc common function pointers. 2019-02-07 14:48:34 -08:00
bionic_mbstate.h Include what we use. 2018-01-22 12:20:16 -08:00
bionic_page.h Move PAGE_MASK into <sys/user.h>. 2015-07-28 14:58:37 -07:00
bionic_sigdefs.h Move <sys/_sigdefs.h> and <sys/_errdefs.h> to private. 2016-04-13 17:45:39 -07:00
bionic_ssp.h Simplify __stack_chk_fail, and fix it so we get debuggerd stack traces. 2013-02-14 14:37:34 -08:00
bionic_string_utils.h Fix pthread_getattr_np for the main thread. 2014-08-26 10:36:38 -07:00
bionic_systrace.h Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00
bionic_time_conversions.h Always use CLOCK_MONOTONIC for pthreads and semaphores 2017-08-18 09:11:05 -07:00
bionic_tls.h Reorganize static TLS memory for ELF TLS 2019-01-11 15:34:22 -08:00
bionic_vdso.h Clean up the time(2) implementation. 2018-01-12 15:20:28 -08:00
CachedProperty.h Address a bunch of clang-tidy complaints. 2018-01-19 15:56:12 -08:00
CFIShadow.h Revert "Revert "arm64: expand CFI shadow to cover 48-bit virtual addresses"" 2017-08-03 14:11:28 -07:00
ErrnoRestorer.h Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00
FdPath.h Add POSIX fexecve. 2017-10-18 16:26:17 -07:00
get_cpu_count_from_string.h Fix the way to count online cpus. 2015-09-29 17:49:37 -07:00
grp_pwd.h Require vendor users and groups to start with vendor_ 2018-05-15 14:10:21 -07:00
icu.h Implement <iconv.h>. 2017-08-25 08:47:41 -07:00
KernelArgumentBlock.h Move the abort message to libc_shared_globals 2018-11-28 14:26:14 -08:00
linker_native_bridge.h Reorganize static TLS memory for ELF TLS 2019-01-11 15:34:22 -08:00
NetdClientDispatch.h Replace android_open_proxy with dns_open_proxy 2018-11-19 18:00:37 +08:00
ScopedPthreadMutexLocker.h Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00
ScopedReaddir.h Fix/suppress bionic google-explicit-constructor warnings 2019-01-02 11:04:05 -08:00
ScopedRWLock.h Factor out ScopedRWLock into its own header 2019-01-16 01:11:26 -08:00
ScopedSignalBlocker.h Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00
ScopedSignalHandler.h Fix/suppress bionic google-explicit-constructor warnings 2019-01-02 11:04:05 -08:00
sigrtmin.h Add RT signal to load heapprofd library. 2018-10-18 21:38:06 +01:00
SigSetConverter.h Add sigset64_t and accompanying functions. 2018-01-30 18:47:16 -08:00
thread_private.h Reimplement popen(3)/pclose(3). 2018-07-11 12:15:26 -07:00
WriteProtected.h Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00