From patchwork Thu Aug 8 16:40:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1970650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HSQOa3Jt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wft9646NBz1yf8 for ; Fri, 9 Aug 2024 02:41:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BCC0A3858420 for ; Thu, 8 Aug 2024 16:41:28 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTP id 88AED3858433 for ; Thu, 8 Aug 2024 16:41:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88AED3858433 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 88AED3858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723135269; cv=none; b=XYFMT770wf04064xYKmsiNr6gE9v+KOOEHYxGlkbUY/jwkIk+1WJL5PyZ3lpIbxO7zj1bUL61zlHHl+bbS0z7tg+111mBOxGaQcyxAp+6bMxZlTtwRZyopZtpAYRhk7ScF4JY5RfT/66F1Gh2KLll4lRqtYev5qtvYIWbLuTyO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723135269; c=relaxed/simple; bh=ichPzx0E8L5biEZnD54uRn00KYmfEUaKMBwm/q3Xk/Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Pw8tsquLvji6Ac1kFtr5GVuWUqHDZTmexH1eLXvIveIbmNfMJT+OpLj40e9Gz+j+Z+aeK/8/yvlnxzR3BoJbwIYXm1WFsYeZR8Vqhq7oUzEcMyvUuB0SMeDDSE7W76V7LYRJiiME+wplFAEy4wag0eiPHP/mWpqYZaV1yoGadHU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723135264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Qg56jNT/XU+eMg2LdPcDtwTUedzWJoc86Bkp+q5pdq0=; b=HSQOa3Jttua1O9l4lM3dH7bwn8OTvP5sW1/dzS9UvXfone3UwEQroSzAIDzpZZ0P3kxD5H bgrpB86r0McG42Ur+2rWf3tweuIWG7y7ESROBalP96T+xmSEuoMb2nlpT15J41qEOO6pi7 un3/r+UHr9trO6UGIae9AfF0UzPzckg= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-RzrcBT-dM0Cj60ejlvqo6g-1; Thu, 08 Aug 2024 12:41:03 -0400 X-MC-Unique: RzrcBT-dM0Cj60ejlvqo6g-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1F1B819772F0 for ; Thu, 8 Aug 2024 16:41:02 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.45.224.76]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2E68A19560AA for ; Thu, 8 Aug 2024 16:41:00 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] dlfcn: dlinfo (RTLD_DI_PHDR) should work for proxy link maps (bug 32060) Date: Thu, 08 Aug 2024 18:40:58 +0200 Message-ID: <87a5hnm0h1.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Previously, 0 was returned as the program header address. --- dlfcn/dlinfo.c | 3 +++ dlfcn/tst-dlinfo-phdr.c | 72 ++++++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 27 deletions(-) base-commit: a0ecbb45969e93ec5eb6ba0d1f0a5578bdb2e54c diff --git a/dlfcn/dlinfo.c b/dlfcn/dlinfo.c index b0feb9362d..1979ba3356 100644 --- a/dlfcn/dlinfo.c +++ b/dlfcn/dlinfo.c @@ -40,6 +40,9 @@ dlinfo_doit (void *argsblock) struct dlinfo_args *const args = argsblock; struct link_map *l = args->handle; + /* Support proxy maps (although they are never returned by dlopen). */ + l = l->l_real; + switch (args->request) { case RTLD_DI_CONFIGADDR: diff --git a/dlfcn/tst-dlinfo-phdr.c b/dlfcn/tst-dlinfo-phdr.c index fdffb17724..43deb4c6d5 100644 --- a/dlfcn/tst-dlinfo-phdr.c +++ b/dlfcn/tst-dlinfo-phdr.c @@ -17,6 +17,7 @@ . */ #include +#include #include #include #include @@ -54,6 +55,42 @@ dlip_callback (struct dl_phdr_info *dlpi, size_t size, void *closure) return 0; } +/* Set by basic_checks. */ +static const ElfW(Phdr) *phdr; +static int phnum; + +/* Basic checks that can be used regardless of namespace. */ +static void +basic_checks (struct link_map *l) +{ + printf ("info: checking link map %p (%p) for \"%s\"\n", + l, l->l_phdr, l->l_name); + + /* Cause dlerror () to return an error message. */ + dlsym (RTLD_DEFAULT, "does-not-exist"); + + /* Use the extension that link maps are valid dlopen handles. */ + phnum = dlinfo (l, RTLD_DI_PHDR, &phdr); + TEST_VERIFY (phnum >= 0); + /* Verify that the error message has been cleared. */ + TEST_COMPARE_STRING (dlerror (), NULL); + + TEST_VERIFY (phdr == l->l_real->l_phdr); + TEST_COMPARE (phnum, l->l_real->l_phnum); + + /* Check that we can find PT_DYNAMIC among the array. */ + { + bool dynamic_found = false; + for (int i = 0; i < phnum; ++i) + if (phdr[i].p_type == PT_DYNAMIC) + { + dynamic_found = true; + TEST_COMPARE ((ElfW(Addr)) l->l_ld, l->l_addr + phdr[i].p_vaddr); + } + TEST_VERIFY (dynamic_found); + } +} + static int do_test (void) { @@ -64,33 +101,7 @@ do_test (void) do { - printf ("info: checking link map %p (%p) for \"%s\"\n", - l, l->l_phdr, l->l_name); - - /* Cause dlerror () to return an error message. */ - dlsym (RTLD_DEFAULT, "does-not-exist"); - - /* Use the extension that link maps are valid dlopen handles. */ - const ElfW(Phdr) *phdr; - int phnum = dlinfo (l, RTLD_DI_PHDR, &phdr); - TEST_VERIFY (phnum >= 0); - /* Verify that the error message has been cleared. */ - TEST_COMPARE_STRING (dlerror (), NULL); - - TEST_VERIFY (phdr == l->l_phdr); - TEST_COMPARE (phnum, l->l_phnum); - - /* Check that we can find PT_DYNAMIC among the array. */ - { - bool dynamic_found = false; - for (int i = 0; i < phnum; ++i) - if (phdr[i].p_type == PT_DYNAMIC) - { - dynamic_found = true; - TEST_COMPARE ((ElfW(Addr)) l->l_ld, l->l_addr + phdr[i].p_vaddr); - } - TEST_VERIFY (dynamic_found); - } + basic_checks (l); /* Check that dl_iterate_phdr finds the link map with the same program headers. */ @@ -119,6 +130,13 @@ do_test (void) } while (l != NULL); + /* The secondary namespace does not contain the main executable, and + dl_iterate_phdr does not cover it. */ + struct link_map *secondary_libc = xdlmopen (LM_ID_NEWLM, LIBC_SO, RTLD_NOW); + for (l = secondary_libc; l != NULL; l = l->l_next) + basic_checks (l); + xdlclose (secondary_libc); + return 0; }