From: "Vivek Das Mohapatra" <vivek@collabora.com>
To: libc-alpha <libc-alpha@sourceware.org>
Subject: [RFC][PATCH v7 11/20] Compare loaded DSOs by file ID and check for DF_GNU_1_UNIQUE
Date: Wed, 16 Dec 2020 13:26:41 +0000 [thread overview]
Message-ID: <20201216132650.22949-12-vivek@collabora.com> (raw)
In-Reply-To: <20201216132650.22949-1-vivek@collabora.com>
If _dl_map_object_from_fd finds that a DSO it was asked to
load into a non-base namespace is already loaded (into the
main namespace) and is flagged DF_GNU_1_UNIQUE then it should
return that DSO's link map entry.
In such cases _dl_open_worker must notice that this has
happened and dontinue down the link map proxy generation
path instead of normal link map entry preparation.
---
elf/dl-load.c | 26 ++++++++++++++++++++++++++
elf/dl-open.c | 10 ++++++++++
2 files changed, 36 insertions(+)
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 3fda5de71b..0e6a493e07 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1020,6 +1020,32 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
}
#endif
+ /* DSOs in the main namespace which are flagged DF_GNU_1_UNIQUE should only
+ be opened into the main namespace. Other namespaces should only get
+ proxies. */
+ if (__glibc_unlikely (nsid != LM_ID_BASE))
+ {
+ /* Check base ns to see if the name matched another already loaded. */
+ for (l = GL(dl_ns)[LM_ID_BASE]._ns_loaded; l != NULL; l = l->l_next)
+ if (!l->l_removed && _dl_file_id_match_p (&l->l_file_id, &id))
+ {
+ if (!(l->l_gnu_flags_1 & DF_GNU_1_UNIQUE))
+ continue;
+
+ /* Already loaded. Bump its reference count and return it. */
+ __close_nocancel (fd);
+
+ /* If the name is not listed for this object add it. */
+ free (realname);
+ add_name_to_object (l, name);
+
+ /* NOTE: It is important that our caller picks up on the fact
+ that we have NOT returned an object in the requested namespace
+ and handles the proxying correctly */
+ return l;
+ }
+ }
+
if (mode & RTLD_NOLOAD)
{
/* We are not supposed to load the object unless it is already
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 02e094a867..a0f3233dd1 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -561,6 +561,16 @@ dl_open_worker (void *a)
return;
}
+ /* If we are trying to load a DF_GNU_1_UNIQUE flagged DSO which was
+ NOT ALREADY LOADED (or not loaded with the name we are using) then
+ _dl_map_object will have returned an instance from the main namespace.
+ We need to detect this and set up the RTLD_SHARED flags. */
+ if (__glibc_unlikely(args->nsid != LM_ID_BASE && new->l_ns == LM_ID_BASE))
+ {
+ want_proxy = RTLD_SHARED;
+ mode |= RTLD_SHARED;
+ }
+
/* If we want proxy and we get this far then the entry in ‘new’ will
be in the main namespace: we should revert to the main namespace code
path(s), but remember the namespace we want the proxy to be in. */
--
2.20.1
next prev parent reply other threads:[~2020-12-16 13:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-16 13:26 [RFC][PATCH v7 00/20] Implementation of RTLD_SHARED for dlmopen Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 01/20] Declare and describe the dlmopen RTLD_SHARED flag Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 02/20] include/link.h: Update the link_map struct to allow proxies Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 03/20] elf/dl-object.c: Implement a helper function to proxy link_map entries Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 04/20] elf/dl-load.c, elf-dl-open.c: Implement RTLD_SHARED dlmopen proxying Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 05/20] elf/dl-fini.c: Handle proxy link_map entries in the shutdown path Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 06/20] elf/dl-init.c: Skip proxied link map entries in the dl init path Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 07/20] elf/dl-open.c: Don't try libc linit in namespaces with no libc mapping Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 08/20] elf/dl-open.c: when creating a proxy check the libc_map in NS 0 Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 09/20] Define a new dynamic section tag - DT_GNU_FLAGS_1 Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 10/20] Abstract the loaded-DSO search code into a private helper function Vivek Das Mohapatra
2020-12-16 13:26 ` Vivek Das Mohapatra [this message]
2020-12-16 13:26 ` [RFC][PATCH v7 12/20] Use the new DSO finder helper function since we have it Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 13/20] Use the DSO search helper to check for preloaded DT_GNU_UNIQUE DSOs Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 14/20] When loading DSOs into alternate namespaces check for DT_GNU_UNIQUE Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 15/20] Suppress audit calls when a (new) namespace is empty Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 16/20] Suppress inter-namespace DSO sharing for audit libraries Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 17/20] dlsym, dlvsym should be able to look up symbols via DSO proxies Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 18/20] Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE dynamic section+flag to glibc DSOs Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 19/20] Add dlmopen / RTLD_SHARED tests Vivek Das Mohapatra
2020-12-16 13:26 ` [RFC][PATCH v7 20/20] Restore separate libc loading for the TLS/namespace storage test Vivek Das Mohapatra
2021-01-07 17:00 ` Ping " Vivek Das Mohapatra
2021-01-07 19:55 ` Adhemerval Zanella
2021-01-08 0:33 ` Vivek Das Mohapatra
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=20201216132650.22949-12-vivek@collabora.com \
--to=vivek@collabora.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).