From patchwork Mon Jan 3 23:57:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 49498 Return-Path: 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 4A317385841E for ; Mon, 3 Jan 2022 23:59:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A317385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1641254344; bh=WjQ2aqKuoeFHoq912+G9aKYYsX4e2MnYP1TvORoo9lI=; 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=idoIKD6riwdbwkZKkxCrK+ZkHBaMokzH+/aALybigJomccY3PWmFba5su+ctXJyCu d9/D1+XBrzUIzPAjtkVaa9FOzPHGW5IKZqWvmv1Q95oMKd2mCg2Y4QFHDPWnDqx47R d+EO0zB8Rwilqr3z/pl44j1tEnO9V+6IF3JP04aA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 4039B3858C2C for ; Mon, 3 Jan 2022 23:58:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4039B3858C2C Received: by mail-pf1-x429.google.com with SMTP id u20so30658659pfi.12 for ; Mon, 03 Jan 2022 15:58:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WjQ2aqKuoeFHoq912+G9aKYYsX4e2MnYP1TvORoo9lI=; b=tco7aqcnVGaDAtHXtTegfiMz8ZOE40gb2LN2wJy+enJjgMCwp3KQUkqbwYdUXLoNzG s0T8K9Uv3q5GujqDLU3Q1OXDVx2t3mOsrdbPJOaH9y8T+QsIG3lBz9xQVvBiFDG7lyQh LQRgzM/y/ZJ2Q9ggGPQ3KRCxCM6ZT2rlMP49WEtSzDrv6LFqDZjdmUVezOj+FJJaOGSq GCQ/mlmJaQ+FA0hayvWE80SPlMLS1lTNdnr271rTOqxnDOQwYzFdgv9kvLCQjFEcu+aV EZXSQclB5dnqe6+Psr/k7TRYQsf5cgh7JnXkAtkn8r/BdProgp0P/19jlC4ab7+PdaHJ hcyg== X-Gm-Message-State: AOAM5304/SFcQWVUzwimkXmXX7whSaz/pL9+41LxkJwMDFn0doZBmCmI /qvcfuWSaRGR2ntFUXwA0ns= X-Google-Smtp-Source: ABdhPJxOKOm2A7Hdp8uB49UdrjmIY4JJmItVsoZJqlpBmqSbrDX7u/C5uRHjpuYTdJBrdMEcvFLmAg== X-Received: by 2002:a05:6a00:174d:b0:4bb:cbd7:c556 with SMTP id j13-20020a056a00174d00b004bbcbd7c556mr39384795pfc.26.1641254279239; Mon, 03 Jan 2022 15:57:59 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id c24sm16923564pgm.67.2022.01.03.15.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 15:57:58 -0800 (PST) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.42]) by gnu-tgl-3.localdomain (Postfix) with ESMTPS id 5E673C08CE; Mon, 3 Jan 2022 15:57:57 -0800 (PST) Received: from gnu-tgl-2.. (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id AF36E300436; Mon, 3 Jan 2022 15:57:53 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v5 1/1] elf: Also try DT_RUNPATH for LD_AUDIT dlopen [BZ #28455] Date: Mon, 3 Jan 2022 15:57:53 -0800 Message-Id: <20220103235753.2062518-2-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220103235753.2062518-1-hjl.tools@gmail.com> References: <20220103235753.2062518-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" DT_RUNPATH is only used to find the immediate dependencies of the executable or shared object containing the DT_RUNPATH entry. Update LD_AUDIT dlopen call to try the DT_RUNPATH entry of the executable. Add tst-audit14a, which is copied from tst-audit14, to DT_RUNPATH and build tst-audit14 with -Wl,--disable-new-dtags to test DT_RPATH. This partially fixes BZ #28455. Reviewed-by: Adhemerval Zanella --- elf/Makefile | 11 ++++++++--- elf/dl-load.c | 15 +++++++++++++++ elf/tst-audit14a.c | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 elf/tst-audit14a.c diff --git a/elf/Makefile b/elf/Makefile index 43dd18cc73..f9006e1d1d 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -354,10 +354,10 @@ ifneq ($(selinux-enabled),1) tests-execstack-yes = tst-execstack tst-execstack-needed tst-execstack-prog endif ifeq ($(have-depaudit),yes) -tests += tst-audit14 tst-audit15 tst-audit16 +tests += tst-audit14 tst-audit15 tst-audit16 tst-audit14a ifeq ($(run-built-tests),yes) tests-special += $(objpfx)tst-audit14-cmp.out $(objpfx)tst-audit15-cmp.out \ - $(objpfx)tst-audit16-cmp.out + $(objpfx)tst-audit16-cmp.out $(objpfx)tst-audit14a-cmp.out endif endif endif @@ -1832,9 +1832,11 @@ $(objpfx)tst-auditmany.out: $(objpfx)tst-auditmanymod1.so \ tst-auditmany-ENV = \ LD_AUDIT=tst-auditmanymod1.so:tst-auditmanymod2.so:tst-auditmanymod3.so:tst-auditmanymod4.so:tst-auditmanymod5.so:tst-auditmanymod6.so:tst-auditmanymod7.so:tst-auditmanymod8.so:tst-auditmanymod9.so -LDFLAGS-tst-audit14 = -Wl,--audit=tst-auditlogmod-1.so +LDFLAGS-tst-audit14 = -Wl,--audit=tst-auditlogmod-1.so,--disable-new-dtags $(objpfx)tst-auditlogmod-1.so: $(libsupport) $(objpfx)tst-audit14.out: $(objpfx)tst-auditlogmod-1.so +LDFLAGS-tst-audit14a = -Wl,--audit=tst-auditlogmod-1.so,--enable-new-dtags +$(objpfx)tst-audit14a.out: $(objpfx)tst-auditlogmod-1.so LDFLAGS-tst-audit15 = \ -Wl,--audit=tst-auditlogmod-1.so,--depaudit=tst-auditlogmod-2.so $(objpfx)tst-auditlogmod-2.so: $(libsupport) @@ -1861,6 +1863,9 @@ tst-audit17-ENV = LD_AUDIT=$(objpfx)tst-auditmod17.so $(objpfx)tst-audit14-cmp.out: tst-audit14.exp $(objpfx)tst-audit14.out cmp $^ > $@; \ $(evaluate-test) +$(objpfx)tst-audit14a-cmp.out: tst-audit14.exp $(objpfx)tst-audit14a.out + cmp $^ > $@; \ + $(evaluate-test) $(objpfx)tst-audit15-cmp.out: tst-audit15.exp $(objpfx)tst-audit15.out cmp $^ > $@; \ $(evaluate-test) diff --git a/elf/dl-load.c b/elf/dl-load.c index ddc4295ef5..12744caf91 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -2111,6 +2111,21 @@ _dl_map_object (struct link_map *loader, const char *name, &main_map->l_rpath_dirs, &realname, &fb, loader ?: main_map, LA_SER_RUNPATH, &found_other_class); + + /* Also try DT_RUNPATH in the executable for LD_AUDIT dlopen + call. */ + if (__glibc_unlikely (mode & __RTLD_AUDIT) + && fd == -1 && !did_main_map + && main_map != NULL && main_map->l_type != lt_loaded) + { + struct r_search_path_struct l_rpath_dirs; + l_rpath_dirs.dirs = NULL; + if (cache_rpath (main_map, &l_rpath_dirs, + DT_RUNPATH, "RUNPATH")) + fd = open_path (name, namelen, mode, &l_rpath_dirs, + &realname, &fb, loader ?: main_map, + LA_SER_RUNPATH, &found_other_class); + } } /* Try the LD_LIBRARY_PATH environment variable. */ diff --git a/elf/tst-audit14a.c b/elf/tst-audit14a.c new file mode 100644 index 0000000000..c6232eacf2 --- /dev/null +++ b/elf/tst-audit14a.c @@ -0,0 +1 @@ +#include "tst-audit14.c"