diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-04-21 19:49:51 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-04-21 19:49:51 +0200 |
commit | fada9018199c21c469ff0e731ef75c6020074ac9 (patch) | |
tree | 92a5914178f7acac985fd4ce15d4e7ee99522e9d /malloc/set-freeres.c | |
parent | b2964eb1d9a6b8ab1250e8a881cf406182da5875 (diff) | |
download | glibc-fada9018199c21c469ff0e731ef75c6020074ac9.tar.gz glibc-fada9018199c21c469ff0e731ef75c6020074ac9.tar.xz glibc-fada9018199c21c469ff0e731ef75c6020074ac9.zip |
dlfcn: dlerror needs to call free from the base namespace [BZ #24773]
Calling free directly may end up freeing a pointer allocated by the dynamic loader using malloc from libc.so in the base namespace using the allocator from libc.so in a secondary namespace, which results in crashes. This commit redirects the free call through GLRO and the dynamic linker, to reach the correct namespace. It also cleans up the dlerror handling along the way, so that pthread_setspecific is no longer needed (which avoids triggering bug 24774).
Diffstat (limited to 'malloc/set-freeres.c')
-rw-r--r-- | malloc/set-freeres.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c index 817fbea8b8..d404250151 100644 --- a/malloc/set-freeres.c +++ b/malloc/set-freeres.c @@ -20,6 +20,7 @@ #include <set-hooks.h> #include <libc-internal.h> #include <unwind-link.h> +#include <dlfcn/dlerror.h> #include "../nss/nsswitch.h" #include "../libio/libioP.h" @@ -28,8 +29,6 @@ DEFINE_HOOK (__libc_subfreeres, (void)); symbol_set_define (__libc_freeres_ptrs); -extern __attribute__ ((weak)) void __libdl_freeres (void); - extern __attribute__ ((weak)) void __libpthread_freeres (void); void __libc_freeres_fn_section @@ -52,11 +51,6 @@ __libc_freeres (void) /* We run the resource freeing after IO cleanup. */ RUN_HOOK (__libc_subfreeres, ()); - /* Call the libdl list of cleanup functions - (weak-ref-and-check). */ - if (&__libdl_freeres != NULL) - __libdl_freeres (); - /* Call the libpthread list of cleanup functions (weak-ref-and-check). */ if (&__libpthread_freeres != NULL) @@ -66,6 +60,8 @@ __libc_freeres (void) __libc_unwind_link_freeres (); #endif + call_function_static_weak (__libc_dlerror_result_free); + for (p = symbol_set_first_element (__libc_freeres_ptrs); !symbol_set_end_p (__libc_freeres_ptrs, p); ++p) free (*p); |