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