]> sourceware.org Git - glibc.git/commit
nptl: Start new threads with all signals blocked [BZ #25098]
authorFlorian Weimer <fweimer@redhat.com>
Mon, 27 Apr 2020 07:55:10 +0000 (09:55 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 27 Apr 2020 08:04:24 +0000 (10:04 +0200)
commitb3cae39dcbfa2432b3f3aa28854d8ac57f0de1b8
tree1e2b2d44b6682b12375a48465f04fcca96634593
parent92954ffa5a5662fbfde14febd7e5dcc358c85470
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>
nptl/descr.h
nptl/pthread_create.c
This page took 0.044824 seconds and 5 git commands to generate.