glibc/signal
Adhemerval Zanella d40ac01cbb stdlib: Make abort/_Exit AS-safe (BZ 26275)
The recursive lock used on abort does not synchronize with a 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 the SIGABRT signal, might create
programs with a non-expected signal mask.  With the default option
(without POSIX_SPAWN_SETSIGDEF), the process can see SIG_DFL for
SIGABRT, where it should be SIG_IGN.

To fix the AS-safe, raise() does not change the process signal mask,
and an AS-safe lock is used if a SIGABRT is installed or the process
is blocked or ignored.  With the signal mask change removal,
there is no need to use a recursive loc.  The lock is also taken on
both _Fork() and posix_spawn(), to avoid the spawn process to see the
abort handler as SIG_DFL.

A read-write lock is used to avoid serialize _Fork and posix_spawn
execution.  Both sigaction (SIGABRT) and abort() requires to lock
as writer (since both change the disposition).

The fallback is also simplified: there is no need to use a loop of
ABORT_INSTRUCTION after _exit() (if the syscall does not terminate the
process, the system is broken).

The proposed fix changes how setjmp works on a SIGABRT handler, where
glibc does not save the signal mask.  So usage like the below will now
always abort.

  static volatile int chk_fail_ok;
  static jmp_buf chk_fail_buf;

  static void
  handler (int sig)
  {
    if (chk_fail_ok)
      {
        chk_fail_ok = 0;
        longjmp (chk_fail_buf, 1);
      }
    else
      _exit (127);
  }
  [...]
  signal (SIGABRT, handler);
  [....]
  chk_fail_ok = 1;
  if (! setjmp (chk_fail_buf))
    {
      // Something that can calls abort, like a failed fortify function.
      chk_fail_ok = 0;
      printf ("FAIL\n");
    }

Such cases will need to use sigsetjmp instead.

The _dl_start_profile calls sigaction through _profil, and to avoid
pulling abort() on loader the call is replaced with __libc_sigaction.

Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Reviewed-by: DJ Delorie <dj@redhat.com>
2024-10-08 14:40:12 -03:00
..
bits/types Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sys
allocrtsig.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
kill.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
killpg.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
libc_sigaction.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Makefile signal/Makefile: Split and sort tests 2024-07-01 13:47:27 +02:00
raise.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigaction.c stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
sigaddset.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigaltstack.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigandset.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigblock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigdelset.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigempty.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigfillset.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
siggetmask.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sighold.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigignore.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigintr.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigisempty.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigismem.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
signal.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
signal.h Always define __USE_TIME_BITS64 when 64 bit time_t is used 2024-04-02 15:28:36 -03:00
sigorset.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigpause.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigpending.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigprocmask.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigqueue.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigrelse.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigreturn.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigset.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigsetmask.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigsetops.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigstack.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigsuspend.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigtimedwait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigvec.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigwait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sigwaitinfo.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sysv_signal.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-minsigstksz-1.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-minsigstksz-2.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-minsigstksz-3.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-minsigstksz-3a.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-minsigstksz-4.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-minsigstksz-5.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-raise.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-sigaction.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-sigisemptyset.c linux/sigsetops: fix type confusion (bug 31468) 2024-03-12 10:00:22 +01:00
tst-signal.c * malloc/memusagestat.c (main): Use return instead of exit to 2000-12-31 10:52:32 +00:00
tst-sigset2.c signal: Avoid system signal disposition to interfere with tests 2024-03-27 13:47:09 -03:00
tst-sigset.c Filter out NPTL internal signals (BZ #22391) 2018-04-03 13:30:49 -03:00
tst-sigsimple.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-sigwait-eintr.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Versions nptl: Move sigaction to libc 2021-03-26 13:37:18 -03:00