From: Dominic Chen <d.c.ddcc@gmail.com>
To: Rich Felker <dalias@libc.org>, fweimer@redhat.com
Cc: musl@lists.openwall.com
Subject: Re: [musl] Incorrect thread TID caching
Date: Wed, 3 Feb 2021 15:21:06 -0500 [thread overview]
Message-ID: <c1944b59-e2ab-d110-b2a1-ca47b93bf521@gmail.com> (raw)
In-Reply-To: <20210203192145.GW23432@brightrain.aerifal.cx>
On 2/3/2021 2:16 AM, Florian Weimer wrote:
> If you use the clone system call wrapper in threading (not fork/vfork)
> mode, you cannot call any libc functions afterwards, including the
> syscall function. Instead, you have to issue direct system calls.
On 2/3/2021 2:21 PM, Rich Felker wrote:
> Unfortunately it's really underdocumented and underexplored what a
> child created with clone() can do. There are definitely limitations --
> for example any usage with CLONE_VM or CLONE_THREAD is restricted not
> to call into libc at all, and might not even be safe whatsoever.
> However basic usage comparable in semantics to _Fork is probably
> supposed to work at least as well as _Fork -- in particular calling
> AS-safe libc functions should work.
I wasn't aware of this behavior, and didn't see any documentation about
this for the glibc clone() wrapper either. This seems to be a big
footgun, and after looking through the history for this code in Chrome,
it looks like they had a similar issue with glibc too.
> BTW does Chrom{e,ium} itself do something with raw clone? If so this
> could be a source of some of the bugs users hit, and it would be great
> to get a clearer picture on what's happening.
The code in question is a unittest for the sandbox, which manually calls
clone with CLONE_NEWPID to fork a child in a PID namespace, then
installs a signal handler and checks that it receives SIGTERM correctly:
https://source.chromium.org/chromium/chromium/src/+/master:sandbox/linux/services/namespace_sandbox_unittest.cc;l=194
. But under musl, raise() uses the cached TID value, so the test
eventually times out.
I missed that the NamespaceSandbox::ForkInNewPidNamespace() function
does manually update the cached TID for glibc after calling the
ForkWithFlags wrapper, so I can just do the same for musl too.
Separately, it looks like glibc used to have a PID cache too, but was
removed after a discussion that you were both involved with:
http://sourceware-org.1504.n7.nabble.com/Caching-of-PID-TID-after-fork-td416394.html
Thanks,
Dominic
next prev parent reply other threads:[~2021-02-03 20:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 4:04 Dominic Chen
2021-02-03 7:16 ` Florian Weimer
2021-02-03 19:21 ` Rich Felker
2021-02-03 20:21 ` Dominic Chen [this message]
2021-02-03 21:01 ` Rich Felker
2021-02-03 22:30 ` Dominic Chen
2021-02-03 22:55 ` Rich Felker
2021-02-15 16:56 ` Rich Felker
2021-02-17 19:49 ` Dominic Chen
2021-02-17 20:11 ` Rich Felker
2021-02-17 21:07 ` Rich Felker
2021-03-12 21:14 ` Dominic Chen
2021-02-04 3:28 ` Carlos O'Donell
2021-02-04 4:22 ` Dominic Chen
2021-02-04 16:15 ` 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=c1944b59-e2ab-d110-b2a1-ca47b93bf521@gmail.com \
--to=d.c.ddcc@gmail.com \
--cc=dalias@libc.org \
--cc=fweimer@redhat.com \
--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).