glibc/sysdeps
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
..
aarch64 AArch64: Simplify rounding-multiply pattern in several AdvSIMD routines 2024-09-23 15:44:08 +01:00
alpha math: Update alpha ulps 2024-07-14 12:44:15 +02:00
arc arc: Cleanup arcbe 2024-09-25 15:54:07 +01:00
arm arm: Regenerate ULPs 2024-08-07 11:02:03 -03:00
csky elf: Remove HWCAP_IMPORTANT 2024-06-18 10:45:36 +02:00
generic stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
gnu sysdeps: Re-flow and sort multiline gnu/Makefile definitions 2024-08-07 11:02:03 -03:00
hppa hppa: Update libm-test-ulps 2024-09-09 09:57:42 -04:00
htl stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
hurd hurd: Move internal functions to internal header 2024-03-23 22:43:07 +01:00
i386 Fix whitespace related license issues. 2024-10-07 18:08:16 -04:00
ieee754 math: Improve layout of expf data 2024-10-01 13:39:26 +01:00
loongarch LoongArch: Fix macro redefined warning in tls-desc.S 2024-09-06 15:46:13 +08:00
m68k math: Update m68k ULPs 2024-07-08 21:51:03 +02:00
mach hurd: Add missing va_end call in fcntl implementation. [BZ #32234] 2024-10-03 20:18:29 +02:00
microblaze Implement C23 logp1 2024-06-17 13:47:09 +00:00
mips MIPS: Regenerate ULPs 2024-08-08 14:53:53 +02:00
nios2 Convert to autoconf 2.72 (vanilla release, no distribution patches) 2024-06-17 21:15:28 +02:00
nptl stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
or1k Implement C23 logp1 2024-06-17 13:47:09 +00:00
posix stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
powerpc Fix whitespace related license issues. 2024-10-07 18:08:16 -04:00
pthread nptl: Fix Race conditions in pthread cancellation [BZ#12683] 2024-08-23 14:27:43 -03:00
riscv riscv: align .preinit_array (bug 32228) 2024-10-02 13:04:30 +02:00
s390 S390: Don't use r11 for cu-instructions as used as frame-pointer. [BZ# 32192] 2024-10-08 10:13:02 +02:00
sh nptl: Fix Race conditions in pthread cancellation [BZ#12683] 2024-08-23 14:27:43 -03:00
sparc sparc: Regenerate ULPs 2024-08-07 11:02:03 -03:00
unix stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
x86 x86: Enable non-temporal memset for Hygon processors 2024-08-26 10:01:58 -07:00
x86_64 Fix whitespace related license issues. 2024-10-07 18:08:16 -04:00