public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get
@ 2024-06-04 13:22 Adhemerval Zanella
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2024-06-04 13:22 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9603fb34c90aef118bd51d96977cdc15643bf908

commit 9603fb34c90aef118bd51d96977cdc15643bf908
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 4 10:07:41 2024 -0300

    elf: Enable RTLD_NODELETE on __libc_unwind_link_get
    
    So the libgcc_s.so can also be sealed.  The library is loaded once
    and not unloaded during process execution (only for memory debug
    with __libc_unwind_link_freeres).

Diff:
---
 include/dlfcn.h    | 2 ++
 misc/unwind-link.c | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/dlfcn.h b/include/dlfcn.h
index f49ee1b0c9..06e2ecbdd2 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -50,6 +50,8 @@ extern char **__libc_argv attribute_hidden;
    better error handling semantics for the library.  */
 #define __libc_dlopen(name) \
   __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
+#define __libc_dlopen_nodelete(name) \
+  __libc_dlopen_mode (name, RTLD_NODELETE | RTLD_NOW | __RTLD_DLOPEN)
 extern void *__libc_dlopen_mode  (const char *__name, int __mode)
   attribute_hidden;
 extern void *__libc_dlsym   (void *__map, const char *__name)
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 213a0162a4..7267ecbec3 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -48,7 +48,7 @@ __libc_unwind_link_get (void)
   /* Initialize a copy of the data, so that we do not need about
      unlocking in case the dynamic loader somehow triggers
      unwinding.  */
