glibc/debug
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
..
asprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
backtrace-tst.c
backtrace.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
backtracesyms.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
backtracesymsfd.c Unify output from backtrace_symbols_fd with backtrace_symbols (bug 31730) 2024-05-14 12:55:06 +02:00
chk_fail.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
confstr_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Depend
dprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
execinfo.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
explicit_bzero_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fdelt_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fgets_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fgets_u_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fgetws_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fgetws_u_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fortify_fail.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fread_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fread_u_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
fwprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
getcwd_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
getdomainname_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
getgroups_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
gethostname_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
gets_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
getwd_chk.c debug/getwd_chk.c: warning should be emitted for the __getwd_chk symbol. 2024-01-12 15:21:26 +01:00
longjmp_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Makefile Do not use -Wp to disable fortify (BZ 31928) 2024-10-01 08:44:40 -03:00
mbsnrtowcs_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
mbsrtowcs_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
mbstowcs_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
memcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
memmove_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
mempcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
memset_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
noophooks.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
obprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pcprofile.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pcprofiledump.c debug: Fix read error handling in pcprofiledump 2024-09-10 12:40:27 +02:00
poll_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
ppoll_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pread64_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
pread_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
printf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
read_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
readlink_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
readlinkat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
readonly-area.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
realpath_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
recv_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
recvfrom_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
snprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
sprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stack_chk_fail_local.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stack_chk_fail.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stpcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
stpncpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
strcat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
strcpy_chk.c string: Add hidden builtin definition for __strcpy_chk. 2024-02-06 09:17:04 +01:00
strlcat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
strlcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
strncat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
strncpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
swprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
test-stpcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
test-strcpy_chk.c stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
tst-backtrace2.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-backtrace3.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-backtrace4.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-backtrace5.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-backtrace6.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-backtrace.h Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-chk-cancel.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-fortify-syslog.c support: Add FAIL test failure helper 2024-07-26 13:21:34 +01:00
tst-fortify-wide.c stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
tst-fortify.c stdlib: Make abort/_Exit AS-safe (BZ 26275) 2024-10-08 14:40:12 -03:00
tst-longjmp_chk2.c debug: Adapt fortify tests to libsupport 2023-12-29 10:57:03 -03:00
tst-longjmp_chk3.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-longjmp_chk.c debug: Adapt fortify tests to libsupport 2023-12-29 10:57:03 -03:00
tst-realpath-chk.c fortify: Fix spurious warning with realpath 2021-12-17 18:49:27 +05:30
tst-sprintf-fortify-rdonly.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-sprintf-fortify-unchecked.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
tst-ssp-1.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
ttyname_r_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vasprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vdprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
Versions Add the wcslcpy, wcslcat functions 2023-06-14 18:10:24 +02:00
vfprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vfwprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vobprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vsnprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vsprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vswprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
vwprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcpcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcpncpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcrtomb_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcscat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcscpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcslcat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcslcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcsncat_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcsncpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcsnrtombs_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcsrtombs_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wcstombs_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wctomb_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wmemcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wmemmove_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wmempcpy_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wmemset_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
wprintf_chk.c Update copyright dates with scripts/update-copyrights 2024-01-01 10:53:40 -08:00
xtrace.sh Update copyright dates not handled by scripts/update-copyrights 2024-01-01 10:53:40 -08:00