public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/azanella/mseal] elf: Enable RTLD_NODELETE on __libc_unwind_link_get Date: Wed, 19 Jun 2024 13:04:56 +0000 (GMT) [thread overview] Message-ID: <20240619130456.A61F23885C3A@sourceware.org> (raw) 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;
next reply other threads:[~2024-06-19 13:04 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-06-19 13:04 Adhemerval Zanella [this message] -- strict thread matches above, loose matches on Subject: below -- 2024-06-21 14:30 Adhemerval Zanella 2024-06-04 22:57 Adhemerval Zanella 2024-06-04 14:08 Adhemerval Zanella 2024-06-04 13:22 Adhemerval Zanella
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240619130456.A61F23885C3A@sourceware.org \ --to=azanella@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).