[RFC,v8,07/20] elf/dl-open.c: Don't try libc linit in namespaces with no libc mapping
Message ID | 20210209171839.7911-8-vivek@collabora.com |
---|---|
State | Superseded |
Delegated to: | Adhemerval Zanella Netto |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> 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 813A83850438; Tue, 9 Feb 2021 17:18:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 813A83850438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1612891134; bh=u6ZDA9SMvnPI6AFemZcEJGfUzxPUIi9LxEa9Y9PEbzA=; 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=enY1L9vnm+qgKMQV49YOm1ZRT17ar73jW1QqGHcbDKgyXNwfOkRQd9PBCEpIxMZ11 lX5/aZZXNjQkPxJkOHhBsHbTturhXQ24adHR9o12GU1F9YSCu2t2UigJ53w+nB7mB0 9c2KPmHuGxqibdV8WTAJRo7pdJKlkq12XUExWjxU= 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 0221B385781F for <libc-alpha@sourceware.org>; Tue, 9 Feb 2021 17:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0221B385781F Received: from noise.lan (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 2F1A51F451DB for <libc-alpha@sourceware.org>; Tue, 9 Feb 2021 17:18:46 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [RFC][PATCH v8 07/20] elf/dl-open.c: Don't try libc linit in namespaces with no libc mapping Date: Tue, 9 Feb 2021 17:18:26 +0000 Message-Id: <20210209171839.7911-8-vivek@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210209171839.7911-1-vivek@collabora.com> References: <20210209171839.7911-1-vivek@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: =?utf-8?q?Vivek_Das=C2=A0Mohapatra_via_Libc-alpha?= <libc-alpha@sourceware.org> Reply-To: =?utf-8?q?Vivek_Das=C2=A0Mohapatra?= <vivek@collabora.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
Implementation of RTLD_SHARED for dlmopen
|
|
Commit Message
Vivek Dasmohapatra
Feb. 9, 2021, 5:18 p.m. UTC
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(-)
Comments
On 09/02/2021 14:18, Vivek Das Mohapatra via Libc-alpha wrote: > 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 4cb90bfe19..dc4b386559 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); No implicit checks. > #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 > Ok.
>> #ifdef SHARED >> - bool initial = libc_map->l_ns == LM_ID_BASE; >> + bool initial = libc_map && (libc_map->l_real->l_ns == LM_ID_BASE); > > No implicit checks. Sorry - It's not clear to me what change you want here.
On 17/02/2021 12:39, Vivek Das Mohapatra wrote: >>> #ifdef SHARED >>> - bool initial = libc_map->l_ns == LM_ID_BASE; >>> + bool initial = libc_map && (libc_map->l_real->l_ns == LM_ID_BASE); >> >> No implicit checks. > > Sorry - It's not clear to me what change you want here. The libc_map is a pointer here, so: bool initial = libc_map != NULL && libc_map->l_real->l_ns == LM_ID_BASE; (is libc_map->l_real always valid here btw?)
> The libc_map is a pointer here, so: > > bool initial = libc_map != NULL && libc_map->l_real->l_ns == LM_ID_BASE; Ah, got it. Will do, > (is libc_map->l_real always valid here btw?) Yes: _dl_new_object assigns it immediately after calloc'ing the link map entry struct. _dl_new_proxy does similar and the only other case is ld.so itself which also has l_real assigned early. _dl_init asserts that ->l_real-><something> is non NULL too so the assumption that l_real is dereferencable is pretty widespread and fundamental.
On 17/02/2021 15:32, Vivek Das Mohapatra wrote: >> The libc_map is a pointer here, so: >> >> bool initial = libc_map != NULL && libc_map->l_real->l_ns == LM_ID_BASE; > > Ah, got it. Will do, Thanks, I will try to finish the set review by the end of the week. > >> (is libc_map->l_real always valid here btw?) > > Yes: _dl_new_object assigns it immediately after calloc'ing the > link map entry struct. _dl_new_proxy does similar and the only > other case is ld.so itself which also has l_real assigned > early. > > _dl_init asserts that ->l_real-><something> is non NULL too > so the assumption that l_real is dereferencable is pretty > widespread and fundamental. > Ack.
diff --git a/elf/dl-open.c b/elf/dl-open.c index 4cb90bfe19..dc4b386559 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