public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/27054] pthread_atfork handlers that call pthread_atfork deadlock
Date: Wed, 25 May 2022 09:31:28 +0000	[thread overview]
Message-ID: <bug-27054-131-LFJDTyaRo1@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27054-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=27054

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Arjun Shankar <arjun@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=52a103e237329b9f88a28513fe7506ffc3bd8ced

commit 52a103e237329b9f88a28513fe7506ffc3bd8ced
Author: Arjun Shankar <arjun@redhat.com>
Date:   Tue May 24 17:57:36 2022 +0200

    Fix deadlock when pthread_atfork handler calls pthread_atfork or dlclose

    In multi-threaded programs, registering via pthread_atfork,
    de-registering implicitly via dlclose, or running pthread_atfork
    handlers during fork was protected by an internal lock.  This meant
    that a pthread_atfork handler attempting to register another handler or
    dlclose a dynamically loaded library would lead to a deadlock.

    This commit fixes the deadlock in the following way:

    During the execution of handlers at fork time, the atfork lock is
    released prior to the execution of each handler and taken again upon its
    return.  Any handler registrations or de-registrations that occurred
    during the execution of the handler are accounted for before proceeding
    with further handler execution.

    If a handler that hasn't been executed yet gets de-registered by another
    handler during fork, it will not be executed.   If a handler gets
    registered by another handler during fork, it will not be executed
    during that particular fork.

    The possibility that handlers may now be registered or deregistered
    during handler execution means that identifying the next handler to be
    run after a given handler may register/de-register others requires some
    bookkeeping.  The fork_handler struct has an additional field, 'id',
    which is assigned sequentially during registration.  Thus, handlers are
    executed in ascending order of 'id' during 'prepare', and descending
    order of 'id' during parent/child handler execution after the fork.

    Two tests are included:

    * tst-atfork3: Adhemerval Zanella <adhemerval.zanella@linaro.org>
      This test exercises calling dlclose from prepare, parent, and child
      handlers.

    * tst-atfork4: This test exercises calling pthread_atfork and dlclose
      from the prepare handler.

    [BZ #24595, BZ #27054]

    Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2022-05-25  9:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 15:26 [Bug libc/27054] New: " fweimer at redhat dot com
2020-12-11 15:31 ` [Bug libc/27054] " fweimer at redhat dot com
2020-12-15 16:37 ` adhemerval.zanella at linaro dot org
2020-12-15 16:46 ` fweimer at redhat dot com
2022-05-25  9:31 ` cvs-commit at gcc dot gnu.org [this message]
2022-05-30 11:39 ` cvs-commit at gcc dot gnu.org
2022-05-30 15:45 ` cvs-commit at gcc dot gnu.org
2022-05-31 16:24 ` arjun.is at lostca dot se

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=bug-27054-131-LFJDTyaRo1@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).