summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>2020-07-06 10:21:16 +0200
committerFlorian Weimer <fweimer@redhat.com>2020-07-06 10:21:16 +0200
commit0c76fc3c2b346dc5401dc055d97d4279632b0fb3 (patch)
tree67d7a99ad801c38a137fbb9d08ac54137bb901b9 /elf
parentf9cf87353772ca370b7bb901d86365a564fba49f (diff)
downloadglibc-0c76fc3c2b346dc5401dc055d97d4279632b0fb3.tar.gz
glibc-0c76fc3c2b346dc5401dc055d97d4279632b0fb3.tar.xz
glibc-0c76fc3c2b346dc5401dc055d97d4279632b0fb3.zip
Linux: Perform rseq registration at C startup and thread creation
Register rseq TLS for each thread (including main), and unregister for
each thread (excluding main).  "rseq" stands for Restartable Sequences.

See the rseq(2) man page proposed here:
  https://lkml.org/lkml/2018/9/19/647

Those are based on glibc master branch commit 3ee1e0ec5c.
The rseq system call was merged into Linux 4.18.

The TLS_STATIC_SURPLUS define is increased to leave additional room for
dlopen'd initial-exec TLS, which keeps elf/tst-auditmany working.

The increase (76 bytes) is larger than 32 bytes because it has not been
increased in quite a while.  The cost in terms of additional TLS storage
is quite significant, but it will also obscure some initial-exec-related
dlopen failures.
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-tls.c8
-rw-r--r--elf/libc_early_init.c4
2 files changed, 11 insertions, 1 deletions
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index fa03234610..ca13778ca9 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -31,7 +31,7 @@
 
 /* Amount of excess space to allocate in the static TLS area
    to allow dynamic loading of modules defining IE-model TLS data.  */
-#define TLS_STATIC_SURPLUS	64 + DL_NNS * 100
+#define TLS_STATIC_SURPLUS	64 + DL_NNS * 176
 
 
 /* Out-of-memory handler.  */
@@ -134,6 +134,12 @@ void
 _dl_determine_tlsoffset (void)
 {
   size_t max_align = TLS_TCB_ALIGN;
+  /* libc.so with rseq has TLS with 32-byte alignment.  Since TLS is
+     initialized before audit modules are loaded and slotinfo
+     information is available, this is not taken into account below in
+     the audit case.  */
+  max_align = MAX (max_align, 32U);
+
   size_t freetop = 0;
   size_t freebottom = 0;
 
diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c
index e6c64fb526..f0fcf6448e 100644
--- a/elf/libc_early_init.c
+++ b/elf/libc_early_init.c
@@ -18,10 +18,14 @@
 
 #include <ctype.h>
 #include <libc-early-init.h>
+#include <rseq-internal.h>
 
 void
 __libc_early_init (_Bool initial)
 {
   /* Initialize ctype data.  */
   __ctype_init ();
+  /* Register rseq ABI to the kernel for the main program's libc.   */
+  if (initial)
+    rseq_register_current_thread ();
 }