From patchwork Mon Aug 12 14:32:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1145750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104315-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="DGwzKmeg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 466dcH48h7z9sN1 for ; Tue, 13 Aug 2019 00:33:03 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type; q=dns; s=default; b=mRPrXe77QmV6AjhU fmYLQUDKyyH08v0CvymTlPVT4iQwJd6inPF6arPTU9+wat5SHY3Scka4Qh65ZDlJ 8wTET7BEXfPjvEq8uP946fRZoRztytpMvJBymADwnzJzreh+DZiqfcSQW44pZA0O hrGhpQJ4Vmg60rFLFdaNf0uUs0k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-type; s=default; bh=lDmsh3IjjdIz48RA5BnObv fXzUI=; b=DGwzKmeg+TiFtTQ/hsFt4yO53vKwumAyg0rnv5r9JYjMrVml6qV5kz 7kXU1lfK1G0sNWYdY7mU7DYO3bP0o6kO64V6OJk2/v686tu1GDhr3ozOxL7H+yYh LqZcpalgOiyL8gka8SAfQDgR/CPeqmw9ZlZf54V05G1zsQ3Ehm1vE= Received: (qmail 122144 invoked by alias); 12 Aug 2019 14:32:57 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 122136 invoked by uid 89); 12 Aug 2019 14:32:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=binaries, thr, puts X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Cc: Paul Pluzhnikov Subject: [PATCH] elf: Support elf/tst-dlopen-aout in more configurations Date: Mon, 12 Aug 2019 16:32:52 +0200 Message-ID: <87blwuo3mz.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 dlopen can no longer open PIE binaries, so it is not necessary to link the executable as non-PIE to trigger a dlopen failure. If we hard-code the path to the real executable, we can run the test with and without hard-coded paths because the dlopen path will not be recognized as the main program in both cases. (With an explict loader invocation, the loader currently adds argv[0] to l_libname for the main map and the dlopen call suceeds as a result; it does not do that in standard mode.) 2019-08-12 Florian Weimer * elf/Makefile (tests): Unconditionally add tst-dlopen-aout. [$(build-hardcoded-path-in-tests)] (tst-dlopen-aout-no-pie): Do not set. * elf/tst-dlopen-aout.c: Do not included . (do_test): Open the executable using an absolute path. Print error message to standard output. Reviewed-by: Carlos O'Donell diff --git a/elf/Makefile b/elf/Makefile index a3eefd1b1f..e8c3458963 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -192,7 +192,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \ tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \ tst-unwind-ctor tst-unwind-main tst-audit13 \ - tst-sonamemove-link tst-sonamemove-dlopen + tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-aout # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -200,10 +200,6 @@ tests-internal += loadtest unload unload2 circleload1 \ tst-ptrguard1 tst-stackguard1 tst-libc_dlvsym \ tst-create_format1 tests-container += tst-pldd -ifeq ($(build-hardcoded-path-in-tests),yes) -tests += tst-dlopen-aout -tst-dlopen-aout-no-pie = yes -endif test-srcs = tst-pathopt selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null) ifneq ($(selinux-enabled),1) diff --git a/elf/tst-dlopen-aout.c b/elf/tst-dlopen-aout.c index deedd11ad0..4b3e3f111a 100644 --- a/elf/tst-dlopen-aout.c +++ b/elf/tst-dlopen-aout.c @@ -23,10 +23,11 @@ Note: this test currently only fails when glibc is configured with --enable-hardcoded-path-in-tests. */ -#include #include -#include #include +#include +#include +#include #include __thread int x; @@ -42,15 +43,21 @@ do_test (int argc, char *argv[]) { int j; + /* Use the full path so that the dynamic loader does not recognize + the main program as already loaded (even with an explicit ld.so + invocation). */ + char *path = xasprintf ("%s/%s", support_objdir_root, "tst-dlopen-aout"); + printf ("info: dlopen object: %s\n", path); + for (j = 0; j < 100; ++j) { pthread_t thr; void *p; - p = dlopen (argv[0], RTLD_LAZY); + p = dlopen (path, RTLD_LAZY); if (p != NULL) { - fprintf (stderr, "dlopen unexpectedly succeeded\n"); + puts ("error: dlopen succeeded unexpectedly"); return 1; } /* We create threads to force TLS allocation, which triggers @@ -60,6 +67,7 @@ do_test (int argc, char *argv[]) xpthread_join (thr); } + free (path); return 0; }