8a8cfb
commit 5177d85b0c050a2333a0c4165c938dd422013d05
8a8cfb
Author: H.J. Lu <hjl.tools@gmail.com>
8a8cfb
Date:   Thu Jan 16 06:45:36 2020 -0800
8a8cfb
8a8cfb
    Clear GL(dl_initfirst) when freeing its link_map memory [BZ# 25396]
8a8cfb
    
8a8cfb
    We should clear GL(dl_initfirst) when freeing its link_map memory.
8a8cfb
    
8a8cfb
    Tested on Fedora 31/x86-64 with CET.
8a8cfb
    
8a8cfb
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
8a8cfb
8a8cfb
diff --git a/elf/dl-close.c b/elf/dl-close.c
8a8cfb
index fa7f3e8174576e46..a9ecdff62dba88fb 100644
8a8cfb
--- a/elf/dl-close.c
8a8cfb
+++ b/elf/dl-close.c
8a8cfb
@@ -749,6 +749,10 @@ _dl_close_worker (struct link_map *map, bool force)
8a8cfb
 	  if (imap->l_runpath_dirs.dirs != (void *) -1)
8a8cfb
 	    free (imap->l_runpath_dirs.dirs);
8a8cfb
 
8a8cfb
+	  /* Clear GL(dl_initfirst) when freeing its link_map memory.  */
8a8cfb
+	  if (imap == GL(dl_initfirst))
8a8cfb
+	    GL(dl_initfirst) = NULL;
8a8cfb
+
8a8cfb
 	  free (imap);
8a8cfb
 	}
8a8cfb
     }