glibc/SOURCES/glibc-RHEL-39415.patch

29 lines
1.1 KiB
Diff

Try to cover for incorrect dynamic TLS usage in some malloc
implementations.
Upstream discussion:
New TLS usage in libgcc_s.so.1, compatibility impact
<https://inbox.sourceware.org/gcc/8734v1ieke.fsf@oldenburg.str.redhat.com/>
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index b9dc56e81a3b43db..231171b72c21828f 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -825,7 +825,14 @@ _dl_update_slotinfo (unsigned long int req_modid, size_t new_gen)
dtv entry free it. Note: this is not AS-safe. */
/* XXX Ideally we will at some point create a memory
pool. */
- free (dtv[modid].pointer.to_free);
+ /* Avoid calling free on a null pointer. Some mallocs
+ incorrectly use dynamic TLS, and depending on how the
+ free function was compiled, it could call
+ __tls_get_addr before the null pointer check in the
+ free implementation. Checking here papers over at
+ least some dynamic TLS usage by interposed mallocs. */
+ if (dtv[modid].pointer.to_free != NULL)
+ free (dtv[modid].pointer.to_free);
dtv[modid].pointer.val = TLS_DTV_UNALLOCATED;
dtv[modid].pointer.to_free = NULL;