From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BCAF23858D33 for ; Mon, 2 May 2022 08:41:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BCAF23858D33 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-5-sqDdwAN8K0YzTlndO2GA-1; Mon, 02 May 2022 04:41:00 -0400 X-MC-Unique: 5-sqDdwAN8K0YzTlndO2GA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6525D85A5A8; Mon, 2 May 2022 08:41:00 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A8E714C1D7C; Mon, 2 May 2022 08:40:59 +0000 (UTC) From: Florian Weimer To: Fangrui Song Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] elf: Simplify version test when searching a versioned symbol References: <20220501074619.1744068-1-maskray@google.com> <20220501075609.wi3bydt7h27vj6sr@google.com> Date: Mon, 02 May 2022 10:40:57 +0200 In-Reply-To: <20220501075609.wi3bydt7h27vj6sr@google.com> (Fangrui Song's message of "Sun, 1 May 2022 00:56:09 -0700") Message-ID: <8735hs8gyu.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 02 May 2022 08:41:06 -0000 * Fangrui Song: > On 2022-05-01, Fangrui Song wrote: >>--- >> elf/dl-lookup.c | 12 ++++++------ >> 1 file changed, 6 insertions(+), 6 deletions(-) >> >>diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c >>index 989b073e4f..3ad6c95d79 100644 >>--- a/elf/dl-lookup.c >>+++ b/elf/dl-lookup.c >>@@ -110,14 +110,14 @@ check_match (const char *const undef_name, >> } >> else >> { >>- /* We can match the version information or use the >>- default one if it is not hidden. */ >>- ElfW(Half) ndx = verstab[symidx] & 0x7fff; >>+ /* When the version does not match, allow VER_NDX_GLOBAL fallback when >>+ resolving relocations (version->hidden==0). Don't bother with the >>+ check done by the linker: VER_NDX_GLOBAL symbol cannot be hidden. >>+ */ >>+ ElfW (Half) ndx = verstab[symidx] & 0x7fff; >> if ((map->l_versions[ndx].hash != version->hash >> || strcmp (map->l_versions[ndx].name, version->name)) >>- && (version->hidden || map->l_versions[ndx].hash >>- || (verstab[symidx] & 0x8000))) >>- /* It's not the version we want. */ >>+ && (version->hidden || ndx != VER_NDX_GLOBAL)) >> return NULL; >> } >> } >> -- 2.36.0.464.gb9c8b46e94-goog > > The existing code has a bug. > > If a has foo@v1 referencing b.so. If I rebuild b.so and change foo@v1 to > foo VER_NDX_GLOBAL, > > `strcmp (map->l_versions[ndx].name, version->name)` may trigger a null > pointer dereference: > > (rr) p map->l_versions[1] > $7 = {name = 0x0, hash = 0, hidden = 0, filename = 0x0} > > This can be fixed with `!map->l_versions[ndx].name || strcmp (map->l_versions[ndx].name, version->name)` Hmm. How do we handle VER_NDX_GLOBAL in the dynamic linker? The if branch has an assert. I think it fires if we drop symbol versioning completely. I think we should report a proper error for that. Should the switch to VER_NDX_GLOBAL also result in an error (eventually)? Thanks, Florian