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