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