b633c42
Disable rseq integration until the Firefox sandbox supports rseq.
b633c42
b633c42
Sandbox is incompatible with rseq registration
b633c42
<https://bugzilla.mozilla.org/show_bug.cgi?id=1651701>
b633c42
b633c42
diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c
b633c42
index 86da66d5e01af08f..fd779941e7180fb6 100644
b633c42
--- a/elf/libc_early_init.c
b633c42
+++ b/elf/libc_early_init.c
b633c42
@@ -28,8 +28,9 @@ __libc_early_init (_Bool initial)
b633c42
   __ctype_init ();
b633c42
 
b633c42
   /* Register rseq ABI to the kernel for the main program's libc.   */
b633c42
+  rseq_active_init ();
b633c42
   if (initial)
b633c42
-    rseq_register_current_thread ();
b633c42
+      rseq_register_current_thread ();
b633c42
 
b633c42
   /* Only the outer namespace is marked as single-threaded.  */
b633c42
   __libc_single_threaded = initial;
b633c42
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
b633c42
index f72741b7e5afb22a..a730077142f0e20a 100644
b633c42
--- a/sysdeps/unix/sysv/linux/Versions
b633c42
+++ b/sysdeps/unix/sysv/linux/Versions
b633c42
@@ -171,6 +171,8 @@ libc {
b633c42
     __rseq_abi;
b633c42
   }
b633c42
   GLIBC_PRIVATE {
b633c42
+    __rseq_active;
b633c42
+
b633c42
     # functions used in other libraries
b633c42
     __syscall_rt_sigqueueinfo;
b633c42
     __open_nocancel;
b633c42
diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h
b633c42
index 8f6772ca1deada89..acaf033be465facd 100644
b633c42
--- a/sysdeps/unix/sysv/linux/rseq-internal.h
b633c42
+++ b/sysdeps/unix/sysv/linux/rseq-internal.h
b633c42
@@ -23,13 +23,29 @@
b633c42
 #include <kernel-features.h>
b633c42
 #include <stdio.h>
b633c42
 #include <sys/rseq.h>
b633c42
+#include <unistd.h>
b633c42
 
b633c42
 #ifdef RSEQ_SIG
b633c42
+
b633c42
+extern _Bool __rseq_active;
b633c42
+
b633c42
+static inline void
b633c42
+rseq_active_init (void)
b633c42
+{
b633c42
+  __rseq_active = __access ("/etc/glibc.rseq.enabled", F_OK) == 0;
b633c42
+}
b633c42
+
b633c42
 static inline void
b633c42
 rseq_register_current_thread (void)
b633c42
 {
b633c42
   int ret;
b633c42
 
b633c42
+  if (!__rseq_active)
b633c42
+    {
b633c42
+      __rseq_abi.cpu_id = RSEQ_CPU_ID_REGISTRATION_FAILED;
b633c42
+      return;
b633c42
+    }
b633c42
+
b633c42
   if (__rseq_abi.cpu_id != RSEQ_CPU_ID_UNINITIALIZED)
b633c42
     __libc_fatal ("glibc fatal error: "
b633c42
                   "rseq already initialized for this thread\n");
b633c42
@@ -64,6 +80,11 @@ rseq_register_current_thread (void)
b633c42
     }
b633c42
 }
b633c42
 #else /* RSEQ_SIG */
b633c42
+static inline void
b633c42
+rseq_active_init (void)
b633c42
+{
b633c42
+}
b633c42
+
b633c42
 static inline void
b633c42
 rseq_register_current_thread (void)
b633c42
 {
b633c42
diff --git a/sysdeps/unix/sysv/linux/rseq-sym.c b/sysdeps/unix/sysv/linux/rseq-sym.c
b633c42
index 090093408f1a4b3f..78d3a9dd8355436b 100644
b633c42
--- a/sysdeps/unix/sysv/linux/rseq-sym.c
b633c42
+++ b/sysdeps/unix/sysv/linux/rseq-sym.c
b633c42
@@ -19,8 +19,11 @@
b633c42
 #include <stdint.h>
b633c42
 #include <kernel-features.h>
b633c42
 #include <sys/rseq.h>
b633c42
+#include <rseq-internal.h>
b633c42
 
b633c42
 __thread struct rseq __rseq_abi =
b633c42
   {
b633c42
     .cpu_id = RSEQ_CPU_ID_UNINITIALIZED,
b633c42
   };
b633c42
+
b633c42
+_Bool __rseq_active __attribute__ ((nocommon));
b633c42
diff --git a/sysdeps/unix/sysv/linux/tst-rseq-nptl.c b/sysdeps/unix/sysv/linux/tst-rseq-nptl.c
b633c42
index 5e788dcfa9eef8ef..ed846e9f5d5a5f4e 100644
b633c42
--- a/sysdeps/unix/sysv/linux/tst-rseq-nptl.c
b633c42
+++ b/sysdeps/unix/sysv/linux/tst-rseq-nptl.c
b633c42
@@ -250,6 +250,10 @@ do_rseq_test (void)
b633c42
 static int
b633c42
 do_test (void)
b633c42
 {
b633c42
+  extern _Bool __rseq_active;
b633c42
+  if (!__rseq_active)
b633c42
+    FAIL_UNSUPPORTED ("/etc/glibc.rseq.enabled missing, test disabled");
b633c42
+
b633c42
   return do_rseq_test ();
b633c42
 }
b633c42
 
b633c42
diff --git a/sysdeps/unix/sysv/linux/tst-rseq.c b/sysdeps/unix/sysv/linux/tst-rseq.c
b633c42
index aa902fb26a64f917..60eaab4bc13d1275 100644
b633c42
--- a/sysdeps/unix/sysv/linux/tst-rseq.c
b633c42
+++ b/sysdeps/unix/sysv/linux/tst-rseq.c
b633c42
@@ -57,6 +57,10 @@ do_rseq_test (void)
b633c42
 static int
b633c42
 do_test (void)
b633c42
 {
b633c42
+  extern _Bool __rseq_active;
b633c42
+  if (!__rseq_active)
b633c42
+    FAIL_UNSUPPORTED ("/etc/glibc.rseq.enabled missing, test disabled");
b633c42
+
b633c42
   do_rseq_test ();
b633c42
   return 0;
b633c42
 }