• Jinoh Kang's avatar
    ntdll: Don't report user (PE) stack via pthread_attr_setstack(). · df5f9b7d
    Jinoh Kang authored
    Today, NtCreateThreadEx() passes to pthread_attr_setstack() an address
    range that spans both the user (PE) stack and the kernel (Unix) stack.
    
    pthread_attr_setstack() accepts an address range that will be used as
    the initial stack area for the thread created by pthread_create().  It
    is often assumed that the initial stack will be available for the entire
    duration of the thread's lifetime.
    
    This assumption, however, conflicts with how Win32 fibers operate.
    Fiber APIs allow the thread's initial stack to be freed before the
    thread exits, or kept alive beyond the point of thread's termination.
    This allows the lifetime of the thread's initial stack to be shorter or
    longer than the originating thread's lifetime.  This is possible because
    each fiber has its own stack and context, and ConvertThreadToFiber()
    transfers the current thread's stack to a new fiber.
    
    This specifically causes problems in Glibc v2.31 and earlier.  These
    Glibc versions have a bug where madvise(2) with the MADV_DONTNEED flag
    is called on the initial stack area on thread exit, even when the stack
    was user-supplied (via pthread_attr_setstack).  Therefore, the kernel
    may zero out any portion of the initial stack at any time after the
    originating thread terminates, even if the stack no longer belongs to
    the current thread (either freed and reallocated, or owned by a fiber).
    This may ultimately lead to memory corruption.
    
    Fix this by only passing the syscall (kernel) portion of the stack to
    pthread_attr_setstack().
    df5f9b7d
Name
Last commit
Last update
..
cdrom.c Loading commit data...
debug.c Loading commit data...
dwarf.h Loading commit data...
env.c Loading commit data...
file.c Loading commit data...
loader.c Loading commit data...
loadorder.c Loading commit data...
process.c Loading commit data...
registry.c Loading commit data...
security.c Loading commit data...
serial.c Loading commit data...
server.c Loading commit data...
signal_arm.c Loading commit data...
signal_arm64.c Loading commit data...
signal_i386.c Loading commit data...
signal_x86_64.c Loading commit data...
socket.c Loading commit data...
sync.c Loading commit data...
system.c Loading commit data...
tape.c Loading commit data...
thread.c Loading commit data...
unix_private.h Loading commit data...
virtual.c Loading commit data...