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