about summary refs log tree commit diff
path: root/nptl/pthread_kill.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-07-31 12:44:37 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-06-19 09:05:43 -0300
commit80f34f5173a29833c4f9e73a9725376448769a99 (patch)
tree4f14d07fe9a9d5c677818d23bda45f9288a5b02d /nptl/pthread_kill.c
parentc49e66c7e507f2d37c4725ce4680f19179cfa44e (diff)
downloadglibc-azanella/bz26275-abort-as.tar.gz
glibc-azanella/bz26275-abort-as.tar.xz
glibc-azanella/bz26275-abort-as.zip
stdlib: Make abort AS-safe (BZ 26275) azanella/bz26275-abort-as
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 the SIGABRT raise might create
programs with a non-expected signal mask.

To fix the AS-safe, the raise is issues 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 on
both _Fork and posix_spawn, to avoid the spawn process to see the
abort handler as SIG_DFL.

The posix_spawn possible issue is if caller sets a SIG_IGN for
SIGABRT, calls abort, and another thread issues posix_spawn just
after the sigaction returns.  With default options (not setting
POSIX_SPAWN_SETSIGDEF), the process can still see SIG_DFL for
SIGABRT, where it should be SIG_IGN.

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

Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Diffstat (limited to 'nptl/pthread_kill.c')
-rw-r--r--nptl/pthread_kill.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c
index 71e5a7bf5b..fa5121a583 100644
--- a/nptl/pthread_kill.c
+++ b/nptl/pthread_kill.c
@@ -69,6 +69,17 @@ __pthread_kill_implementation (pthread_t threadid, int signo, int no_tid)
   return ret;
 }
 
+/* Send the signal SIGNO to the caller.  Used by abort and called where the
+   signals are being already blocked and there is no need to synchronize with
+   exit_lock.  */
+int
+__pthread_raise_internal (int signo)
+{
+  /* Use the gettid syscall so it works after vfork.  */
+  int ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), __gettid(), signo);
+  return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
+}
+
 int
 __pthread_kill_internal (pthread_t threadid, int signo)
 {