zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] Crash due to malloc call in signal handler
Date: Fri, 13 Dec 2019 10:31:48 +0000	[thread overview]
Message-ID: <1576233108.5214.5.camel@samsung.com> (raw)
In-Reply-To: <CAN=4vMpC60idntMAO_wYTsUNRusz6grTuTk6ZgOUVxrYEAkBYQ@mail.gmail.com>

On Fri, 2019-12-13 at 11:19 +0100, Roman Perepelitsa wrote:
> On Fri, Dec 13, 2019 at 11:17 AM Peter Stephenson
> <p.stephenson@samsung.com> wrote:
> > 
> > 
> > On Fri, 2019-12-13 at 10:45 +0100, Roman Perepelitsa wrote:
> > > 
> > > On Fri, Dec 13, 2019 at 10:40 AM Peter Stephenson
> > > <p.stephenson@samsung.com> wrote:
> > > > 
> > > > 
> > > > The main shell is suspended, waiting for a child to finish, so the fact
> > > > it's in the signal handler isn't saying anything.
> > > > 
> > > > From the look of it, some memory corruption must already have occurred
> > > > at this point to get the malloc to fail.
> > > malloc is not async signal safe. It's illegal to call it from a signal
> > > handler. I'm not saying this is what's causing a crash.
> > In zsh, this is handled by queuing interrupts and only allowing them to
> > run in a few places in the code.  Obviously, waiting for a child to
> > exit is one of those places.
> The stack trace shows malloc being called zhandler. zhandler is a
> signal handler. What am I missing?

You're not missing anything there, that's how it works.

Interrupts are queued so they don't normally go off.

In certain places they are allowed to take place; one of these is when
we are sitting waiting for a child to exit.

At this point the signal handler will then run.

Thus the signal handler is supposed not to be running when any memory
management is taking place underneath.  So it's not asynchronous
with respect to code actually running in the main shell (despite being
run from a signal handler which can formally occur anywhere, but
we make sure it doesn't).

Of course, there's the possibility of bugs in this, but the stack in
this case doesn't show evidence of that at the point in question.

You'll find long discussions of this in the mail archive going back
some years.

pws


      reply	other threads:[~2019-12-13 10:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20191212182957epcas5p48645aa560e781ac1c34f00662a6d6176@epcas5p4.samsung.com>
2019-12-12 18:28 ` Antoine C.
2019-12-13  9:40   ` Peter Stephenson
2019-12-13  9:45     ` Roman Perepelitsa
2019-12-13 10:16       ` Peter Stephenson
2019-12-13 10:19         ` Roman Perepelitsa
2019-12-13 10:31           ` Peter Stephenson [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=1576233108.5214.5.camel@samsung.com \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

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

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).