From patchwork Wed Jun 17 14:00:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Dasmohapatra X-Patchwork-Id: 39658 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 238273898520; Wed, 17 Jun 2020 14:00:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 238273898520 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592402445; bh=dqTPntQKhvmrp6rRVOxriDmZ5lTk7kIdCpAMJESCXzM=; 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=NNFDw88Yz0GevAFix6xWnu/vItv8T6IgKrqGKfs8RA2NogSlsjjZGuL5C+8A+rnUl pOkJWdaprQpaiDnh1/Hh1rpKRI+udkJK2YQgcoKki0ncVSGa2cU4RbRIzKISdXS0MV AhJH6FOQDRuVsLLFAAmN/pdQ3TJUwH8OwRNPrfRE= 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 AB48B389366A for ; Wed, 17 Jun 2020 14:00:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AB48B389366A Received: from noise.collabora.co.uk (unknown [IPv6:2001:4d48:ad56:3000:88ff:22ff:81f3:30c8]) (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 86AC12A3FC6 for ; Wed, 17 Jun 2020 15:00:35 +0100 (BST) To: libc-alpha@sourceware.org Subject: [RFC][PATCH v5 11/16] Use the DSO search helper to check for preloaded DT_GNU_UNIQUE DSOs Date: Wed, 17 Jun 2020 15:00:19 +0100 Message-Id: <20200617140024.12777-12-vivek@collabora.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200617140024.12777-1-vivek@collabora.com> References: <20200617140024.12777-1-vivek@collabora.com> X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, 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-load.c | 2 +- elf/dl-open.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 62820167d5..66848f8434 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -950,7 +950,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, 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_flags_1 & DF_1_UNIQUE)) + if (l->l_info[VALIDX (DT_GNU_UNIQUE)] == NULL) continue; /* Already loaded. Bump its reference count and return it. */ diff --git a/elf/dl-open.c b/elf/dl-open.c index 75dc3893d3..43597a510e 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -476,6 +476,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; @@ -519,6 +520,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_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_info[VALIDX (DT_GNU_UNIQUE)] != NULL)) + { + 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, @@ -548,7 +566,7 @@ dl_open_worker (void *a) return; } - /* If we were trying to load a DF_1_UNIQUE flagged DSO which was NOT + /* If we were trying to load a DT_GNU_UNIQUE flagged DSO which was NOT ALREADY LOADED (or not loaded with the name we are using) then _dl_map_object will return an instance from the main namespace. We need to detect this and set up the RTLD_SHARED flags. */