From: "Vivek Das Mohapatra" <vivek@collabora.com>
To: libc-alpha <libc-alpha@sourceware.org>
Subject: [RFC][PATCH v7 16/20] Suppress inter-namespace DSO sharing for audit libraries
Date: Wed, 16 Dec 2020 13:26:46 +0000 [thread overview]
Message-ID: <20201216132650.22949-17-vivek@collabora.com> (raw)
In-Reply-To: <20201216132650.22949-1-vivek@collabora.com>
Audit libraries should not participate in DSO sharing: In
particular libraries tagged with DF_GNU_1_UNIQUE should not
be shared between the audit namespace and any others - they
should get their own copy.
This is signalled to the loader code by passing the RTLD_ISOLATE
flag from the relevant entry point in the dl modes argument.
---
bits/dlfcn.h | 3 +++
elf/dl-load.c | 5 +++--
elf/dl-open.c | 13 +++++++++++--
elf/rtld.c | 2 +-
sysdeps/mips/bits/dlfcn.h | 3 +++
5 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/bits/dlfcn.h b/bits/dlfcn.h
index 9170059323..2f1f7c04fa 100644
--- a/bits/dlfcn.h
+++ b/bits/dlfcn.h
@@ -32,6 +32,9 @@
visible as if the object were linked directly into the program. */
#define RTLD_GLOBAL 0x00100
+/* Suppress RTLD_SHARED and/or DF_GNU_1_UNIQUE. */
+#define RTLD_ISOLATE 0x00040
+
/* If the following bit is set in the MODE argument to dlmopen
then the target object is loaded into the main namespace (if
it is not already there) and a shallow copy (proxy) is placed
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 9bd4884a88..22c0e92a1d 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1079,7 +1079,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
/* 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))
+ if (__glibc_unlikely ((nsid != LM_ID_BASE) && !(mode & RTLD_ISOLATE)))
{
/* 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)
@@ -1174,7 +1174,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
/* We need to check for DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE before we start
initialising any namespace dependent metatada. */
- if (nsid != LM_ID_BASE)
+ if (__glibc_unlikely ((nsid != LM_ID_BASE) && !(mode & RTLD_ISOLATE)))
{
/* Target DSO is flagged as unique: Make sure it gets loaded into
the base namespace. It is up to our caller to generate a proxy in
@@ -2188,6 +2188,7 @@ _dl_map_object (struct link_map *loader, const char *name,
assert (nsid >= 0);
assert (nsid < GL(dl_nns));
+ assert (!((mode & RTLD_ISOLATE) && (mode & RTLD_SHARED)));
#ifdef SHARED
/* Only need to do proxy checks if `nsid' is not LM_ID_BASE. */
diff --git a/elf/dl-open.c b/elf/dl-open.c
index 84f27dd1c6..62ed2a084f 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -485,9 +485,16 @@ dl_open_worker (void *a)
int mode = args->mode;
struct link_map *call_map = NULL;
struct link_map *preloaded = NULL;
- int want_proxy = mode & RTLD_SHARED;
+ int want_proxy = 0;
+ int dl_isolate = mode & RTLD_ISOLATE;
Lmid_t proxy_ns = LM_ID_BASE;
+ /* Isolation means we should suppress all inter-namespace sharing. */
+ if (dl_isolate)
+ mode &= ~RTLD_SHARED;
+ else
+ want_proxy = mode & RTLD_SHARED;
+
/* Determine the caller's map if necessary. This is needed in case
we have a DST, when we don't know the namespace ID we have to put
the new object in, or when the file name has no path in which
@@ -539,6 +546,7 @@ dl_open_worker (void *a)
mode and set want_proxy.
NOTE: RTLD_ISOLATE in the mode suppresses this behaviour. */
if (__glibc_unlikely (args->nsid != LM_ID_BASE) &&
+ __glibc_likely (!dl_isolate) &&
__glibc_likely (!want_proxy))
{
preloaded = _dl_find_dso (file, LM_ID_BASE);
@@ -650,7 +658,8 @@ dl_open_worker (void *a)
/* Load that object's dependencies. */
_dl_map_object_deps (new, NULL, 0, 0,
- mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT));
+ mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT |
+ RTLD_ISOLATE));
/* So far, so good. Now check the versions. */
for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
diff --git a/elf/rtld.c b/elf/rtld.c
index 526360237f..f127df2c53 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -657,7 +657,7 @@ dlmopen_doit (void *a)
struct dlmopen_args *args = (struct dlmopen_args *) a;
args->map = _dl_open (args->fname,
(RTLD_LAZY | __RTLD_DLOPEN | __RTLD_AUDIT
- | __RTLD_SECURE),
+ | __RTLD_SECURE | RTLD_ISOLATE),
dl_main, LM_ID_NEWLM, _dl_argc, _dl_argv,
__environ);
}
diff --git a/sysdeps/mips/bits/dlfcn.h b/sysdeps/mips/bits/dlfcn.h
index fc33fd184e..a21755a868 100644
--- a/sysdeps/mips/bits/dlfcn.h
+++ b/sysdeps/mips/bits/dlfcn.h
@@ -39,6 +39,9 @@
share a single instance of a DSO. */
#define RTLD_SHARED 0x00020
+/* Suppress RTLD_SHARED and/or DF_GNU_1_UNIQUE. */
+#define RTLD_ISOLATE 0x00040
+
/* Unix98 demands the following flag which is the inverse to RTLD_GLOBAL.
The implementation does this by default and so we can define the
value to zero. */
--
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 ` [RFC][PATCH v7 11/20] Compare loaded DSOs by file ID and check for DF_GNU_1_UNIQUE Vivek Das Mohapatra
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 ` Vivek Das Mohapatra [this message]
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-17-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).