-  void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO);
+  void *local_libgcc_handle = __libc_dlopen_nodelete (LIBGCC_S_SO);
   if (local_libgcc_handle == NULL)
     {
       __libc_lock_unlock (lock);
@@ -100,7 +100,8 @@ __libc_unwind_link_get (void)
 
   __libc_lock_lock (lock);
   if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
-    /* This thread lost the race.  Clean up.  */
+    /* This thread lost the race.  Drop the l_direct_opencount and issue
+       the debug log.  */
     __libc_dlclose (local_libgcc_handle);
   else
     {

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get
@ 2024-06-21 14:30 Adhemerval Zanella
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2024-06-21 14:30 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fa6cd21f529d4baf555d89a8fb7acabd89e79b0f

commit fa6cd21f529d4baf555d89a8fb7acabd89e79b0f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Jun 7 21:12:18 2024 +0000

    elf: Enable RTLD_NODELETE on __libc_unwind_link_get
    
    The libgcc_s.so can also be sealed.  The library is loaded once
    and not unloaded during process execution (only for memory debug
    with __libc_unwind_link_freeres).
    
    Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Diff:
---
 include/dlfcn.h                        |  2 ++
 manual/tunables.texi                   |  4 ++++
 misc/unwind-link.c                     |  5 +++--
 sysdeps/unix/sysv/linux/tst-dl_mseal.c | 13 +++++++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/dlfcn.h b/include/dlfcn.h
index f49ee1b0c9..06e2ecbdd2 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -50,6 +50,8 @@ extern char **__libc_argv attribute_hidden;
    better error handling semantics for the library.  */
 #define __libc_dlopen(name) \
   __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
+#define __libc_dlopen_nodelete(name) \
+  __libc_dlopen_mode (name, RTLD_NODELETE | RTLD_NOW | __RTLD_DLOPEN)
 extern void *__libc_dlopen_mode  (const char *__name, int __mode)
   attribute_hidden;
 extern void *__libc_dlsym   (void *__map, const char *__name)
diff --git a/manual/tunables.texi b/manual/tunables.texi
index 65ec47c3d2..a5cc08ddf2 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -380,6 +380,10 @@ Any preload libraries.
 
 @item
 Any library loaded with @code{dlopen} with @code{RTLD_NODELETE} flag.
+
+@item
+Any runtime library used for process unwind (such as required by @code{backtrace}
+or @code{pthread_exit}).
 @end itemize
 
 The tunable accepts three diferent values: @samp{0} where sealing is disabled,
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 213a0162a4..7267ecbec3 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -48,7 +48,7 @@ __libc_unwind_link_get (void)
   /* Initialize a copy of the data, so that we do not need about
      unlocking in case the dynamic loader somehow triggers
      unwinding.  */
-  void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO);
+  void *local_libgcc_handle = __libc_dlopen_nodelete (LIBGCC_S_SO);
   if (local_libgcc_handle == NULL)
     {
       __libc_lock_unlock (lock);
@@ -100,7 +100,8 @@ __libc_unwind_link_get (void)
 
   __libc_lock_lock (lock);
   if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
-    /* This thread lost the race.  Clean up.  */
+    /* This thread lost the race.  Drop the l_direct_opencount and issue
+       the debug log.  */
     __libc_dlclose (local_libgcc_handle);
   else
     {
diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal.c b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
index 72a33d04c7..da1a3ebe5a 100644
--- a/sysdeps/unix/sysv/linux/tst-dl_mseal.c
+++ b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
@@ -19,6 +19,7 @@
 #include <array_length.h>
 #include <errno.h>
 #include <getopt.h>
+#include <gnu/lib-names.h>
 #include <inttypes.h>
 #include <libgen.h>
 #include <stdio.h>
@@ -31,6 +32,7 @@
 #include <support/support.h>
 #include <support/xdlfcn.h>
 #include <support/xstdio.h>
+#include <support/xthread.h>
 
 #define LIB_PRELOAD              "lib-tst-dl_mseal-preload.so"
 
@@ -70,6 +72,7 @@ static const char *expected_sealed_libs[] =
   LIB_NEEDED_2,
   LIB_DLOPEN_NODELETE,
   LIB_DLOPEN_NODELETE_DEP,
+  LIBGCC_S_SO,
 #endif
   "[vdso]",
 };
@@ -100,6 +103,13 @@ is_in_string_list (const char *s, const char *const list[], size_t len)
   return -1;
 }
 
+static void *
+tf (void *closure)
+{
+  pthread_exit (NULL);
+  return NULL;
+}
+
 static int
 handle_restart (void)
 {
@@ -108,6 +118,9 @@ handle_restart (void)
   xdlopen (LIB_DLOPEN_DEFAULT, RTLD_NOW);
 #endif
 
+  /* pthread_exit will load LIBGCC_S_SO.  */
+  xpthread_join (xpthread_create (NULL, tf, NULL));
+
   FILE *fp = xfopen ("/proc/self/maps", "r");
   char *line = NULL;
   size_t linesiz = 0;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get
@ 2024-06-19 13:04 Adhemerval Zanella
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2024-06-19 13:04 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=00c5ee1da3973e352f9adab4c4e7dd378b6593ef

commit 00c5ee1da3973e352f9adab4c4e7dd378b6593ef
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Jun 7 21:12:18 2024 +0000

    elf: Enable RTLD_NODELETE on __libc_unwind_link_get
    
    The libgcc_s.so can also be sealed.  The library is loaded once
    and not unloaded during process execution (only for memory debug
    with __libc_unwind_link_freeres).
    
    Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Diff:
---
 include/dlfcn.h                        |  2 ++
 manual/tunables.texi                   |  4 ++++
 misc/unwind-link.c                     |  5 +++--
 sysdeps/unix/sysv/linux/tst-dl_mseal.c | 13 +++++++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/dlfcn.h b/include/dlfcn.h
index f49ee1b0c9..06e2ecbdd2 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -50,6 +50,8 @@ extern char **__libc_argv attribute_hidden;
    better error handling semantics for the library.  */
 #define __libc_dlopen(name) \
   __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
+#define __libc_dlopen_nodelete(name) \
+  __libc_dlopen_mode (name, RTLD_NODELETE | RTLD_NOW | __RTLD_DLOPEN)
 extern void *__libc_dlopen_mode  (const char *__name, int __mode)
   attribute_hidden;
 extern void *__libc_dlsym   (void *__map, const char *__name)
diff --git a/manual/tunables.texi b/manual/tunables.texi
index 65ec47c3d2..a5cc08ddf2 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -380,6 +380,10 @@ Any preload libraries.
 
 @item
 Any library loaded with @code{dlopen} with @code{RTLD_NODELETE} flag.
+
+@item
+Any runtime library used for process unwind (such as required by @code{backtrace}
+or @code{pthread_exit}).
 @end itemize
 
 The tunable accepts three diferent values: @samp{0} where sealing is disabled,
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 213a0162a4..7267ecbec3 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -48,7 +48,7 @@ __libc_unwind_link_get (void)
   /* Initialize a copy of the data, so that we do not need about
      unlocking in case the dynamic loader somehow triggers
      unwinding.  */
-  void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO);
+  void *local_libgcc_handle = __libc_dlopen_nodelete (LIBGCC_S_SO);
   if (local_libgcc_handle == NULL)
     {
       __libc_lock_unlock (lock);
@@ -100,7 +100,8 @@ __libc_unwind_link_get (void)
 
   __libc_lock_lock (lock);
   if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
-    /* This thread lost the race.  Clean up.  */
+    /* This thread lost the race.  Drop the l_direct_opencount and issue
+       the debug log.  */
     __libc_dlclose (local_libgcc_handle);
   else
     {
diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal.c b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
index 72a33d04c7..da1a3ebe5a 100644
--- a/sysdeps/unix/sysv/linux/tst-dl_mseal.c
+++ b/sysdeps/unix/sysv/linux/tst-dl_mseal.c
@@ -19,6 +19,7 @@
 #include <array_length.h>
 #include <errno.h>
 #include <getopt.h>
+#include <gnu/lib-names.h>
 #include <inttypes.h>
 #include <libgen.h>
 #include <stdio.h>
@@ -31,6 +32,7 @@
 #include <support/support.h>
 #include <support/xdlfcn.h>
 #include <support/xstdio.h>
+#include <support/xthread.h>
 
 #define LIB_PRELOAD              "lib-tst-dl_mseal-preload.so"
 
@@ -70,6 +72,7 @@ static const char *expected_sealed_libs[] =
   LIB_NEEDED_2,
   LIB_DLOPEN_NODELETE,
   LIB_DLOPEN_NODELETE_DEP,
+  LIBGCC_S_SO,
 #endif
   "[vdso]",
 };
@@ -100,6 +103,13 @@ is_in_string_list (const char *s, const char *const list[], size_t len)
   return -1;
 }
 
+static void *
+tf (void *closure)
+{
+  pthread_exit (NULL);
+  return NULL;
+}
+
 static int
 handle_restart (void)
 {
@@ -108,6 +118,9 @@ handle_restart (void)
   xdlopen (LIB_DLOPEN_DEFAULT, RTLD_NOW);
 #endif
 
+  /* pthread_exit will load LIBGCC_S_SO.  */
+  xpthread_join (xpthread_create (NULL, tf, NULL));
+
   FILE *fp = xfopen ("/proc/self/maps", "r");
   char *line = NULL;
   size_t linesiz = 0;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get
@ 2024-06-04 22:57 Adhemerval Zanella
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2024-06-04 22:57 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1dfe4b60eefbf3d72b1d3951be422d4345b293ab

commit 1dfe4b60eefbf3d72b1d3951be422d4345b293ab
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 4 10:07:41 2024 -0300

    elf: Enable RTLD_NODELETE on __libc_unwind_link_get
    
    So the libgcc_s.so can also be sealed.  The library is loaded once
    and not unloaded during process execution (only for memory debug
    with __libc_unwind_link_freeres).

Diff:
---
 include/dlfcn.h    | 2 ++
 misc/unwind-link.c | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/dlfcn.h b/include/dlfcn.h
index f49ee1b0c9..06e2ecbdd2 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -50,6 +50,8 @@ extern char **__libc_argv attribute_hidden;
    better error handling semantics for the library.  */
 #define __libc_dlopen(name) \
   __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
+#define __libc_dlopen_nodelete(name) \
+  __libc_dlopen_mode (name, RTLD_NODELETE | RTLD_NOW | __RTLD_DLOPEN)
 extern void *__libc_dlopen_mode  (const char *__name, int __mode)
   attribute_hidden;
 extern void *__libc_dlsym   (void *__map, const char *__name)
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 213a0162a4..7267ecbec3 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -48,7 +48,7 @@ __libc_unwind_link_get (void)
   /* Initialize a copy of the data, so that we do not need about
      unlocking in case the dynamic loader somehow triggers
      unwinding.  */
-  void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO);
+  void *local_libgcc_handle = __libc_dlopen_nodelete (LIBGCC_S_SO);
   if (local_libgcc_handle == NULL)
     {
       __libc_lock_unlock (lock);
@@ -100,7 +100,8 @@ __libc_unwind_link_get (void)
 
   __libc_lock_lock (lock);
   if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
-    /* This thread lost the race.  Clean up.  */
+    /* This thread lost the race.  Drop the l_direct_opencount and issue
+       the debug log.  */
     __libc_dlclose (local_libgcc_handle);
   else
     {

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get
@ 2024-06-04 14:08 Adhemerval Zanella
  0 siblings, 0 replies; 5+ messages in thread
From: Adhemerval Zanella @ 2024-06-04 14:08 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3b8c02ca8b20b9ae1c0872426131402dc2b50695

commit 3b8c02ca8b20b9ae1c0872426131402dc2b50695
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jun 4 10:07:41 2024 -0300

    elf: Enable RTLD_NODELETE on __libc_unwind_link_get
    
    So the libgcc_s.so can also be sealed.  The library is loaded once
    and not unloaded during process execution (only for memory debug
    with __libc_unwind_link_freeres).

Diff:
---
 include/dlfcn.h    | 2 ++
 misc/unwind-link.c | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/dlfcn.h b/include/dlfcn.h
index f49ee1b0c9..06e2ecbdd2 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -50,6 +50,8 @@ extern char **__libc_argv attribute_hidden;
    better error handling semantics for the library.  */
 #define __libc_dlopen(name) \
   __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
+#define __libc_dlopen_nodelete(name) \
+  __libc_dlopen_mode (name, RTLD_NODELETE | RTLD_NOW | __RTLD_DLOPEN)
 extern void *__libc_dlopen_mode  (const char *__name, int __mode)
   attribute_hidden;
 extern void *__libc_dlsym   (void *__map, const char *__name)
diff --git a/misc/unwind-link.c b/misc/unwind-link.c
index 213a0162a4..7267ecbec3 100644
--- a/misc/unwind-link.c
+++ b/misc/unwind-link.c
@@ -48,7 +48,7 @@ __libc_unwind_link_get (void)
   /* Initialize a copy of the data, so that we do not need about
      unlocking in case the dynamic loader somehow triggers
      unwinding.  */
-  void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO);
+  void *local_libgcc_handle = __libc_dlopen_nodelete (LIBGCC_S_SO);
   if (local_libgcc_handle == NULL)
     {
       __libc_lock_unlock (lock);
@@ -100,7 +100,8 @@ __libc_unwind_link_get (void)
 
   __libc_lock_lock (lock);
   if (atomic_load_relaxed (&global_libgcc_handle) != NULL)
-    /* This thread lost the race.  Clean up.  */
+    /* This thread lost the race.  Drop the l_direct_opencount and issue
+       the debug log.  */
     __libc_dlclose (local_libgcc_handle);
   else
     {

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-21 14:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-04 13:22 [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get Adhemerval Zanella
2024-06-04 14:08 Adhemerval Zanella
2024-06-04 22:57 Adhemerval Zanella
2024-06-19 13:04 Adhemerval Zanella
2024-06-21 14:30 Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).