From patchwork Tue Dec 15 18:44:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41407 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2976738708B9; Tue, 15 Dec 2020 18:45:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2976738708B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057912; bh=uT+xrjqqemSFvmKd6qSgI/1zIBLxgrmdmsq5nOIJjk4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=H+/rhnQD6WXaG8D6nmQBesoaX4CQdpt38FnhLrZEz5N5+0dro2sDlNTm8B6rzIiKF EZdQ2hlr7i0ASGGyD6eECaMYd1ynKwkajOkOOdm/i5aEWZD2IKXsgFo24K8Q3gWV+S 0bXgpwRR09XzGfKrhvcEpORbVILbpjuhLUUPQEtk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id D2ACD386F035 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D2ACD386F035 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 1C1771F45610 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 01/20] Declare and describe the dlmopen RTLD_SHARED flag Date: Tue, 15 Dec 2020 18:44:41 +0000 Message-Id: <20201215184500.25915-2-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This flag will instruct dlmopen to create a shared object present in the main namespace and accessible from the selected namespace when supplied in the MODE argument. --- bits/dlfcn.h | 7 +++++++ sysdeps/mips/bits/dlfcn.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/bits/dlfcn.h b/bits/dlfcn.h index ed67f29bc3..9170059323 100644 --- a/bits/dlfcn.h +++ b/bits/dlfcn.h @@ -32,6 +32,13 @@ visible as if the object were linked directly into the program. */ #define RTLD_GLOBAL 0x00100 +/* 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 + in the target namespace: This allows multiple namespaces to + share a single instance of a DSO. */ +#define RTLD_SHARED 0x00080 + /* 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. */ diff --git a/sysdeps/mips/bits/dlfcn.h b/sysdeps/mips/bits/dlfcn.h index e55262f3aa..fc33fd184e 100644 --- a/sysdeps/mips/bits/dlfcn.h +++ b/sysdeps/mips/bits/dlfcn.h @@ -32,6 +32,13 @@ visible as if the object were linked directly into the program. */ #define RTLD_GLOBAL 0x0004 +/* 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 + in the target namespace: This allows multiple namespaces to + share a single instance of a DSO. */ +#define RTLD_SHARED 0x00020 + /* 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. */ From patchwork Tue Dec 15 18:44:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41409 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42BB43851C26; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42BB43851C26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057913; bh=hGbG6X5+wF6D2HZyGs/QjzCqcjtlN3vTsZt0DjjMI0Y=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=XzmhMpAnDIcUWnb7p2Jj0P0VXqOSn8VtZ8k+xigCs0juOthfe+vfCBZghrNjaadiQ KOYlbBC6NLmh7aLtRseeZWuqEjJ7KE+SNSsT4wqvrrd5xmG1dOv7/WhsLGlM4xi5Yr YOdX7v1kzthG7oEePc3KxsxLaHr6tb0c1PdXVc3Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id DBAFC387089C for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DBAFC387089C Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 2AB1E1F45611 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 02/20] include/link.h: Update the link_map struct to allow proxies Date: Tue, 15 Dec 2020 18:44:42 +0000 Message-Id: <20201215184500.25915-3-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" We already have an l_real pointer, used for a similar purpose by the linker for copies of ld.so in secondary namespaces. Update its documentation and add a bitfield to indicate when link_map entry is a proxy. --- include/link.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/link.h b/include/link.h index d4714bc28d..8732f3b5d5 100644 --- a/include/link.h +++ b/include/link.h @@ -107,8 +107,9 @@ struct link_map They may change without notice. */ /* This is an element which is only ever different from a pointer to - the very same copy of this type for ld.so when it is used in more - than one namespace. */ + the very same copy of this type when: + - A shallow copy of ld.so is placed in namespaces other than LM_ID_BASE. + - An object is proxied into a namespace by dlmopen with RTLD_SHARED. */ struct link_map *l_real; /* Number of the namespace this link map belongs to. */ @@ -180,6 +181,7 @@ struct link_map unsigned int l_relocated:1; /* Nonzero if object's relocations done. */ unsigned int l_init_called:1; /* Nonzero if DT_INIT function called. */ unsigned int l_global:1; /* Nonzero if object in _dl_global_scope. */ + unsigned int l_proxy:1; /* Nonzero if object is a shallow copy. */ unsigned int l_reserved:2; /* Reserved for internal use. */ unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed to by `l_phdr' is allocated. */ From patchwork Tue Dec 15 18:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41411 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F83D38708B2; Tue, 15 Dec 2020 18:45:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F83D38708B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057914; bh=pRj7WJEeUc29ouhHSxgk9yj0JN9OrX9Iz+rEJm+9sDk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GImWRW3XV+iEsTsD/goBGrPoSrzo/tDjQpPLNnPK7WBBUTazPudVDqq7bgkseTPPL K5FJXvRZyrZyYYiYB9fj3czHG8Ke7yh0OgrikZ55NYtXjFxaQpJihTtf4dToeqCJZy VU+IhearkdrVuRYmKu14kowq/IsGe4VUlU8QLYAc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by sourceware.org (Postfix) with ESMTPS id 26FBD387089D for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 26FBD387089D Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 39F601F45612 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 03/20] elf/dl-object.c: Implement a helper function to proxy link_map entries Date: Tue, 15 Dec 2020 18:44:43 +0000 Message-Id: <20201215184500.25915-4-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Provides the minimal functionality needed to take an existing link_map entry and create a proxy for it in the specified namespace. --- elf/dl-object.c | 84 ++++++++++++++++++++++++++++++++++++++ sysdeps/generic/ldsodefs.h | 5 +++ 2 files changed, 89 insertions(+) diff --git a/elf/dl-object.c b/elf/dl-object.c index d2cdf135cc..2ee5eee13c 100644 --- a/elf/dl-object.c +++ b/elf/dl-object.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -50,6 +51,89 @@ _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid) __rtld_lock_unlock_recursive (GL(dl_load_write_lock)); } +/* Proxy an existing link map entry into a new link map: + This is based on _dl_new_object, skipping the steps we know we won't need + because this is mostly just a shell for the l_real pointer holding the real + link map entry (normally l == l->l_real, but not for ld.so in non-main + link maps or RTLD_SHARED proxies). + It also flags the proxy by setting l_proxy, and sets the the no-delete + flag in the original if it is an lt_loaded. */ +struct link_map * +_dl_new_proxy (struct link_map *old, int mode, Lmid_t nsid) +{ + const char *name; + struct link_map *new; + struct libname_list *newname; +#ifdef SHARED + unsigned int na = GLRO(dl_naudit); + + if ((mode & __RTLD_OPENEXEC) != 0) + na = DL_NNS; + + size_t audit_space = na * sizeof (struct auditstate); +#else +# define audit_space 0 +#endif + + name = old->l_name; + + /* Find the original link map entry if `old' is itself a proxy. */ + while (old && old->l_proxy) + old = old->l_real; + + if (old == NULL) + _dl_signal_error (EINVAL, name, NULL, N_("cannot proxy NULL link_map")); + + /* Object already exists in the target namespace. This should get handled + by dl_open_worker but just in case we get this far, handle it: */ + if (__glibc_unlikely (old->l_ns == nsid)) + { + /* Not actually possible, given the sanity checks above. */ + if (old->l_proxy) + return old; + + _dl_signal_error (EEXIST, name, NULL, + N_("existing object cannot be demoted to a proxy")); + } + + /* Now duplicate as little of _dl_new_object as possible to get a + working proxied object in the target link map. */ + new = (struct link_map *) calloc (sizeof (*new) + audit_space + + sizeof (struct link_map *) + + sizeof (*newname) + PATH_MAX, 1); + + if (new == NULL) + _dl_signal_error (ENOMEM, name, NULL, + N_("cannot create shared object descriptor")); + + /* Specific to the proxy. */ + new->l_real = old; + new->l_proxy = 1; + new->l_ns = nsid; + + /* Copied from the origin. */ + new->l_libname = old->l_libname; + new->l_name = old->l_name; + /* Proxies are considered lt_loaded if the real entry type is lt_library. */ + new->l_type = (old->l_type == lt_library) ? lt_loaded : old->l_type; + + if (__glibc_unlikely (mode & RTLD_NODELETE)) + new->l_flags_1 |= DF_1_NODELETE; + + /* Specific to the origin. Ideally we'd do some accounting here but + for now it's easier to pin the original so the proxy remains valid. */ + if (old->l_type == lt_loaded) + old->l_flags_1 |= DF_1_NODELETE; + + /* Fix up the searchlist so that relocations work. */ + _dl_map_object_deps (new, NULL, 0, 0, + mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT)); + + /* And finally put the proxy in the target namespace. */ + _dl_add_to_namespace_list (new, nsid); + + return new; +} /* Allocate a `struct link_map' for a new object being loaded, and enter it into the _dl_loaded list. */ diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 933cda117d..5411263cc0 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -971,6 +971,11 @@ extern lookup_t _dl_lookup_symbol_x (const char *undef, struct link_map *skip_map) attribute_hidden; +/* Proxy an existing link map entry into a new link map */ +extern struct link_map *_dl_new_proxy (struct link_map *old, + int mode, + Lmid_t nsid) + attribute_hidden; /* Restricted version of _dl_lookup_symbol_x. Searches MAP (and only MAP) for the symbol UNDEF_NAME, with GNU hash NEW_HASH (computed From patchwork Tue Dec 15 18:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41410 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD5CC38708B5; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD5CC38708B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057913; bh=hm0HluOj0tsDOblrvy16QLsQgRLWkHTqmB30vLnddOQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=v4umfVGYbAY9UwDUVvWtSfBAnPEa++Sa1KXqKvwGS6jQoLnxP3BcDvn3Ii5knX5k3 oJqf64O3kniCio8eKyL+IATJC15/HJQQUqv41TDGZWjmQDKCynZnk3fvDXLvfar9qB S9JK2l4Qy93AbQpsX9l+wnii8VAfoebpTOPWW91Y= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 201D73851C26 for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 201D73851C26 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 48AEC1F45613 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 04/20] elf/dl-load.c, elf-dl-open.c: Implement RTLD_SHARED dlmopen proxying Date: Tue, 15 Dec 2020 18:44:44 +0000 Message-Id: <20201215184500.25915-5-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This uses the new infrastructure to implement RTLD_SHARED object proxying via dlmopen: Instead of opening the specified object in the requested namespace we open it in the main namespace (if it is not already present there) and proxy it to the destination. The following rules apply: If a proxy of the object is already present in the requested namespace, we simply return it (with an incremented direct-open count). If the object is already present in the requested namespace, a dl error is signalled, since we cannot satisfy the user's request. Proxies are never created in the main namespace: RTLD_SHARED has no effect when the requested namespace is LM_ID_BASE. --- elf/dl-load.c | 46 +++++++++++++++++++++++++++++++++++++++ elf/dl-open.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 21c2920396..0c8cb763c1 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2006,6 +2006,38 @@ open_path (const char *name, size_t namelen, int mode, return -1; } +/* Search for a link map proxy in the given namespace by name. + Consider it to be an error if the found object is not a proxy. */ + +struct link_map * +_dl_find_proxy (Lmid_t nsid, const char *name) +{ + struct link_map *l; + + for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next) + { + if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0)) + continue; + + if (!_dl_name_match_p (name, l)) + continue; + + /* We have a match - stop searching. */ + break; + } + + if (l) + { + if (l->l_proxy) + return l; + + _dl_signal_error (EEXIST, name, NULL, + N_("object cannot be demoted to a proxy")); + } + + return NULL; +} + /* Map in the shared object file NAME. */ struct link_map * @@ -2022,6 +2054,20 @@ _dl_map_object (struct link_map *loader, const char *name, assert (nsid >= 0); assert (nsid < GL(dl_nns)); +#ifdef SHARED + /* Only need to do proxy checks if `nsid' is not LM_ID_BASE. */ + if (__glibc_unlikely ((mode & RTLD_SHARED) && (nsid != LM_ID_BASE))) + { + /* Search the namespace in case the object is already proxied. */ + if((l = _dl_find_proxy (nsid, name)) != NULL) + return l; + + /* Further searches should be in the base ns: We will proxy the + resulting object in dl_open_worker *after* it is initialised. */ + nsid = LM_ID_BASE; + } +#endif + /* Look for this name among those already loaded. */ for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next) { diff --git a/elf/dl-open.c b/elf/dl-open.c index 8769e47051..809845e5e9 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -484,6 +484,8 @@ dl_open_worker (void *a) const char *file = args->file; int mode = args->mode; struct link_map *call_map = NULL; + int want_proxy = mode & RTLD_SHARED; + Lmid_t proxy_ns = LM_ID_BASE; /* 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 @@ -508,6 +510,15 @@ dl_open_worker (void *a) args->nsid = call_map->l_ns; } + /* Now that we know the NS for sure, sanity check the mode. */ + if (__glibc_likely(args->nsid == LM_ID_BASE) && + __glibc_unlikely(mode & RTLD_SHARED)) + { + args->mode &= ~RTLD_SHARED; + mode &= ~RTLD_SHARED; + want_proxy = 0; + } + /* The namespace ID is now known. Keep track of whether libc.so was already loaded, to determine whether it is necessary to call the early initialization routine (or clear libc_map on error). */ @@ -541,6 +552,24 @@ dl_open_worker (void *a) /* This object is directly loaded. */ ++new->l_direct_opencount; + /* Proxy already existed in the target ns, nothing left to do. */ + if (__glibc_unlikely (new->l_proxy)) + { + if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES)) + _dl_debug_printf ("proxied file=%s [%lu]; direct_opencount=%u\n\n", + new->l_name, new->l_ns, new->l_direct_opencount); + return; + } + + /* 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. */ + if (__glibc_unlikely (want_proxy)) + { + proxy_ns = args->nsid; + args->nsid = LM_ID_BASE; + } + /* It was already open. */ if (__glibc_unlikely (new->l_searchlist.r_list != NULL)) { @@ -572,6 +601,16 @@ dl_open_worker (void *a) assert (_dl_debug_initialize (0, args->nsid)->r_state == RT_CONSISTENT); + if (__glibc_unlikely (want_proxy)) + { + args->map = new = _dl_new_proxy (new, mode, proxy_ns); + ++new->l_direct_opencount; + + if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES)) + _dl_debug_printf ("proxying file=%s [%lu]; direct_opencount=%u\n\n", + new->l_name, new->l_ns, new->l_direct_opencount); + } + return; } @@ -787,6 +826,14 @@ dl_open_worker (void *a) if (mode & RTLD_GLOBAL) add_to_global_update (new); + if (__glibc_unlikely (want_proxy)) + { + /* args->map is the return slot which the caller sees, but keep + the original value of new hanging around so we can see the + real link map entry (for logging etc). */ + args->map = _dl_new_proxy (new, mode, proxy_ns); + ++args->map->l_direct_opencount; + } #ifndef SHARED /* We must be the static _dl_open in libc.a. A static program that has loaded a dynamic object now has competition. */ @@ -795,8 +842,16 @@ dl_open_worker (void *a) /* Let the user know about the opencount. */ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES)) - _dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n", - new->l_name, new->l_ns, new->l_direct_opencount); + { + _dl_debug_printf ("opening file=%s [%lu]; direct_opencount=%u\n\n", + new->l_name, new->l_ns, new->l_direct_opencount); + + if (args->map->l_proxy) + _dl_debug_printf ("proxying file=%s [%lu]; direct_opencount=%u\n\n", + args->map->l_name, + args->map->l_ns, + args->map->l_direct_opencount); + } } void * From patchwork Tue Dec 15 18:44:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41415 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23CAC38708C8; Tue, 15 Dec 2020 18:45:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23CAC38708C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057917; bh=9sLLCEutTvj/LpNOZMGDFnb6gaegZG0AZGtqDe48W9E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vUFoFXI7oalBk+5vvrEesqaZ1NfSDTtEFX/k6VpSccXIghC23T53gyp4Is6YoKV8H /JYGullqfzFbLvSlN/fjvaMVkfO9EXGrzqCUCH2ZCJdOtHJ0RVrMd9pbCXUZsqaNZP bgmDKF0aKrTw5zeP6LDiPasgFFjwcTcMbVbqwta0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by sourceware.org (Postfix) with ESMTPS id AB3D23851C26 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AB3D23851C26 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5994F1F45614 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 05/20] elf/dl-fini.c: Handle proxy link_map entries in the shutdown path Date: Tue, 15 Dec 2020 18:44:45 +0000 Message-Id: <20201215184500.25915-6-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" When cleaning up before exit we should not call destructors or otherwise free [most of] the contents of proxied link_map entries since they share [most of] their contents with the LM_ID_BASE objects to which they point. --- elf/dl-close.c | 43 ++++++++++++++++++++++++++----------------- elf/dl-fini.c | 6 ++++-- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/elf/dl-close.c b/elf/dl-close.c index 8e146ecee1..4847b3294f 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -283,8 +283,9 @@ _dl_close_worker (struct link_map *map, bool force) /* Call its termination function. Do not do it for half-cooked objects. Temporarily disable exception - handling, so that errors are fatal. */ - if (imap->l_init_called) + handling, so that errors are fatal. + Proxies should never have this flag set, but we double check. */ + if (imap->l_init_called && !imap->l_proxy) { /* When debugging print a message first. */ if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS, @@ -360,7 +361,9 @@ _dl_close_worker (struct link_map *map, bool force) one for the terminating NULL pointer. */ size_t remain = (new_list != NULL) + 1; bool removed_any = false; - for (size_t cnt = 0; imap->l_scope[cnt] != NULL; ++cnt) + for (size_t cnt = 0; + imap->l_scope && imap->l_scope[cnt] != NULL; + ++cnt) /* This relies on l_scope[] entries being always set either to its own l_symbolic_searchlist address, or some map's l_searchlist address. */ @@ -686,8 +689,10 @@ _dl_close_worker (struct link_map *map, bool force) /* We can unmap all the maps at once. We determined the start address and length when we loaded the object and - the `munmap' call does the rest. */ - DL_UNMAP (imap); + the `munmap' call does the rest. Proxies do not have + any segments of their own to unmap. */ + if (!imap->l_proxy) + DL_UNMAP (imap); /* Finally, unlink the data structure and free it. */ #if DL_NNS == 1 @@ -727,19 +732,23 @@ _dl_close_worker (struct link_map *map, bool force) _dl_debug_printf ("\nfile=%s [%lu]; destroying link map\n", imap->l_name, imap->l_ns); - /* This name always is allocated. */ - free (imap->l_name); - /* Remove the list with all the names of the shared object. */ + /* Skip structures borrowed by proxies from the real map. */ + if (!imap->l_proxy) + { + /* This name always is allocated. */ + free (imap->l_name); + /* Remove the list with all the names of the shared object. */ - struct libname_list *lnp = imap->l_libname; - do - { - struct libname_list *this = lnp; - lnp = lnp->next; - if (!this->dont_free) - free (this); - } - while (lnp != NULL); + struct libname_list *lnp = imap->l_libname; + do + { + struct libname_list *this = lnp; + lnp = lnp->next; + if (!this->dont_free) + free (this); + } + while (lnp != NULL); + } /* Remove the searchlists. */ free (imap->l_initfini); diff --git a/elf/dl-fini.c b/elf/dl-fini.c index 231db3d66d..25feb5216d 100644 --- a/elf/dl-fini.c +++ b/elf/dl-fini.c @@ -73,7 +73,7 @@ _dl_fini (void) assert (nloaded != 0 || GL(dl_ns)[ns]._ns_loaded == NULL); for (l = GL(dl_ns)[ns]._ns_loaded, i = 0; l != NULL; l = l->l_next) /* Do not handle ld.so in secondary namespaces. */ - if (l == l->l_real) + if (l == l->l_real || l->l_proxy) { assert (i < nloaded); @@ -111,7 +111,9 @@ _dl_fini (void) { struct link_map *l = maps[i]; - if (l->l_init_called) + /* Do not call fini functions via proxies, or for + objects which are not marked as initialised. */ + if (l->l_init_called && !l->l_proxy) { /* Make sure nothing happens if we are called twice. */ l->l_init_called = 0; From patchwork Tue Dec 15 18:44:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41419 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 571D838708DC; Tue, 15 Dec 2020 18:45:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 571D838708DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057919; bh=jRVNkUBiH1Quiqd+1h/R82nHpjgXX8anlNLgXUprz0A=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Hhkw6Nxa2rdvPZJ8QHSEYhWfkudW+n78MVsWiFxnoQNaAK+OAzcle6fbWf9CAvtNP QcXZNyQ74po5tUo1V6jHEVl2CRi2nws8x8H2TXF7ZukmRfo7QuHchtmr6k4mNO+C/z KeT01xT/4g9X6RS2T9JhF+5HO0hg5Y8FY2y5Zz8g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id D0EAF38708B1 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D0EAF38708B1 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 69E091F45615 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 06/20] elf/dl-init.c: Skip proxied link map entries in the dl init path Date: Tue, 15 Dec 2020 18:44:46 +0000 Message-Id: <20201215184500.25915-7-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Proxies should not trigger calls to DT_INIT constructors since they're just shims that point to the real, already loaded and initialised, objects. --- elf/dl-init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elf/dl-init.c b/elf/dl-init.c index 518824e8a5..11b00641a6 100644 --- a/elf/dl-init.c +++ b/elf/dl-init.c @@ -34,8 +34,8 @@ call_init (struct link_map *l, int argc, char **argv, char **env) need relocation, and neither do proxy objects.) */ assert (l->l_real->l_relocated || l->l_real->l_type == lt_executable); - if (l->l_init_called) - /* This object is all done. */ + if (l->l_init_called || l->l_proxy) + /* This object is all done, or a proxy (and therefore initless). */ return; /* Avoid handling this constructor again in case we have a circular From patchwork Tue Dec 15 18:44:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41413 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05B7938708AD; Tue, 15 Dec 2020 18:45:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05B7938708AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057916; bh=hZx4NnSU7lzpznxNR/B4/L0bqwZKUI4EFKCGDdVEjCg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fCJ10Cs00GYz4kwqDdK2TAIAbI2AA29T+oa39NY6UbQCkh/owqUIfAABYMrNyhLPu MihplmQsdTuUed1+dG5eTR3gcsAo+lT6Bb8hIoMkjvpWEk5OOIUd250Jqolf3ThJDF dNrDrcttoROGJZOMAomoB92ltgydVVeOPeDzSciY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by sourceware.org (Postfix) with ESMTPS id ABEF6386F035 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ABEF6386F035 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 779CA1F45616 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 07/20] elf/dl-open.c: Don't try libc linit in namespaces with no libc mapping Date: Tue, 15 Dec 2020 18:44:47 +0000 Message-Id: <20201215184500.25915-8-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Secondary namespaces which share their libc mapping with the main namespace cannot (and should not) have _dl_call_libc_early_init called for them by dl_open_worker. --- elf/dl-open.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/elf/dl-open.c b/elf/dl-open.c index 809845e5e9..a995e9086f 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -792,16 +792,21 @@ dl_open_worker (void *a) namespace. */ if (!args->libc_already_loaded) { + /* If this is a secondary (nsid != LM_ID_BASE) namespace then + it is POSSIBLE there's no libc_map at all - We use the one + shared with LM_ID_BASE instead (which MUST already be + initialised for us to even reach here). */ struct link_map *libc_map = GL(dl_ns)[args->nsid].libc_map; #ifdef SHARED - bool initial = libc_map->l_ns == LM_ID_BASE; + bool initial = libc_map && (libc_map->l_real->l_ns == LM_ID_BASE); #else /* In the static case, there is only one namespace, but it contains a secondary libc (the primary libc is statically linked). */ bool initial = false; #endif - _dl_call_libc_early_init (libc_map, initial); + if (libc_map != NULL) + _dl_call_libc_early_init (libc_map, initial); } #ifndef SHARED From patchwork Tue Dec 15 18:44:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41412 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D00138708CF; Tue, 15 Dec 2020 18:45:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D00138708CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057915; bh=/lARSfm/TLLkmmQFJbn2WgFiMNrrsDgWQLVd0Il0WwY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=s32iZJ+dlHFOFF9lYr2UsJllOg3tzlx+kD/ITN4rb8bI/z9reEbf0ficAB+fxzwRK GHvuYPBBMrYZ6gpNNnnEcL5pYLvMtqQpHN9191E9zavSaqInCOkF94QasYr5liPy/w rx1zX6Ja5SYwUxt8r/6E0U/grs82VhaZlfOJ061g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id BAEA9387089D for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BAEA9387089D Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 85BF51F45617 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 08/20] elf/dl-open.c: when creating a proxy check the libc_map in NS 0 Date: Tue, 15 Dec 2020 18:44:48 +0000 Message-Id: <20201215184500.25915-9-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The libc_already_loaded check normally considers the libc_map entry in GL(dl_ns)[args->nsid].libc_map. This is not correct for proxies, which use the libc_map from the default namespace (as proxies are dummy entries that point to the base namespace via their l_real members). --- elf/dl-open.c | 1 + 1 file changed, 1 insertion(+) diff --git a/elf/dl-open.c b/elf/dl-open.c index a995e9086f..02e094a867 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -568,6 +568,7 @@ dl_open_worker (void *a) { proxy_ns = args->nsid; args->nsid = LM_ID_BASE; + args->libc_already_loaded = GL(dl_ns)[LM_ID_BASE].libc_map != NULL; } /* It was already open. */ From patchwork Tue Dec 15 18:44:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41416 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB71F38708D4; Tue, 15 Dec 2020 18:45:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB71F38708D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057917; bh=Ey47orljHj9RoT7AsmGngb5Nx07Z2Ndd8fwCvD1puQg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=F1YK9P76KVTcmzJnwRHlolZ9WovqqSnWfy8bG8yisiJGq7YQ+zGENAfmKxBRMV/JF L+wq0Qk5pm1+j0QTwveAc7/g0OWUGZCS/A6tIWZmyjKBxUrxGeGoRDHVGt7T28cY8v DmlY0mTGZrfbOPk0yS/3Hbf0y9Yc7Lsr5WMh1uXY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id B15303870899 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B15303870899 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 940931F45618 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 09/20] Define a new dynamic section tag - DT_GNU_FLAGS_1 Date: Tue, 15 Dec 2020 18:44:49 +0000 Message-Id: <20201215184500.25915-10-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Define a new flags section DT_GNU_FLAGS_1 (no more bits are available in DT_GNU_FLAGS). One flag is currently defined: DF_GNU_1_UNIQUE. libc and its companion DSOs (libpthread et al) should have this section and flag set. --- elf/elf.h | 7 ++++++- elf/get-dynamic-info.h | 12 ++++++++++++ include/elf.h | 2 ++ include/link.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/elf/elf.h b/elf/elf.h index 8e3e618fa1..bd3955ad8c 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -893,6 +893,7 @@ typedef struct Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's approach. */ #define DT_VALRNGLO 0x6ffffd00 +#define DT_GNU_FLAGS_1 0x6ffffdf4 /* Open DSO once across all namespaces */ #define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */ #define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */ #define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */ @@ -907,7 +908,7 @@ typedef struct #define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ #define DT_VALRNGHI 0x6ffffdff #define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */ -#define DT_VALNUM 12 +#define DT_VALNUM 13 /* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the Dyn.d_un.d_ptr field of the Elf*_Dyn structure. @@ -996,6 +997,10 @@ typedef struct #define DF_1_WEAKFILTER 0x20000000 #define DF_1_NOCOMMON 0x40000000 +/* State flags selectable in the `d_un.d_val' element of the DT_GNU_FLAGS_1 + entry in the dynamic section. */ +#define DF_GNU_1_UNIQUE 0x00000001 + /* Flags for the feature selection in DT_FEATURE_1. */ #define DTF_1_PARINIT 0x00000001 #define DTF_1_CONFEXP 0x00000002 diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h index 4f6a86ef37..a489475a94 100644 --- a/elf/get-dynamic-info.h +++ b/elf/get-dynamic-info.h @@ -180,6 +180,18 @@ elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp) if (l->l_flags_1 & DF_1_NOW) info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)]; } + if (info[DT_VALTAGIDX (DT_GNU_FLAGS_1) + + DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM + DT_EXTRANUM] != NULL) + { + l->l_gnu_flags_1 = info[DT_VALTAGIDX (DT_GNU_FLAGS_1) + + DT_NUM + DT_THISPROCNUM + + DT_VERSIONTAGNUM + DT_EXTRANUM]->d_un.d_val; + + if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0) + && l->l_gnu_flags_1 & ~DT_GNU_1_SUPPORTED_MASK) + _dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x in DT_GNU_FLAGS_1.\n", + l->l_gnu_flags_1 & ~DT_GNU_1_SUPPORTED_MASK); + } if (info[DT_RUNPATH] != NULL) /* If both RUNPATH and RPATH are given, the latter is ignored. */ info[DT_RPATH] = NULL; diff --git a/include/elf.h b/include/elf.h index 14ed67ff67..5eee37c294 100644 --- a/include/elf.h +++ b/include/elf.h @@ -25,5 +25,7 @@ (DF_1_NOW | DF_1_NODELETE | DF_1_INITFIRST | DF_1_NOOPEN \ | DF_1_ORIGIN | DF_1_NODEFLIB | DF_1_PIE) +#define DT_GNU_1_SUPPORTED_MASK DF_GNU_1_UNIQUE + #endif /* !_ISOMAC */ #endif /* elf.h */ diff --git a/include/link.h b/include/link.h index 8732f3b5d5..1a4e8e4ab0 100644 --- a/include/link.h +++ b/include/link.h @@ -285,6 +285,7 @@ struct link_map unsigned int l_used; /* Various flag words. */ + ElfW(Word) l_gnu_flags_1; ElfW(Word) l_feature_1; ElfW(Word) l_flags_1; ElfW(Word) l_flags; From patchwork Tue Dec 15 18:44:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41417 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DE2A38708D5; Tue, 15 Dec 2020 18:45:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DE2A38708D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057918; bh=GzPrZ7Wllf8M5KSUTb7utV7ILz90N+Jqrzcte9pMuDw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GZi+Pa/i6Kx3f3vLCyB4tGNPScVQfIMX6t6h5jZ7V7203nR2tZYA5umw2FRYYxQCW BCKI6dF53/CjeroQ83aO7CjqX8tQmR0/Y2DONCnM4i9YHsJBhyXey7BpqARZILldxw 9dz9JXKx4eAuHkruZ6nQf/BHulaEmvvuaMezhAR4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id D3A2138708B2 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D3A2138708B2 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id A178D1F45619 for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 10/20] Abstract the loaded-DSO search code into a private helper function Date: Tue, 15 Dec 2020 18:44:50 +0000 Message-Id: <20201215184500.25915-11-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- elf/dl-load.c | 38 ++++++++++++++++++++++++++++++++++++++ sysdeps/generic/ldsodefs.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/elf/dl-load.c b/elf/dl-load.c index 0c8cb763c1..3fda5de71b 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2038,6 +2038,44 @@ _dl_find_proxy (Lmid_t nsid, const char *name) return NULL; } +/* search for a shared object in a given namespace. */ +struct link_map * +_dl_find_dso (const char *name, Lmid_t nsid) +{ + struct link_map *l; + + for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next) + { + /* If the requested name matches the soname of a loaded object, + use that object. Elide this check for names that have not + yet been opened. */ + if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0)) + continue; + if (!_dl_name_match_p (name, l)) + { + const char *soname; + + if (__glibc_likely (l->l_soname_added) + || l->l_info[DT_SONAME] == NULL) + continue; + + soname = ((const char *) D_PTR (l, l_info[DT_STRTAB]) + + l->l_info[DT_SONAME]->d_un.d_val); + if (strcmp (name, soname) != 0) + continue; + + /* We have a match on a new name -- cache it. */ + add_name_to_object (l, soname); + l->l_soname_added = 1; + } + + /* We have a match. */ + return l; + } + + return NULL; +} + /* Map in the shared object file NAME. */ struct link_map * diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 5411263cc0..13cbe30482 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1239,6 +1239,10 @@ extern void _dl_show_scope (struct link_map *new, int from) extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr); rtld_hidden_proto (_dl_find_dso_for_object) +extern struct link_map *_dl_find_dso (const char *name, Lmid_t nsid); +rtld_hidden_proto (_dl_find_dso) + + /* Initialization which is normally done by the dynamic linker. */ extern void _dl_non_dynamic_init (void) attribute_hidden; From patchwork Tue Dec 15 18:44:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41414 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 943F538708C5; Tue, 15 Dec 2020 18:45:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 943F538708C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057916; bh=FrWAx+aJluUddnd2xw9K+72Bo8dZF7N1s19bYX5bkKI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sLUSF7Fl80VJvkxUCfC5hFsEJgtqN1LXAhR4VtJmw09EV+VP1IQ+H19CLbINq+5I8 PvJd92BuOI0TDEacyfll0uAAteQM3me/KBGqTEEg0ZShdWJmQTIVFjBQGO626iDmYP SV8qUVgO3Y+OwRgNamZZu1qdDvCzlo9ijpzBiChc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by sourceware.org (Postfix) with ESMTPS id B19EE387089C for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B19EE387089C Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id AF4DB1F4561B for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 11/20] Compare loaded DSOs by file ID and check for DF_GNU_1_UNIQUE Date: Tue, 15 Dec 2020 18:44:51 +0000 Message-Id: <20201215184500.25915-12-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. */ From patchwork Tue Dec 15 18:44:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41418 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3F9D38708D8; Tue, 15 Dec 2020 18:45:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3F9D38708D8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057918; bh=SMwdlyqEkrgF5uH4VsdzpHWYFxdRvsAGUKpn2QC1i9U=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=STOkinNy4vvCXxFPCgFdZ0NfHS1Udy3gLp8ELiFGz8gK87Iy821Eov+BnpEliCWRk xNU8k6IFsvh7HqZSkU9c/loiB+dWie+SXl9Al5bvJoSf9fbaMOoa+UM8W1IydrVzae JkkgTm/x2X6cXKiP0dAr9DhK8C4g+9CwJ7sB+BMQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id CE60038708AA for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CE60038708AA Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id BD2D11F4561C for ; Tue, 15 Dec 2020 18:45:08 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 12/20] Use the new DSO finder helper function since we have it Date: Tue, 15 Dec 2020 18:44:52 +0000 Message-Id: <20201215184500.25915-13-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- elf/dl-load.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 0e6a493e07..a31f3771de 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2133,35 +2133,26 @@ _dl_map_object (struct link_map *loader, const char *name, #endif /* Look for this name among those already loaded. */ - for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next) + l = _dl_find_dso (name, nsid); + + if (l != NULL) { - /* If the requested name matches the soname of a loaded object, - use that object. Elide this check for names that have not - yet been opened. */ - if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0)) - continue; - if (!_dl_name_match_p (name, l)) - { - const char *soname; - - if (__glibc_likely (l->l_soname_added) - || l->l_info[DT_SONAME] == NULL) - continue; - - soname = ((const char *) D_PTR (l, l_info[DT_STRTAB]) - + l->l_info[DT_SONAME]->d_un.d_val); - if (strcmp (name, soname) != 0) - continue; - - /* We have a match on a new name -- cache it. */ - add_name_to_object (l, soname); - l->l_soname_added = 1; - } - - /* We have a match. */ +#ifdef SHARED + /* If we are trying to load a DF_GNU_1_UNIQUE flagged DSO which WAS + already opened in the target NS but with RTLD_ISOLATE so it WAS NOT + created as a proxy we need to error out since we cannot satisfy the + DF_GNU_1_UNIQUE is-equivalent-to RTLD_SHARED semantics. */ + if (!(mode & RTLD_ISOLATE) && + (l->l_ns != LM_ID_BASE) && + (l->l_gnu_flags_1 & DF_GNU_1_UNIQUE) && + !l->l_proxy) + { + _dl_signal_error (EEXIST, name, NULL, + N_("object cannot be demoted to a proxy")); + } +#endif return l; } - /* Display information if we are debugging. */ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES) && loader != NULL) From patchwork Tue Dec 15 18:44:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41420 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC62438708E5; Tue, 15 Dec 2020 18:45:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC62438708E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057919; bh=TrynSPXgKmZpqmBWw/fM25VAOOlPk+Ra2daGych0lAk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Pbn4N6gRlXPOXWWWV24cmbbyWQRpcDMpYWabHHTQWeTxUjgqwMG9YkLPbFcYTmjJY yrGM047fqq4Biz83JJmekKPDVXWqTTVkMk28eyKMB5idgBFPxN0qHDsZtBvpprqtrj 9ReHwLC+XY5TwUr1hHdznZ+/RthPk6TLsmZH6XVM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id D62E438708B3 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D62E438708B3 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 0D35A1F4561D for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 13/20] Use the DSO search helper to check for preloaded DT_GNU_UNIQUE DSOs Date: Tue, 15 Dec 2020 18:44:53 +0000 Message-Id: <20201215184500.25915-14-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" If a DSO already exists (with the same name) in the base namespace and it is flagged DT_GNU_UNIQUE then we should behave as if a proxy had been requested. --- elf/dl-open.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/elf/dl-open.c b/elf/dl-open.c index a0f3233dd1..84f27dd1c6 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -484,6 +484,7 @@ dl_open_worker (void *a) const char *file = args->file; int mode = args->mode; struct link_map *call_map = NULL; + struct link_map *preloaded = NULL; int want_proxy = mode & RTLD_SHARED; Lmid_t proxy_ns = LM_ID_BASE; @@ -532,6 +533,23 @@ dl_open_worker (void *a) may not be true if this is a recursive call to dlopen. */ _dl_debug_initialize (0, args->nsid); + /* Target Lmid is not the base and we haven't explicitly asked for a proxy: + We need to check for a matching DSO in the base Lmid in case it is flagged + DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE in which case we add RTLD_SHARED to the + mode and set want_proxy. + NOTE: RTLD_ISOLATE in the mode suppresses this behaviour. */ + if (__glibc_unlikely (args->nsid != LM_ID_BASE) && + __glibc_likely (!want_proxy)) + { + preloaded = _dl_find_dso (file, LM_ID_BASE); + + if (preloaded && (preloaded->l_gnu_flags_1 & DF_GNU_1_UNIQUE)) + { + want_proxy = RTLD_SHARED; + mode |= RTLD_SHARED; + } + } + /* Load the named object. */ struct link_map *new; args->map = new = _dl_map_object (call_map, file, lt_loaded, 0, From patchwork Tue Dec 15 18:44:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41421 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 709BD38708E7; Tue, 15 Dec 2020 18:45:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 709BD38708E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057920; bh=X0qc5IAYK+A1puWCCB0A2LKr/+vWnHugp/tu5YaNOgs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aOnPng37g5F54PllUq5K1F8Q/yg6jwwt8duwWLC7TSJMVgChVCKKAUWF/KRfhOGgx E8JvYZ9rz5KpTUe1XVvclY6iTSJzB8kpGzsT4WmzTZDiq2Ezsm7sAHDFvCYRZ+Lfee JV+CgVusofCsgjvfpb11sHUIC1z0mgWB1h3VrFhI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by sourceware.org (Postfix) with ESMTPS id C20C238708A5 for ; Tue, 15 Dec 2020 18:45:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C20C238708A5 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 201111F4561E for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 14/20] When loading DSOs into alternate namespaces check for DT_GNU_UNIQUE Date: Tue, 15 Dec 2020 18:44:54 +0000 Message-Id: <20201215184500.25915-15-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" If a DSO has not already been loaded and the target is not the main namespace then we must check to see if it's been DT_GNU_UNIQUE tagged and load it into the main namespace instead. dl_open_worker has alread been modified to notice the discrepancy between the request and the result in such cases, and will set up a proxy in the target namespace. --- elf/dl-load.c | 96 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 14 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index a31f3771de..68587831fd 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -837,6 +837,62 @@ _dl_init_paths (const char *llp, const char *source, __rtld_env_path_list.dirs = (void *) -1; } +static ElfW(Word) +_has_gnu_unique (int fd, const ElfW(Ehdr) *header, const ElfW(Phdr) *phdr) +{ + int unique = 0; + const ElfW(Phdr) *ph; + ElfW(Dyn) entry = {}; + off_t reset; + off_t pos; + off_t end; + + reset = __lseek (fd, 0, SEEK_CUR); + + for (ph = phdr; ph < &phdr[header->e_phnum]; ++ph) + { + switch (ph->p_type) + { + case PT_DYNAMIC: + pos = __lseek (fd, ph->p_offset, SEEK_SET); + end = pos + ph->p_filesz; + + while (pos < end) + { + ssize_t rb = 0; + do + { + ssize_t rretl = __read_nocancel (fd, &entry + rb, + sizeof (ElfW(Dyn)) - rb); + if (rretl <= 0) + goto cleanup; + + rb += rretl; + } + while (__glibc_unlikely (rb < sizeof (ElfW(Dyn)))); + + switch (entry.d_tag) + { + case DT_GNU_FLAGS_1: + unique = entry.d_un.d_val & DF_GNU_1_UNIQUE; + case DT_NULL: + goto cleanup; + break; + default: + break; + } + pos += rb; + } + break; + } + } + + cleanup: + /* Put the file descriptor offset back where it was when we were called. */ + __lseek (fd, reset, SEEK_SET); + + return unique; +} /* Process PT_GNU_PROPERTY program header PH in module L after PT_LOAD segments are mapped. Only one NT_GNU_PROPERTY_TYPE_0 @@ -1098,6 +1154,32 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, else assert (r->r_state == RT_ADD); + /* Load the ELF header using preallocated struct space if it's big enough. */ + maplength = header->e_phnum * sizeof (ElfW(Phdr)); + if (header->e_phoff + maplength <= (size_t) fbp->len) + phdr = (void *) (fbp->buf + header->e_phoff); + else + { + phdr = alloca (maplength); + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, + header->e_phoff) != maplength) + { + errstring = N_("cannot read file data"); + goto lose_errno; + } + } + + /* 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) + { + /* 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 + the target nsid. */ + if (_has_gnu_unique (fd, header, phdr)) + nsid = LM_ID_BASE; + } + /* Enter the new object in the list of loaded objects. */ l = _dl_new_object (realname, name, l_type, loader, mode, nsid); if (__glibc_unlikely (l == NULL)) @@ -1115,20 +1197,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, type = header->e_type; l->l_phnum = header->e_phnum; - maplength = header->e_phnum * sizeof (ElfW(Phdr)); - if (header->e_phoff + maplength <= (size_t) fbp->len) - phdr = (void *) (fbp->buf + header->e_phoff); - else - { - phdr = alloca (maplength); - if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, - header->e_phoff) != maplength) - { - errstring = N_("cannot read file data"); - goto lose_errno; - } - } - /* On most platforms presume that PT_GNU_STACK is absent and the stack is * executable. Other platforms default to a nonexecutable stack and don't * need PT_GNU_STACK to do so. */ From patchwork Tue Dec 15 18:44:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41422 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A2BF38708C2; Tue, 15 Dec 2020 18:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A2BF38708C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057922; bh=JCjqhkb7Mg2ruCT/zpjmvbd0XfWMWTdboQbdyWS/4XQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iMXslbB/zTn97eOIIY7mCHPoKBZssYCocf42aGoWQ6WjkkyJwP7XHa3/czXGoptbA EzRMJC6fRf7m9l76aRB+ULJNS8cUNH4sIj2gIsNMec+3rBF1XrN5xE7LmwtR6ARr5i 9iXVGIWpRJJgfp+chkxu9pHBFo8b6GCtWjl/IXP0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 8DBF438708B4 for ; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8DBF438708B4 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 306901F4561F for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 15/20] Suppress audit calls when a (new) namespace is empty Date: Tue, 15 Dec 2020 18:44:55 +0000 Message-Id: <20201215184500.25915-16-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" When preparing an RTLD_SHARED proxy in a new namespace it is possible for the target namespace to be empty: This can happen for RTLD_SHARED + LM_ID_NEWLM. The audit infrastructure should not be invoked at this point (as there's nothing there to audit yet). --- elf/dl-load.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 68587831fd..9bd4884a88 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1127,8 +1127,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, && __glibc_unlikely (GLRO(dl_naudit) > 0)) { struct link_map *head = GL(dl_ns)[nsid]._ns_loaded; - /* Do not call the functions for any auditing object. */ - if (head->l_auditing == 0) + /* Do not call the functions for any auditing object. + Do not try to call auditing functions if the namespace + is currently empty. This can hapen when opening the first + DSO in a new namespace. */ + if (head && head->l_auditing == 0) { struct audit_ifaces *afct = GLRO(dl_audit); for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) From patchwork Tue Dec 15 18:44:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41426 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B572538708FA; Tue, 15 Dec 2020 18:45:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B572538708FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057923; bh=QU11sgotS3DnlXfM242kUaM4+Jya7THFefoFmqlMNSY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Zl3TtA2CLL6X+RZPH7w+o06/ePjQrSNC2CFm64GRe5yuOTzC+K9FljQFGmDkcHRpB Kn+5RIz88nt6/11V0fKw5GMO9yLd+7wcye5t/peDjNKrT2QmaiMvGEFR2Xq1op9KTo zQa80GzvIq1wWnSaYt2hBq52GWcjkUoAIo1scyK4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 8A82B38708AD for ; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8A82B38708AD Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 3ECA01F45620 for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 16/20] Suppress inter-namespace DSO sharing for audit libraries Date: Tue, 15 Dec 2020 18:44:56 +0000 Message-Id: <20201215184500.25915-17-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. */ From patchwork Tue Dec 15 18:44:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41423 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C22738708EC; Tue, 15 Dec 2020 18:45:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C22738708EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057921; bh=/yTgZfzyu3Bci74gxNOAUNrYymX4DGueK8qGLLp41Cs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YPo3dK9HE5+H59OiceeHAQpNbuOiveI2e7eH2znzHo6dOQWHKfS7Oy7O80TtV7Fak 4DH7wCM+CMl+8DpNSEpn06oCeczFz5a3LBiWRAGntW/krqxDCqiWjjvyJTyJsEZX++ 5xpGbzu8bbdYoxE527TAkrZWSY14NQ2/YzecKUsk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by sourceware.org (Postfix) with ESMTPS id 88604387089D for ; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 88604387089D Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 519911F45621 for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 17/20] dlsym, dlvsym should be able to look up symbols via DSO proxies Date: Tue, 15 Dec 2020 18:44:57 +0000 Message-Id: <20201215184500.25915-18-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" --- elf/dl-sym.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/elf/dl-sym.c b/elf/dl-sym.c index 361b926ea9..4abd7eb3b4 100644 --- a/elf/dl-sym.c +++ b/elf/dl-sym.c @@ -96,6 +96,10 @@ do_sym (void *handle, const char *name, void *who, { match = _dl_sym_find_caller_link_map (caller); + /* Proxies don't contain any symbols: Need to look at the real DSO. */ + if (__glibc_unlikely (match->l_proxy)) + match = match->l_real; + /* Search the global scope. We have the simple case where we look up in the scope of an object which was part of the initial binary. And then the more complex part @@ -140,6 +144,11 @@ RTLD_NEXT used in code not dynamically loaded")); } struct link_map *l = match; + + /* Proxies don't contain any symbols: Need to look at the real DSO. */ + if (__glibc_unlikely (l->l_proxy)) + l = l->l_real; + while (l->l_loader != NULL) l = l->l_loader; @@ -150,6 +159,11 @@ RTLD_NEXT used in code not dynamically loaded")); { /* Search the scope of the given object. */ struct link_map *map = handle; + + /* Proxies don't contain any symbols: Need to look at the real DSO. */ + if (__glibc_unlikely (map->l_proxy)) + map = map->l_real; + result = GLRO(dl_lookup_symbol_x) (name, map, &ref, map->l_local_scope, vers, 0, flags, NULL); } From patchwork Tue Dec 15 18:44:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41424 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D8F638708F1; Tue, 15 Dec 2020 18:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D8F638708F1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057922; bh=rYBTjWuTBh8hdFlIvKkt/mh8ts1gxbdOW1r5KqNGFjs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FjhLymNuSwcFmz/T5rBUseWRu8VDu4xwe1KyWMc+JZUrmJDXQojA+Lh0oy7/jq9dn 6Z+G766dw+TzrmuUNBs6cJH6r/O7FRjrYoJoucS6GGPYSwIo/TPToDHdlEW+OC7qrP s0bPzkLMLAP8BGR+lwrLSwK303rNa9trHSRl9HCY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id 97EAE38708C0 for ; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 97EAE38708C0 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5F7AD1F45622 for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 18/20] Add DT_GNU_FLAGS_1/DF_GNU_1_UNIQUE dynamic section+flag to glibc DSOs Date: Tue, 15 Dec 2020 18:44:58 +0000 Message-Id: <20201215184500.25915-19-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" libc.so, libpthread.so etc should have the new unique-dso-by-default flag set to allow dlmopen to work better (libc et al instance shared by default when DSOs dlmopened into a new namespace). --- Makeconfig | 1 + Makerules | 2 +- iconvdata/Makefile | 1 + nptl/Makefile | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makeconfig b/Makeconfig index 8074613b85..6ed137e2a3 100644 --- a/Makeconfig +++ b/Makeconfig @@ -398,6 +398,7 @@ LDFLAGS-lib.so += -Wl,-z,now # Extra flags for dynamically linked non-test main programs. link-extra-flags += -Wl,-z,now endif +LDFLAGS-lib.so += -Wl,-z,unique # Command to run after every final link (executable or shared object). # This is invoked with $(call after-link,...), so it should operate on diff --git a/Makerules b/Makerules index ef0fe67d9a..ffb4f74de0 100644 --- a/Makerules +++ b/Makerules @@ -635,7 +635,7 @@ build-shlib-objlist = $(build-module-helper-objlist) \ # Don't try to use -lc when making libc.so itself. # Also omits crti.o and crtn.o, which we do not want # since we define our own `.init' section specially. -LDFLAGS-c.so = -nostdlib -nostartfiles +LDFLAGS-c.so = -nostdlib -nostartfiles -Wl,-z,unique # But we still want to link libc.so against $(libc.so-gnulib). LDLIBS-c.so += $(libc.so-gnulib) # Give libc.so an entry point and make it directly runnable itself. diff --git a/iconvdata/Makefile b/iconvdata/Makefile index 4ec2741cdc..121808a8fe 100644 --- a/iconvdata/Makefile +++ b/iconvdata/Makefile @@ -67,6 +67,7 @@ modules := ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 \ ifeq ($(bind-now),yes) LDFLAGS.so += -Wl,-z,now endif +LDFLAGS.so += -Wl,-z,unique modules.so := $(addsuffix .so, $(modules)) diff --git a/nptl/Makefile b/nptl/Makefile index ddd83dfbdd..314931cbaa 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -354,7 +354,7 @@ else tests-printers-libs := $(static-thread-library) endif -LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst +LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,unique,-z,nodelete,-z,initfirst tests += tst-cancelx7 tst-cancelx17 tst-cleanupx4 From patchwork Tue Dec 15 18:45:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 41425 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2DA7B38708F7; Tue, 15 Dec 2020 18:45:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DA7B38708F7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608057923; bh=FGKqbT9p6chC1dW9R0k9BxNSg7eJdmTqg75kjK46IiQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=C/hy6HCDGBohZFFL7G6x45PC9StuUxJPmyEDNTFeLIti+R9aq7sDNThrQYSVfXQP7 lbWYeveGlW9HouVD8TBC17GJ5BJtf6122BupgR6jPPDVQ3kdkb4OMAug5KE3gQuKn8 Vgp9rIzW5WetWyNGHd5NEiCG/qc3E13GpsKdt17w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by sourceware.org (Postfix) with ESMTPS id AD11538708C1 for ; Tue, 15 Dec 2020 18:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AD11538708C1 Received: from noise.cbg.collabora.co.uk (unknown [IPv6:2001:4d48:ad5c:ef00:8e70:5aff:fe59:c29c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 9C8611F45624 for ; Tue, 15 Dec 2020 18:45:09 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v6 20/20] Restore separate libc loading for the TLS/namespace storage test Date: Tue, 15 Dec 2020 18:45:00 +0000 Message-Id: <20201215184500.25915-21-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201215184500.25915-1-vivek@collabora.com> References: <20201215184500.25915-1-vivek@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= From: Vivek Dasmohapatra Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" tst-tls-ie-dlmopen checks to see that new namespaces consume TLS memory as expected: This does not happen when new namespaces share the same libc instance (since TLS is allocated only when a new libc instance insitialises its threading infrastructure). Adding RTLD_ISOLATE to the dlmopen flags in the test restores the old behaviour which allows the test to check what it actually needs to. --- elf/tst-tls-ie-dlmopen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elf/tst-tls-ie-dlmopen.c b/elf/tst-tls-ie-dlmopen.c index c7b5c688e3..8ba24ce54d 100644 --- a/elf/tst-tls-ie-dlmopen.c +++ b/elf/tst-tls-ie-dlmopen.c @@ -53,7 +53,7 @@ static void * load_and_access (Lmid_t lmid, const char *mod, const char *func) { /* Load module with TLS. */ - void *p = xdlmopen (lmid, mod, RTLD_NOW); + void *p = xdlmopen (lmid, mod, RTLD_NOW|RTLD_ISOLATE); /* Access the TLS variable to ensure it is allocated. */ void (*f) (void) = (void (*) (void))xdlsym (p, func); f (); @@ -95,7 +95,7 @@ do_test (void) than 1024 bytes are available (exact number depends on TLS optimizations and the libc TLS use). */ printf ("The next dlmopen should fail...\n"); - void *p = dlmopen (LM_ID_BASE, "tst-tls-ie-mod4.so", RTLD_NOW); + void *p = dlmopen (LM_ID_BASE, "tst-tls-ie-mod4.so", RTLD_NOW|RTLD_ISOLATE); if (p != NULL) FAIL_EXIT1 ("error: expected dlmopen to fail because there is " "not enough surplus static TLS.\n");