c5d972
commit 1e1ecea62e899acb58c3fdf3b320a0833ddd0dff
c5d972
Author: H.J. Lu <hjl.tools@gmail.com>
c5d972
Date:   Thu Sep 30 10:29:17 2021 -0700
c5d972
c5d972
    elf: Replace nsid with args.nsid [BZ #27609]
c5d972
    
c5d972
    commit ec935dea6332cb22f9881cd1162bad156173f4b0
c5d972
    Author: Florian Weimer <fweimer@redhat.com>
c5d972
    Date:   Fri Apr 24 22:31:15 2020 +0200
c5d972
    
c5d972
        elf: Implement __libc_early_init
c5d972
    
c5d972
    has
c5d972
    
c5d972
    @@ -856,6 +876,11 @@ no more namespaces available for dlmopen()"));
c5d972
       /* See if an error occurred during loading.  */
c5d972
       if (__glibc_unlikely (exception.errstring != NULL))
c5d972
         {
c5d972
    +      /* Avoid keeping around a dangling reference to the libc.so link
c5d972
    +   map in case it has been cached in libc_map.  */
c5d972
    +      if (!args.libc_already_loaded)
c5d972
    +  GL(dl_ns)[nsid].libc_map = NULL;
c5d972
    +
c5d972
    
c5d972
    do_dlopen calls _dl_open with nsid == __LM_ID_CALLER (-2), which calls
c5d972
    dl_open_worker with args.nsid = nsid.  dl_open_worker updates args.nsid
c5d972
    if it is __LM_ID_CALLER.  After dl_open_worker returns, it is wrong to
c5d972
    use nsid.
c5d972
    
c5d972
    Replace nsid with args.nsid after dl_open_worker returns.  This fixes
c5d972
    BZ #27609.
c5d972
c5d972
diff --git a/elf/dl-open.c b/elf/dl-open.c
c5d972
index 661a2172d1789b26..b5a4da04907d8d29 100644
c5d972
--- a/elf/dl-open.c
c5d972
+++ b/elf/dl-open.c
c5d972
@@ -916,7 +916,7 @@ no more namespaces available for dlmopen()"));
c5d972
       /* Avoid keeping around a dangling reference to the libc.so link
c5d972
 	 map in case it has been cached in libc_map.  */
c5d972
       if (!args.libc_already_loaded)
c5d972
-	GL(dl_ns)[nsid].libc_map = NULL;
c5d972
+	GL(dl_ns)[args.nsid].libc_map = NULL;
c5d972
 
c5d972
       /* Remove the object from memory.  It may be in an inconsistent
c5d972
 	 state if relocation failed, for example.  */