glibc/sysdeps/htl
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 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
include htl: Fix build error in annexc 2022-01-17 23:18:27 +00:00
dl-support.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
dl-thread_gscope_wait.c htl: Implement some support for TLS_DTV_AT_TP 2024-03-23 23:00:30 +01:00
flockfile.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
ftrylockfile.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
funlockfile.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
futex-internal.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Implies
libc-lock.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
libc-lockP.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Makeconfig hurd 64bit: Add missing libanl 2023-05-01 13:36:14 +02:00
Makefile htl: Add __errno_location and __h_errno_location 2020-01-04 19:37:53 +01:00
pt-attr-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-getdetachstate.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-getguardsize.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-getinheritsched.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-getschedparam.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-getschedpolicy.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-getscope.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-getstack.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-getstackaddr.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-getstacksize.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-setdetachstate.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-setguardsize.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-setinheritsched.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-setschedparam.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-setschedpolicy.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-attr-setscope.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-setstack.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-setstackaddr.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr-setstacksize.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-attr.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrier-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrier-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrier-wait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrier.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrierattr-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrierattr-getpshared.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrierattr-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-barrierattr-setpshared.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond-brdcast.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond-signal.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond-timedwait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond-wait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-cond.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-condattr-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-condattr-getclock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-condattr-getpshared.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-condattr-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-condattr-setclock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-condattr-setpshared.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-destroy-specific.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-equal.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-getconcurrency.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-getcpuclockid.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-getschedparam.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-getspecific.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-init-specific.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-key-create.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-key-delete.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-key.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-once.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-attr.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-rdlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-timedrdlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-timedwrlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-tryrdlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-trywrlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-unlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlock-wrlock.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlockattr-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlockattr-getpshared.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlockattr-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-rwlockattr-setpshared.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-setconcurrency.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-setschedparam.c hurd: Fix missing pthread_ compat symbol in libc 2024-08-01 23:58:51 +02:00
pt-setschedprio.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-setspecific.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pt-startup.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pthread_atfork_compat.h Consolidate pthread_atfork 2021-06-24 10:04:41 -03:00
pthread-functions.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pthread.h Add pthread_getname_np and pthread_setname_np for Hurd 2024-07-16 09:21:52 +02:00
pthreadP.h stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
raise.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-destroy.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-getvalue.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-init.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-post.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-timedwait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-trywait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-wait.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sem-waitfast.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stdio-lock.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Subdirs
thrd_current.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
timer_routines.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
timer_routines.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Versions htl: Respect GL(dl_stack_flags) when allocating stacks 2024-03-23 22:48:44 +01:00