mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Conditional signal safety?
Date: Mon, 1 Jul 2019 12:13:16 -0400	[thread overview]
Message-ID: <20190701161316.GU1506@brightrain.aerifal.cx> (raw)
In-Reply-To: <87h885bvhg.fsf@oldenburg2.str.redhat.com>

On Mon, Jul 01, 2019 at 05:55:07PM +0200, Florian Weimer wrote:
> * Rich Felker:
> 
> > On Mon, Jul 01, 2019 at 06:21:11AM +0200, Florian Weimer wrote:
> >> * Markus Wichmann:
> >> 
> >> > at work yesterday I had to build an exception handler (a signal handler
> >> > for SIGSEGV, SIGBUS, SIGILL, and SIGFPE). For my purposes, it was really
> >> > convenient to just use dladdr() to find out at least what module and
> >> > function PC and LR were pointing to when the exception happened, so I
> >> > used that function.
> >> 
> >> Are these signals generated synchronously, by running code?  Then the
> >> rules regarding asynchronous signal safety do not apply.
> >
> > That's a meaningful distinction if they're generated by accesses in
> > the application code. If they're generated by accesses from within
> > standard library functions (e.g. because you passed an invalid pointer
> > or one to memory that was intentionally setup to generate them) to a
> > stdlib function, it's just UB, and if you were going to define it,
> > it'd still be an async signal context just because it's async with
> > respect to the interrupted state of the stdlib function being
> > unspecified/unspecifiable.
> 
> Right, but if libc code traps without violating preconditions, that's
> generally a bug.

Yes. If any of these signals are generated in libc without the
preconditions of the interface having been violated, that's a bug in
libc. For appropriate notions of what the preconditions are. It's
clear for stuff like invalid pointers, but less obvious when you're
dealing with things like memory setup explicitly to trap. My view is
that such memory still does not constitute the regular C object the
function requires, and thus the standard doesn't define any behavior
for it. I think it would be hard to specify any particular behavior
without also specifying a lot of the library internals -- either you
have to specify that the signal context is an async one, or you have
to place constraints on how internal locking and resource usage works
and what locks can possibly be held by what interfaces.

So, IMO you have to treat it as "at best an async signal context; at
worst, UB and thereby completely undefined program state".

> And if you violate preconditions, than *that* already
> triggers undefined behavior, and not the trap later on.  (For example,
> the compiler uses the knowledge of well-known functions and optimizes
> accordingly.)

Yes.

Rich


      reply	other threads:[~2019-07-01 16:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-29  5:54 Markus Wichmann
2019-06-29  9:33 ` Szabolcs Nagy
2019-06-29 16:49 ` Rich Felker
2019-07-01  4:21 ` Florian Weimer
2019-07-01 14:06   ` Rich Felker
2019-07-01 15:55     ` Florian Weimer
2019-07-01 16:13       ` Rich Felker [this message]

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=20190701161316.GU1506@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).