From patchwork Wed Dec 16 13:26: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: 41455 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 AD5D33875449; Wed, 16 Dec 2020 13:27:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD5D33875449 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608125278; 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=iajTmTY2kEre/4i2QFzG9DLg2QswQAYtOl/ig/OO6cLWG9HFFYQv77k1Fa1LF5b6q f6vFGN7JJgQ3EBCtYcHesyw+6NOmHn48YzIV25drPxKlU0/xCmau9SgLKPtYHEqkBf GAywmNDXvJI8mvksoAtrYpKi1TxU/ploXlpIQ8tQ= 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 DF02E386F43B for ; Wed, 16 Dec 2020 13:27:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DF02E386F43B 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 809B11F4569B for ; Wed, 16 Dec 2020 13:27:46 +0000 (GMT) To: libc-alpha Subject: [RFC][PATCH v7 13/20] Use the DSO search helper to check for preloaded DT_GNU_UNIQUE DSOs Date: Wed, 16 Dec 2020 13:26:43 +0000 Message-Id: <20201216132650.22949-14-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201216132650.22949-1-vivek@collabora.com> References: <20201216132650.22949-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,