public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Daniel Colascione <dancol@dancol.org>
To: Rich Felker <dalias@libc.org>, Zack Weinberg <zackw@panix.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [RFC] Toward Shareable POSIX Signals
Date: Fri, 09 Mar 2018 20:54:00 -0000	[thread overview]
Message-ID: <18fe6935-67c2-a901-7730-e08625aeebf2@dancol.org> (raw)
In-Reply-To: <20180309202524.GT1436@brightrain.aerifal.cx>

On 03/09/2018 12:25 PM, Rich Felker wrote:
> On Fri, Mar 09, 2018 at 02:30:51PM -0500, Zack Weinberg wrote:
>>> "Just use glib" is of course fundamentally unacceptable. But the
>>> obvious solution is "just use threads" and I don't see why that's not
>>> acceptable. The cost of a thread is miniscule compared to the cost of
>>> a child process, and threads performing synchronous waitpid can
>>> convert the result into whatever type of notification (poll wakeup,
>>> cond var, synchronous handling, etc.) you like.
>>
>> The main problem I see with this idea is, a thread waiting for _any_
>> process can steal the event from a thread waiting for a specific
>> process; this makes it nonviable for any situation where you don't
> 
> I never proposed using a thread that calls wait or waidpid with a
> negative argument, rather one thread per child. 

Understood.

> As long as there is no
> rogue thread in the program doing wait-any, the thread-per-child
> approach lets you emulate pdfork pretty well; programs written around
> this model can use pdfork as a drop-in replacement and eliminate the
> cost of the thread.

My contention is that a thread per child process is infeasible from a 
resource POV and that major subsystem authors will never adopt this 
approach.

Let's be realistic here: lots of systems behave badly due to the 
inadequacies of the wait API. If a better alternative doesn't appear, 
these systems are going to continue behaving badly.

>>> On Fri, Mar 09, 2018 at 05:58:51PM +0100, Florian Weimer wrote:
>>>> But [threads] only works for asynchronous signals.  It's reasonable
>>>> for an application to want to catch synchronous signals (SIGBUS
>>>> when dealing with file mappings, SIGFPE for arithmetic), and there
>>>> is currently no thread-safe or library-safe way at all to do that.
>>>
>>> Yes, as I noted each use case needs to be considered separately to
>>> determine if there's some other better/more-portable/whatnot way it
>>> could be done already. The above applies only to SIGCHLD.
>>>
>>> FWIW I'm rather skeptical of many of the usage cases for synchronous
>>> signals (most are dangerous papering-over of UB for dubious
>>> performance reasons; never-taken "test reg,reg;jz" takes essentially 0
>>> cycles on a modern uarch) but SIGBUS makes it hard to use mmap safely
>>> to begin with. So there's still a lot of material to consider here.
>>
>> If I remember correctly, GCJ tried to use signal handlers to generate
>> NullPointerExceptions not for speed reasons, but for code-size and
>> exception-precision reasons.  But it was never 100% reliable and it
>> might have been better to go with "test reg,reg;jz" + lean harder on
>> proving pointers couldn't be null.
> 
> This is my view. Null checks/proofs should be maximally hoisted and
> explicitly emitted in the output rather than relying on traps.

Every major managed code runtime team disagrees with you.

It's not productive for low-level infrastructure maintainers to claim 
that a universal practice is somehow illegitimate. This attitude is not 
going to convince people doing the supposedly illegitimate thing to stop 
doing it, but it will block progress that leads to improvement of the 
system as a whole.

>> That's the only case I'm personally familiar with where a serious
>> application tried to _recover from_ synchronous signals.  I've also
>> dug into Breakpad a little, but that is a debugger at heart, and it
>> would be well-served by a mechanism where the kernel would
>> automatically spawn a ptrace supervisor instead of delivering a fatal
>> signal.  (This would also allow us to kick core dump generation out of
>> the kernel.)
> 
> This is a very bad idea. Introspective crash logging/reporting is a
> huge gift to attackers. If an attacker has compromised a process in a
> manner to cause it to segfault, they almost surely have enough control
> over the process state to force the handler to perform code execution
> for them. There have been real-world CVEs along these lines.

I've hacked on crash reporters for a while now. Reporting a crash in a 
damaged process environment is undesirable, but unavoidable in some 
cases. For example, on iOS, fork(2) doesn't work. At all. Consequently, 
breakpad there needs to do its best with the state it has.

Calling fork(2) in a SIGSEGV handler and immediately execing a crash 
reporting process is generally safe enough. It's hard for things to go 
wrong enough that this mechanism doesn't work. That fresh crash 
reporting process can ptrace its parent and collect what it wants.

While some kernel help in spawning this process wouldn't hurt, I don't 
think it's particularly necessary. (And I think the existing Linux 
core_pipe approach is adequate.)

We _do_ need user-space dump collection though. The logic for deciding 
what information we include in a crash report is too complex to hoist to 
the kernel, where it'll seldom get updates. The kernel's job should be 
limited to hooking up a crashing process and a crash-reporting process; 
I'd get rid of kernel-written core dumps entirely if I had my way.

  reply	other threads:[~2018-03-09 20:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-08 17:53 Daniel Colascione
2018-03-08 20:09 ` Florian Weimer
2018-03-08 20:22   ` dancol
2018-03-08 21:21     ` Ondřej Bílka
2018-03-08 21:50       ` dancol
2018-03-09  8:17         ` Ondřej Bílka
2018-03-09 10:51           ` Daniel Colascione
2018-03-09  9:19     ` Florian Weimer
2018-03-09 10:43       ` Daniel Colascione
2018-03-09 16:41         ` Rich Felker
2018-03-09 16:58           ` Florian Weimer
2018-03-09 17:14             ` Rich Felker
2018-03-09 17:36               ` Paul Eggert
2018-03-09 19:34               ` Daniel Colascione
2018-03-09 19:28           ` Daniel Colascione
2018-03-09 19:30           ` Zack Weinberg
2018-03-09 20:06             ` Daniel Colascione
2018-03-09 20:25             ` Rich Felker
2018-03-09 20:54               ` Daniel Colascione [this message]
2018-03-09 21:10                 ` Rich Felker
2018-03-09 21:27                   ` dancol
2018-03-09 21:05               ` Zack Weinberg
2018-03-10  7:56               ` Florian Weimer
2018-03-10  8:41                 ` dancol
2018-03-11 18:07 ` Zack Weinberg
2018-03-11 18:56   ` Daniel Colascione
2018-03-12 15:17     ` Zack Weinberg
2018-03-12 19:47       ` Daniel Colascione

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=18fe6935-67c2-a901-7730-e08625aeebf2@dancol.org \
    --to=dancol@dancol.org \
    --cc=dalias@libc.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=zackw@panix.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.
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).