1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

Fix a few more problem with the recent setxid changes.

This commit is contained in:
Ulrich Drepper
2010-03-09 20:21:12 -08:00
parent 462a5227b0
commit 1d78f2996d
3 changed files with 28 additions and 29 deletions

View File

@ -1,3 +1,11 @@
2010-03-09 Ulrich Drepper <drepper@redhat.com>
* pthread_create.c (__pthread_create_2_1): If priorities are incorrect
and the call fails wake eventually waiting setxid threads. Don't free
stack here if we try starting a thread.
* sysdeps/pthread/createthread.c (do_clone): Only wake setxid waiter
if the clone call failed.
2010-03-08 Andreas Schwab <schwab@redhat.com> 2010-03-08 Andreas Schwab <schwab@redhat.com>
* pthread_create.c (__pthread_create_2_1): Don't set setxid_futex. * pthread_create.c (__pthread_create_2_1): Don't set setxid_futex.

View File

@ -537,33 +537,23 @@ __pthread_create_2_1 (newthread, attr, start_routine, arg)
if (pd->schedparam.sched_priority < minprio if (pd->schedparam.sched_priority < minprio
|| pd->schedparam.sched_priority > maxprio) || pd->schedparam.sched_priority > maxprio)
{ {
err = EINVAL; /* Perhaps a thread wants to change the IDs and if waiting
goto errout; for this stillborn thread. */
if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0)
== -2, 0))
lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE);
__deallocate_stack (pd);
return EINVAL;
} }
} }
/* Pass the descriptor to the caller. */ /* Pass the descriptor to the caller. */
*newthread = (pthread_t) pd; *newthread = (pthread_t) pd;
/* Remember whether the thread is detached or not. In case of an
error we have to free the stacks of non-detached stillborn
threads. */
bool is_detached = IS_DETACHED (pd);
/* Start the thread. */ /* Start the thread. */
err = create_thread (pd, iattr, STACK_VARIABLES_ARGS); return create_thread (pd, iattr, STACK_VARIABLES_ARGS);
if (err != 0)
{
/* Something went wrong. Free the resources. */
if (!is_detached)
{
errout:
__deallocate_stack (pd);
}
return err;
}
return 0;
} }
versioned_symbol (libpthread, __pthread_create_2_1, pthread_create, GLIBC_2_1); versioned_symbol (libpthread, __pthread_create_2_1, pthread_create, GLIBC_2_1);

View File

@ -75,19 +75,17 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr,
int rc = 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); 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)) 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. */
/* Failed. If the thread is detached, remove the TCB here since /* Perhaps a thread wants to change the IDs and if waiting
the caller cannot do this. The caller remembered the thread for this stillborn thread. */
as detached and cannot reverify that it is not since it must if (__builtin_expect (atomic_exchange_acq (&pd->setxid_futex, 0)
not access the thread descriptor again. */ == -2, 0))
if (IS_DETACHED (pd)) lll_futex_wake (&pd->setxid_futex, 1, LLL_PRIVATE);
/* Free the resources. */
__deallocate_stack (pd); __deallocate_stack (pd);
/* We have to translate error codes. */ /* We have to translate error codes. */
@ -120,6 +118,9 @@ do_clone (struct pthread *pd, const struct pthread_attr *attr,
(void) INTERNAL_SYSCALL (tkill, err2, 2, pd->tid, SIGCANCEL); (void) INTERNAL_SYSCALL (tkill, err2, 2, pd->tid, SIGCANCEL);
#endif #endif
/* We do not free the stack here because the canceled thread
itself will do this. */
return (INTERNAL_SYSCALL_ERROR_P (res, err) return (INTERNAL_SYSCALL_ERROR_P (res, err)
? INTERNAL_SYSCALL_ERRNO (res, err) ? INTERNAL_SYSCALL_ERRNO (res, err)
: 0); : 0);