From patchwork Wed Jul 7 18:26:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 44209 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 BA8A5396E41A for ; Wed, 7 Jul 2021 18:27:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA8A5396E41A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625682442; bh=AKq2qbd99jzUNis23hTpUXHtG6G+oFwa7eW+PcHpCJE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=X8PyQXphCNpjuHK+6/xek2FqlyI15Leum+Clzl7mwQ96XXQse0y+YUSkDGc/6jwCb A9wtdbqlq69pveut7o318O+MYbsGeOvfcviYkdahQE/Rvc5zD8nmLBBsLBpfHZy/dT LxOjQbQ+Q+NnESC0VEqSva59+UnZHsCf/fc9pnTc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id B6970386EC2F for ; Wed, 7 Jul 2021 18:26:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B6970386EC2F Received: by mail-pg1-x531.google.com with SMTP id y4so699848pgl.10 for ; Wed, 07 Jul 2021 11:26:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AKq2qbd99jzUNis23hTpUXHtG6G+oFwa7eW+PcHpCJE=; b=hN041lAsj2M49KG/ElxqzxBAzzcIi6BfzBiDHmoB2MM9CkPrVmQMMv4H16k6BN8rpa 6RKM/a7DzSlGbIm9zCDIazW4BYBtjcB0qfGWG9fydFOFbka1ZV2d7FL1berBhE7Gn6f2 7bUn59h2ykYMX+kLEI41r5ZKrSn9aaKYQmqU9kV/kSwjg4RTQzXE9uot2Z5/PtuEz55q XMvZVe383rwTGLTLWPXt2Ib5cBDqH9Stb+LcTNap7dlJkgylfNMlEY15DdxBz/vK3JvH W+bQ29A9rIMwRgpXUWgU7xHdqQb6Tan7sy0n+FcHA6iohwINE3TO5ur2IwoP9pQvKaJ4 qMwA== X-Gm-Message-State: AOAM530XlYf5Aqw6Zf/cm91vlSb/48QIn+PxUPENoOtclRE7ytwBI4Nm ZtUZ/SDLV1at/L0N27ZJZKDWZRazY5lcbw== X-Google-Smtp-Source: ABdhPJwvg3VuuWmu07mIZdvbrWpJh7UVHlBoYebCgllZlX1VN4WHG8VfqGOthZ2N3YanHfKBznPIFw== X-Received: by 2002:a05:6a00:1508:b029:30a:2b2:b2ea with SMTP id q8-20020a056a001508b029030a02b2b2eamr27237497pfu.30.1625682377617; Wed, 07 Jul 2021 11:26:17 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id fv8sm18868662pjb.21.2021.07.07.11.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 11:26:17 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/5] elf: Fix audit regression Date: Wed, 7 Jul 2021 15:26:06 -0300 Message-Id: <20210707182610.3940620-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210707182610.3940620-1-adhemerval.zanella@linaro.org> References: <20210707182610.3940620-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: John Mellor-Crummey Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Commit 03e187a41d9 added a regression when an audit module does not have libc as DT_NEEDED (although unusual it is possible). Checked on x86_64-linux-gnu. --- elf/Makefile | 12 +++++++++++- elf/dl-open.c | 2 +- elf/tst-audit17.c | 25 +++++++++++++++++++++++++ elf/tst-auditmod17.c | 24 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 elf/tst-audit17.c create mode 100644 elf/tst-auditmod17.c diff --git a/elf/Makefile b/elf/Makefile index b1e01d9516..5214196de6 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -219,7 +219,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail \ tst-dlopenfail-2 \ tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen \ - tst-audit14 tst-audit15 tst-audit16 \ + tst-audit14 tst-audit15 tst-audit16 tst-audit17 \ tst-single_threaded tst-single_threaded-pthread \ tst-tls-ie tst-tls-ie-dlmopen argv0test \ tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ @@ -361,6 +361,7 @@ modules-names += tst-gnu2-tls1mod $(objpfx)tst-gnu2-tls1: $(objpfx)tst-gnu2-tls1mod.so tst-gnu2-tls1mod.so-no-z-defs = yes CFLAGS-tst-gnu2-tls1mod.c += -mtls-dialect=gnu2 + endif ifeq (yes,$(have-protected-data)) modules-names += tst-protected1moda tst-protected1modb @@ -1467,6 +1468,15 @@ $(objpfx)tst-auditlogmod-3.so: $(libsupport) $(objpfx)tst-audit16.out: \ $(objpfx)tst-auditlogmod-1.so $(objpfx)tst-auditlogmod-2.so \ $(objpfx)tst-auditlogmod-3.so +$(objpfx)tst-audit17.out: $(objpfx)tst-auditmod17.so +# The test check if a audit library without libc.so on DT_NEEDED works as +# intended, so it uses an explicit link rule. +$(objpfx)tst-auditmod17.so: $(objpfx)tst-auditmod17.os + $(CC) -nostdlib -nostartfiles -shared -o $@.new \ + $(filter-out $(map-file),$^) + $(call after-link,$@.new) + mv -f $@.new $@ +tst-audit17-ENV = LD_AUDIT=$(objpfx)tst-auditmod17.so # tst-sonamemove links against an older implementation of the library. LDFLAGS-tst-sonamemove-linkmod1.so = \ diff --git a/elf/dl-open.c b/elf/dl-open.c index a066f39bd0..66ec9d7ed5 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -771,7 +771,7 @@ dl_open_worker (void *a) { struct link_map *libc_map = GL(dl_ns)[args->nsid].libc_map; #ifdef SHARED - bool initial = libc_map->l_ns == LM_ID_BASE; + bool initial = libc_map != NULL ? libc_map->l_ns == LM_ID_BASE : false; #else /* In the static case, there is only one namespace, but it contains a secondary libc (the primary libc is statically diff --git a/elf/tst-audit17.c b/elf/tst-audit17.c new file mode 100644 index 0000000000..92986699d4 --- /dev/null +++ b/elf/tst-audit17.c @@ -0,0 +1,25 @@ +/* Check DT_AUDIT with audit not linked against libc. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +static int +do_test (void) +{ + return 0; +} + +#include diff --git a/elf/tst-auditmod17.c b/elf/tst-auditmod17.c new file mode 100644 index 0000000000..762de376e2 --- /dev/null +++ b/elf/tst-auditmod17.c @@ -0,0 +1,24 @@ +/* Check DT_AUDIT with audit not linked against libc. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +unsigned int +la_version (unsigned int version) +{ + return version; +} +