about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-04-21 19:49:51 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-04-21 19:49:51 +0200
commitfada9018199c21c469ff0e731ef75c6020074ac9 (patch)
tree92a5914178f7acac985fd4ce15d4e7ee99522e9d /sysdeps
parentb2964eb1d9a6b8ab1250e8a881cf406182da5875 (diff)
downloadglibc-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 'sysdeps')
-rw-r--r--sysdeps/generic/ldsodefs.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index b207f229c3..dfc117a445 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -668,6 +668,9 @@ struct rtld_global_ro
   int (*_dl_catch_error) (const char **objname, const char **errstring,
 			  bool *mallocedp, void (*operate) (void *),
 			  void *args);
+  /* libdl in a secondary namespace must use free from the base
+     namespace.  */
+  void (*_dl_error_free) (void *);
   void *(*_dl_tls_get_addr_soft) (struct link_map *);
 #ifdef HAVE_DL_DISCOVER_OSVERSION
   int (*_dl_discover_osversion) (void);
@@ -823,6 +826,10 @@ void _dl_exception_create (struct dl_exception *, const char *object,
   __attribute__ ((nonnull (1, 3)));
 rtld_hidden_proto (_dl_exception_create)
 
+/* Used internally to implement dlerror message freeing.  See
+   include/dlfcn.h and dlfcn/dlerror.c.  */
+void _dl_error_free (void *ptr) attribute_hidden;
+
 /* Like _dl_exception_create, but create errstring from a format
    string FMT.  Currently, only "%s" and "%%" are supported as format
    directives.  */