mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Леонид Юрьев" <leo@yuriev.ru>
To: musl@lists.openwall.com
Subject: ldso pthread finalization
Date: Sun, 26 Feb 2017 12:48:07 +0300	[thread overview]
Message-ID: <CAO2+NUCb+FeqZGhX2-C3782anvbagETVDoaGaR2GaAu_k0sE9w@mail.gmail.com> (raw)

Hi,

In glibc there are a couple of problems. I do not know whether they
are relevant for Musl. However, I think should pay attention.

So, please take in accound two glibc bugs:

1) pthread_key_delete() race with thread finalization.

A race condition could occur between the pthread_key_delete() and the
__nptl_deallocate_tsd().

For instance, __nptl_deallocate_tsd() could call a destructor for the
key, immediately before the pthread_key_delete() invalidates it (from
an another thread), and will continue destructor execution after the
completion of pthread_key_delete().

From a user code this looks as if the corresponding destructor
executes after the key has been removed by pthread_key_delete(), and
there is no way to know whether was destructor called/executed or not.

Suggest add pthread_rwlock_rdlock() for __nptl_deallocate_tsd() and
pthread_rwlock_wrlock() for pthread_key_delete().
== https://sourceware.org/bugzilla/show_bug.cgi?id=21031


2) pthread_key_create() destructors and segfault after a DSO unloading.

The pthread_key_create() and __nptl_deallocate_tsd() do not track the
references to destructor's DSO like the __cxa_thread_atexit_impl().

Therefore the DSO, which holds a destructor's code, could be unloaded
before destructor execution or before deleting a corresponding key.

So in a complex environment there is no way to know whether it is safe
to unload a particular DSO or some tls-destructors are still left.

Suggest this should be fixed or documented, e.g. that the
pthread_create_key() with a destructor should not be used from lib.so.
== https://sourceware.org/bugzilla/show_bug.cgi?id=21032

Regards,
Leonid.


             reply	other threads:[~2017-02-26  9:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-26  9:48 Леонид Юрьев [this message]
2017-02-26 11:41 ` Szabolcs Nagy
2017-02-26 21:33 ` Rich Felker

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=CAO2+NUCb+FeqZGhX2-C3782anvbagETVDoaGaR2GaAu_k0sE9w@mail.gmail.com \
    --to=leo@yuriev.ru \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).