summary refs log tree commit diff
path: root/nptl/descr.h
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2020-04-27 09:55:10 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-04-27 10:04:24 +0200
commitb3cae39dcbfa2432b3f3aa28854d8ac57f0de1b8 (patch)
tree1e2b2d44b6682b12375a48465f04fcca96634593 /nptl/descr.h
parent92954ffa5a5662fbfde14febd7e5dcc358c85470 (diff)
downloadglibc-b3cae39dcbfa2432b3f3aa28854d8ac57f0de1b8.tar.gz
glibc-b3cae39dcbfa2432b3f3aa28854d8ac57f0de1b8.tar.xz
glibc-b3cae39dcbfa2432b3f3aa28854d8ac57f0de1b8.zip
nptl: Start new threads with all signals blocked [BZ #25098]
New threads inherit the signal mask from the current thread.  This
means that signal handlers can run on the newly created thread
immediately after the kernel has created the userspace thread, even
before glibc has initialized the TCB.  Consequently, new threads can
observe uninitialized ctype data, among other things.

To address this, block all signals before starting the thread, and
pass the original signal mask to the start routine wrapper.  On the
new thread, first perform all thread initialization, and then unblock
signals.

The cost of doing this is two rt_sigprocmask system calls on the old
thread, and one rt_sigprocmask system call on the new thread.  (If
there was a way to clone a new thread with a signals disabled, this
could be brought down to one system call each.)  The thread descriptor
increases in size, too, and sigset_t is fairly large.  This increase
could be brought down by reusing space the in the descriptor which is
not needed before running user code, or by switching to an internal
sigset_t definition which only covers the signals supported by the
kernel definition.  (Part of the thread descriptor size increase is
already offset by reduced stack usage in the thread start wrapper
routine after this commit.)

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'nptl/descr.h')
-rw-r--r--nptl/descr.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/nptl/descr.h b/nptl/descr.h
index 9dcf480bdf..e1c7db5473 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -332,9 +332,8 @@ struct pthread
   /* True if thread must stop at startup time.  */
   bool stopped_start;
 
-  /* The parent's cancel handling at the time of the pthread_create
-     call.  This might be needed to undo the effects of a cancellation.  */
-  int parent_cancelhandling;
+  /* Formerly used for dealing with cancellation.  */
+  int parent_cancelhandling_unsed;
 
   /* Lock to synchronize access to the descriptor.  */
   int lock;
@@ -391,6 +390,11 @@ struct pthread
   /* Resolver state.  */
   struct __res_state res;
 
+  /* Signal mask for the new thread.  Used during thread startup to
+     restore the signal mask.  (Threads are launched with all signals
+     masked.)  */
+  sigset_t sigmask;
+
   /* Indicates whether is a C11 thread created by thrd_creat.  */
   bool c11;