about summary refs log tree commit diff
path: root/elf/dl-exception.c
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 /elf/dl-exception.c
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 'elf/dl-exception.c')
-rw-r--r--elf/dl-exception.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/elf/dl-exception.c b/elf/dl-exception.c
index 30adb7d1dc..8eaad418cb 100644
--- a/elf/dl-exception.c
+++ b/elf/dl-exception.c
@@ -30,6 +30,17 @@
    a pointer comparison.  See below and in dlfcn/dlerror.c.  */
 static const char _dl_out_of_memory[] = "out of memory";
 
+/* Call free in the main libc.so.  This allows other namespaces to
+   free pointers on the main libc heap, via GLRO (dl_error_free).  It
+   also avoids calling free on the special, pre-allocated
+   out-of-memory error message.  */
+void
+_dl_error_free (void *ptr)
+{
+  if (ptr != _dl_out_of_memory)
+    free (ptr);
+}
+
 /* Dummy allocation object used if allocating the message buffer
    fails.  */
 static void