From patchwork Tue Jul 4 12:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1803194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=OqYeGkm8; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QwMwy4TNPz20ZC for ; Tue, 4 Jul 2023 22:46:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95B87385734F for ; Tue, 4 Jul 2023 12:46:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95B87385734F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688474784; bh=dLAfXylFiCKcHDvbQ3+qqlx+NYdv6Fa6MkbPqYLms+g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OqYeGkm8/G4nQpoi76J85/tkXj+lZV6AZfZzPpxlmpnmAz82nT9eS8XXuW8k0nuvj /YUFK1+wOH27wXTDBOCie1pl4zl7t0AwptWJBueZkoHYN8CmB6uoLnaXiC/6X8ysYs nhPRGKU2VpmV0TZW2pO+P1skWJd8CKh5TQNutIGI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 13D17385773C for ; Tue, 4 Jul 2023 12:46:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 13D17385773C 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-586-45bpzikDO5qGqOCQgK9vFQ-1; Tue, 04 Jul 2023 08:46:08 -0400 X-MC-Unique: 45bpzikDO5qGqOCQgK9vFQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80E8481DA5D for ; Tue, 4 Jul 2023 12:46:08 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1704D492C13 for ; Tue, 4 Jul 2023 12:46:07 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v2] elf: _dl_find_object may return 1 during early startup (bug 30515) Date: Tue, 04 Jul 2023 14:46:06 +0200 Message-ID: <874jmj6e0h.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Success is reported with a 0 return value, and failure is -1. Enhance the kitchen sink test elf/tst-audit28 to cover _dl_find_object as well. Fixes commit 5d28a8962dcb ("elf: Add _dl_find_object function") and bug 30515. --- v2: Support --enable-hardcoded-path-in-tests. elf/dl-find_object.c | 2 +- elf/tst-auditmod28.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) base-commit: 2eddd1bf3e562e6e1b19e1f07af8ec19c0445d23 diff --git a/elf/dl-find_object.c b/elf/dl-find_object.c index 928eb499cc..c1390ee10f 100644 --- a/elf/dl-find_object.c +++ b/elf/dl-find_object.c @@ -46,7 +46,7 @@ _dl_find_object_slow (void *pc, struct dl_find_object *result) struct dl_find_object_internal internal; _dl_find_object_from_map (l, &internal); _dl_find_object_to_external (&internal, result); - return 1; + return 0; } /* Object not found. */ diff --git a/elf/tst-auditmod28.c b/elf/tst-auditmod28.c index f6ab991398..f6dfbbe202 100644 --- a/elf/tst-auditmod28.c +++ b/elf/tst-auditmod28.c @@ -71,6 +71,17 @@ la_version (unsigned int current) TEST_VERIFY (dladdr1 (&_exit, &info, &extra_info, RTLD_DL_LINKMAP) != 0); TEST_VERIFY (extra_info == handle); + /* Check _dl_find_object. */ + struct dl_find_object dlfo; + TEST_COMPARE (_dl_find_object (__builtin_return_address (0), &dlfo), 0); + /* "ld.so" is seen with --enable-hardcoded-path-in-tests. */ + if (strcmp (basename (dlfo.dlfo_link_map->l_name), "ld.so") != 0) + TEST_COMPARE_STRING (basename (dlfo.dlfo_link_map->l_name), LD_SO); + TEST_COMPARE (_dl_find_object (dlsym (handle, "environ"), &dlfo), 0); + TEST_COMPARE_STRING (basename (dlfo.dlfo_link_map->l_name), LIBC_SO); + TEST_COMPARE (_dl_find_object ((void *) 1, &dlfo), -1); + TEST_COMPARE (_dl_find_object ((void *) -1, &dlfo), -1); + /* Verify that dlmopen creates a new namespace. */ void *dlmopen_handle = xdlmopen (LM_ID_NEWLM, LIBC_SO, RTLD_NOW); TEST_VERIFY (dlmopen_handle != handle);