From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org, Carlos O'Donell <carlos@redhat.com>
Subject: [PATCH 0/2] Make abort AS-safe
Date: Mon, 31 Jul 2023 14:18:58 -0300 [thread overview]
Message-ID: <20230731171900.4065501-1-adhemerval.zanella@linaro.org> (raw)
Besides POSIX stating abort should be AS-safe, Rust also had an
open PR about it [1] (it was closed with a different fix).
The main issue is the recursive lock used on abort does not
synchronize with new process creation (either by fork-like interfaces
or posix_spawn ones), nor it is reinitialized after fork.
Also, the SIGABRT unblock before raise shows another race-condition,
where a fork or posix_spawn call by another thread just after
the recursive lock release and before raising SIGABRT might create
a new process with a non-expected signal mask.
To fix the AS-safe, the raise is issued without changing the process
signal mask, and an AS-safe lock is used if a SIGABRT is installed or
the process is blocked or ignored. The the signal mask change removal,
there is no need to use a recursive lock. The lock is also used on
both _Fork and posix_spawn, to avoid the spawn process to see the
abort handler as SIG_DFL.
The clone is also subjected to this issue, but since glibc does not
do any internal metadata setup (as for fork-like function), this patch
does not handle it for the symbol.
I have not added a regression tests because, from previous Carlos's
patch [2], hitting the code path to trigger the potential issue
(fork just after abort has acquired the lock and reset SIGABRT handler)
is not deterministic and it would generate a lot of development
overhead.
[1] https://github.com/rust-lang/rust/issues/73894#issuecomment-673478761
[2] https://sourceware.org/pipermail/libc-alpha/2020-September/117934.html
Adhemerval Zanella (2):
setjmp: Use BSD sematic as default for setjmp
stdlib: Make abort AS-safe (BZ 26275)
include/stdlib.h | 4 +
manual/setjmp.texi | 14 +--
manual/startup.texi | 3 -
nptl/pthread_create.c | 3 +-
nptl/pthread_kill.c | 11 ++
posix/fork.c | 2 +
setjmp/setjmp.h | 5 -
signal/sigaction.c | 21 +++-
stdlib/abort.c | 128 ++++++++-------------
sysdeps/generic/internal-signals.h | 24 ++++
sysdeps/htl/pthreadP.h | 2 +
sysdeps/nptl/_Fork.c | 12 ++
sysdeps/nptl/libc_start_call_main.h | 3 +-
sysdeps/nptl/pthreadP.h | 1 +
sysdeps/unix/sysv/linux/internal-signals.h | 9 ++
sysdeps/unix/sysv/linux/spawni.c | 3 +
16 files changed, 140 insertions(+), 105 deletions(-)
--
2.34.1
next reply other threads:[~2023-07-31 17:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 17:18 Adhemerval Zanella [this message]
2023-07-31 17:18 ` [PATCH 1/2] setjmp: Use BSD sematic as default for setjmp Adhemerval Zanella
2023-08-01 8:35 ` Florian Weimer
2023-08-01 13:51 ` Adhemerval Zanella Netto
2023-08-02 7:59 ` Florian Weimer
2023-08-02 12:32 ` Adhemerval Zanella Netto
2023-08-02 12:42 ` Florian Weimer
2023-08-02 12:48 ` Adhemerval Zanella Netto
2023-08-02 13:17 ` Florian Weimer
2023-08-02 13:29 ` Adhemerval Zanella Netto
2023-08-02 14:43 ` Florian Weimer
2023-08-02 14:56 ` Adhemerval Zanella Netto
2023-07-31 17:19 ` [PATCH 2/2] stdlib: Make abort AS-safe (BZ 26275) Adhemerval Zanella
2023-08-01 8:10 ` Florian Weimer
2023-08-01 13:52 ` Adhemerval Zanella Netto
2023-08-01 8:26 ` Florian Weimer
2023-08-01 13:57 ` Adhemerval Zanella Netto
2023-08-01 13:44 ` Cristian Rodríguez
2023-08-02 7:57 ` Florian Weimer
2023-08-02 13:08 ` Adhemerval Zanella Netto
2023-08-02 14:44 ` Florian Weimer
2023-08-02 14:48 ` Adhemerval Zanella Netto
2023-08-02 12:38 ` Florian Weimer
2023-08-02 13:08 ` Adhemerval Zanella Netto
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=20230731171900.4065501-1-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=carlos@redhat.com \
--cc=libc-alpha@sourceware.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.
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).