public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andreas Schwab <schwab@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] nptl: wait for pending setxid request also in detached thread (bug 25942)
Date: Tue, 12 May 2020 15:23:09 +0000 (GMT)	[thread overview]
Message-ID: <20200512152309.1878A386F02B@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4cab20fa49b3ea3e3454fdc4f13bf3828d8efd19

commit 4cab20fa49b3ea3e3454fdc4f13bf3828d8efd19
Author: Andreas Schwab <schwab@suse.de>
Date:   Thu May 7 15:50:09 2020 +0200

    nptl: wait for pending setxid request also in detached thread (bug 25942)
    
    There is a race between __nptl_setxid and exiting detached thread, which
    causes a deadlock on stack_cache_lock.  The deadlock happens in this
    state:
    
    T1: setgroups -> __nptl_setxid (holding stack_cache_lock, waiting on cmdp->cntr == 0)
    T2 (detached, exiting): start_thread -> __deallocate_stack (waiting on stack_cache_lock)
    more threads waiting on stack_cache_lock in pthread_create
    
    For non-detached threads, start_thread waits for its own setxid handler to
    finish before exiting.  Do this for detached threads as well.

Diff:
---
 nptl/pthread_create.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index afd379e89a..a43089065c 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -552,11 +552,7 @@ START_THREAD_DEFN
   advise_stack_range (pd->stackblock, pd->stackblock_size, (uintptr_t) pd,
 		      pd->guardsize);
 
-  /* If the thread is detached free the TCB.  */
-  if (IS_DETACHED (pd))
-    /* Free the TCB.  */
-    __free_tcb (pd);
-  else if (__glibc_unlikely (pd->cancelhandling & SETXID_BITMASK))
+  if (__glibc_unlikely (pd->cancelhandling & SETXID_BITMASK))
     {
       /* Some other thread might call any of the setXid functions and expect
 	 us to reply.  In this case wait until we did that.  */
@@ -572,6 +568,11 @@ START_THREAD_DEFN
       pd->setxid_futex = 0;
     }
 
+  /* If the thread is detached free the TCB.  */
+  if (IS_DETACHED (pd))
+    /* Free the TCB.  */
+    __free_tcb (pd);
+
   /* We cannot call '_exit' here.  '_exit' will terminate the process.
 
      The 'exit' implementation in the kernel will signal when the


                 reply	other threads:[~2020-05-12 15:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200512152309.1878A386F02B@sourceware.org \
    --to=schwab@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).