public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH v2] elf: Replace nsid with args.nsid [BZ #27609]
Date: Thu, 30 Sep 2021 11:36:21 -0700	[thread overview]
Message-ID: <CAMe9rOrbsOiH6MKKLkp3uW9_dnLk3rZpN++z0cSLOJ3CJURuCw@mail.gmail.com> (raw)
In-Reply-To: <87v92h2a1t.fsf@oldenburg.str.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1216 bytes --]

On Thu, Sep 30, 2021 at 11:27 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > do_dlopen calls _dl_open with nsid == __LM_ID_CALLER (-2), which calls
> > dl_open_worker with args.nsid = nsid.  dl_open_worker updates args.nsid
> > if it is __LM_ID_CALLER.  After dl_open_worker returns, use args.nsid
> > instead of nsid.  This fixes BZ #27609.
> > ---
> >  elf/dl-open.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/elf/dl-open.c b/elf/dl-open.c
> > index a25443f6d1..5295e931b0 100644
> > --- a/elf/dl-open.c
> > +++ b/elf/dl-open.c
> > @@ -886,7 +886,7 @@ no more namespaces available for dlmopen()"));
> >        /* Avoid keeping around a dangling reference to the libc.so link
> >        map in case it has been cached in libc_map.  */
> >        if (!args.libc_already_loaded)
> > -     GL(dl_ns)[nsid].libc_map = NULL;
> > +     GL(dl_ns)[args.nsid].libc_map = NULL;
> >
> >        /* Remove the object from memory.  It may be in an inconsistent
> >        state if relocation failed, for example.  */
>
> Patch looks okay.  But could you reference the fixed commit in the
> commit message?
>

Done.   Here is the patch I am checking in.

Thanks.

-- 
H.J.

[-- Attachment #2: v3-0001-elf-Replace-nsid-with-args.nsid-BZ-27609.patch --]
[-- Type: text/x-patch, Size: 1705 bytes --]

From 735f80b08b910c5e10c95fb5ea72b39726b143bb Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 30 Sep 2021 10:29:17 -0700
Subject: [PATCH v3] elf: Replace nsid with args.nsid [BZ #27609]

commit ec935dea6332cb22f9881cd1162bad156173f4b0
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Apr 24 22:31:15 2020 +0200

    elf: Implement __libc_early_init

has

@@ -856,6 +876,11 @@ no more namespaces available for dlmopen()"));
   /* See if an error occurred during loading.  */
   if (__glibc_unlikely (exception.errstring != NULL))
     {
+      /* Avoid keeping around a dangling reference to the libc.so link
+   map in case it has been cached in libc_map.  */
+      if (!args.libc_already_loaded)
+  GL(dl_ns)[nsid].libc_map = NULL;
+

do_dlopen calls _dl_open with nsid == __LM_ID_CALLER (-2), which calls
dl_open_worker with args.nsid = nsid.  dl_open_worker updates args.nsid
if it is __LM_ID_CALLER.  After dl_open_worker returns, it is wrong to
use nsid.

Replace nsid with args.nsid after dl_open_worker returns.  This fixes
BZ #27609.
---
 elf/dl-open.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/elf/dl-open.c b/elf/dl-open.c
index a25443f6d1..5295e931b0 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -886,7 +886,7 @@ no more namespaces available for dlmopen()"));
       /* Avoid keeping around a dangling reference to the libc.so link
 	 map in case it has been cached in libc_map.  */
       if (!args.libc_already_loaded)
-	GL(dl_ns)[nsid].libc_map = NULL;
+	GL(dl_ns)[args.nsid].libc_map = NULL;
 
       /* Remove the object from memory.  It may be in an inconsistent
 	 state if relocation failed, for example.  */
-- 
2.31.1


      reply	other threads:[~2021-09-30 18:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 18:23 H.J. Lu
2021-09-30 18:27 ` Florian Weimer
2021-09-30 18:36   ` H.J. Lu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOrbsOiH6MKKLkp3uW9_dnLk3rZpN++z0cSLOJ3CJURuCw@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).