mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-03 00:10:10 +00:00
Fix setxid race with thread creation
This commit is contained in:
parent
01f1f5ee8b
commit
66f1b8eeb2
@ -1,3 +1,14 @@
|
|||||||
|
2010-03-05 Andreas Schwab <schwab@redhat.com>
|
||||||
|
Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* allocatestack.c (setxid_mark_thread): Delay handling of thread if
|
||||||
|
it is creating a thread or it is just being created.
|
||||||
|
* pthread_create.c (start_thread): Wake setxid thread if it is
|
||||||
|
waiting.
|
||||||
|
(__pthread_create_2_1): Initialize setxid_futex.
|
||||||
|
* sysdeps/pthread/createthread.c (do_clone): Wake setxid thread if it
|
||||||
|
is waiting.
|
||||||
|
|
||||||
2010-01-15 Ulrich Drepper <drepper@redhat.com>
|
2010-01-15 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S:
|
* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2002-2007, 2009 Free Software Foundation, Inc.
|
/* Copyright (C) 2002-2007, 2009, 2010 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
||||||
|
|
||||||
@ -380,7 +380,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
|||||||
- TLS_TCB_SIZE - adj);
|
- TLS_TCB_SIZE - adj);
|
||||||
#elif TLS_DTV_AT_TP
|
#elif TLS_DTV_AT_TP
|
||||||
pd = (struct pthread *) (((uintptr_t) attr->stackaddr
|
pd = (struct pthread *) (((uintptr_t) attr->stackaddr
|
||||||
- __static_tls_size - adj)
|
- __static_tls_size - adj)
|
||||||
- TLS_PRE_TCB_SIZE);
|
- TLS_PRE_TCB_SIZE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -546,7 +546,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
|
|||||||
#ifndef __ASSUME_PRIVATE_FUTEX
|
#ifndef __ASSUME_PRIVATE_FUTEX
|
||||||
/* The thread must know when private futexes are supported. */
|
/* The thread must know when private futexes are supported. */
|
||||||
pd->header.private_futex = THREAD_GETMEM (THREAD_SELF,
|
pd->header.private_futex = THREAD_GETMEM (THREAD_SELF,
|
||||||
header.private_futex);
|
header.private_futex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NEED_DL_SYSINFO
|
#ifdef NEED_DL_SYSINFO
|
||||||
@ -969,6 +969,13 @@ setxid_mark_thread (struct xid_command *cmdp, struct pthread *t)
|
|||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
|
/* Wait until this thread is cloned. */
|
||||||
|
if (t->setxid_futex == -1
|
||||||
|
&& ! atomic_compare_and_exchange_bool_acq (&t->setxid_futex, -2, -1))
|
||||||
|
do
|
||||||
|
lll_futex_wait (&t->setxid_futex, -2, LLL_PRIVATE);
|
||||||
|
while (t->setxid_futex == -2);
|
||||||
|
|
||||||
/* Don't let the thread exit before the setxid handler runs. */
|
/* Don't let the thread exit before the setxid handler runs. */
|
||||||
t->setxid_futex = 0;
|
t->setxid_futex = 0;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2002-2007,2008,2009 Free Software Foundation, Inc.
|
/* Copyright (C) 2002-2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
||||||
|
|
||||||
@ -239,6 +239,10 @@ start_thread (void *arg)
|
|||||||
/* Initialize resolver state pointer. */
|
/* Initialize resolver state pointer. */
|
||||||
__resp = &pd->res;
|
__resp = &pd->res;
|
||||||
|
|
||||||
|
/* Allow setxid from now onwards. */
|
||||||
|
if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) == -2, 0))
|
||||||
|
lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE);
|
||||||
|
|
||||||
#ifdef __NR_set_robust_list
|
#ifdef __NR_set_robust_list
|
||||||
# ifndef __ASSUME_SET_ROBUST_LIST
|
# ifndef __ASSUME_SET_ROBUST_LIST
|
||||||
if (__set_robust_list_avail >= 0)
|
if (__set_robust_list_avail >= 0)
|
||||||
@ -538,6 +542,9 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Don't allow setxid until cloned. */
|
||||||
|
pd->setxid_futex = -1;
|
||||||
|
|
||||||
/* Pass the descriptor to the caller. */
|
/* Pass the descriptor to the caller. */
|
||||||
*newthread = (pthread_t) pd;
|
*newthread = (pthread_t) pd;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2002-2007, 2008 Free Software Foundation, Inc.
|
/* Copyright (C) 2002-2007, 2008, 2010 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
||||||
|
|
||||||
@ -28,7 +28,7 @@
|
|||||||
#include "kernel-features.h"
|
#include "kernel-features.h"
|
||||||
|
|
||||||
|
|
||||||
#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
|
#define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
|
||||||
|
|
||||||
/* Unless otherwise specified, the thread "register" is going to be
|
/* Unless otherwise specified, the thread "register" is going to be
|
||||||
initialized with a pointer to the TCB. */
|
initialized with a pointer to the TCB. */
|
||||||
@ -72,8 +72,14 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr,
|
|||||||
that cares whether the thread count is correct. */
|
that cares whether the thread count is correct. */
|
||||||
atomic_increment (&__nptl_nthreads);
|
atomic_increment (&__nptl_nthreads);
|
||||||
|
|
||||||
if (ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags,
|
int rc = ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags,
|
||||||
pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
|
pd, &pd->tid, TLS_VALUE, &pd->tid);
|
||||||
|
|
||||||
|
/* Allow setxid from now onwards. */
|
||||||
|
if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0) == -2, 0))
|
||||||
|
lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE);
|
||||||
|
|
||||||
|
if (__builtin_expect (rc == -1, 0))
|
||||||
{
|
{
|
||||||
atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */
|
atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user