From patchwork Wed Jul 7 18:26:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44212 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 1E04C396E807 for ; Wed, 7 Jul 2021 18:31:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E04C396E807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625682690; bh=S075vDMoDQcjjTFDJ5tKGDnLYgnn6P74mhIcuoO4ymQ=; 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=AVEXJTKY1K/ipnuFAn/gj1UHaTuFDxiNafDw7omLxbt+w7r+qWes6Rkxzvav/EoPX npH0YGoJUKyoXartnKOrQFlnR0lhUTMTZAVVNs/BOxaXsudl7LEjOe3JENBsyMY9/e foUfu0mk77olMkBL83bqJd3C119aBWDyEauMUDZg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id E5E98396E473 for ; Wed, 7 Jul 2021 18:29:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5E98396E473 Received: by mail-pg1-x52b.google.com with SMTP id h4so3182860pgp.5 for ; Wed, 07 Jul 2021 11:29:35 -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=S075vDMoDQcjjTFDJ5tKGDnLYgnn6P74mhIcuoO4ymQ=; b=e4LdCWNXFdkootk9fq/aG+pcE8hpUPmxbphV958+PWkzz50eLoH3nYUieP099anTVe +ued9/9ThH2gKecbBG57fMMJ8laXyqmb06JxWegKCYfySVRsF+7uDalGiloQ0PV1bMen d+2VmCNft6shdYV/2054U05X8+KtLxr47uKVTPui3L3QUTRaTYGItOgkiHRAzPyTvxno VZnDcHGiMTqyaLraUbrmoJkXS+0HZIMEOQq7vo6hhZcq/g6QWdWhtT1TQ2QBVrM+vwEr B/28EKNxqKC/nAyOOnMX//PgyxKMCzPJ/DWHmDOyUZDYelrF7lwPWAVDw86MWmawlH05 DU9g== X-Gm-Message-State: AOAM532SiQQWpq8UbIo21aTLoC3bb3O18l7fk1j4E32JaS2qsIBvcxpP 5mUQ5VGGTg9qnUv7ecROVCbWxLN3n26/fg== X-Google-Smtp-Source: ABdhPJynoz56K0rWPrub8ACsEgkMVNEqTWCMFSJADbnIuvE9C+7oatufE3pI9YX3uOmxUR+qtozVlw== X-Received: by 2002:aa7:8254:0:b029:2ed:b41:fefc with SMTP id e20-20020aa782540000b02902ed0b41fefcmr27242228pfn.42.1625682574818; Wed, 07 Jul 2021 11:29:34 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id fv8sm18868662pjb.21.2021.07.07.11.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 11:29:34 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 4/5] elf: Do not fail for failed dlmopen on audit modules (BZ #28061) Date: Wed, 7 Jul 2021 15:26:09 -0300 Message-Id: <20210707182610.3940620-5-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=-12.5 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 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 Reply-To: Adhemerval Zanella Cc: John Mellor-Crummey Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The dl_main() sets the LM_ID_BASE to RT_ADD just before starting to add load new shared objects. The state is set to R_CONSISTENT just after all objects are loaded. However if a audit modules tries to dlmopen() an inexistent module, the _dl_open() will assert that the namespace is in an inconsistent state. This is different than dlopen(), since first it will not use LM_ID_BASE and second _dl_map_object_from_fd() is the sole responsible to set and reset the r_state value. So the assert() on _dl_open() can not really see if the state is consistent since it is _dt_main() that reset is. This patch removes the assert. Checked on x86_64-linux-gnu. --- elf/Makefile | 7 ++++-- elf/dl-open.c | 2 -- elf/tst-audit19.c | 25 +++++++++++++++++++ elf/tst-auditmod19.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 elf/tst-audit19.c create mode 100644 elf/tst-auditmod19.c diff --git a/elf/Makefile b/elf/Makefile index 19f885679a..513b7e68a2 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -220,7 +220,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-dlopenfail-2 \ tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen \ tst-audit14 tst-audit15 tst-audit16 tst-audit17 tst-audit18a \ - tst-audit18b \ + tst-audit18b tst-audit19 \ 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 \ @@ -295,7 +295,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-unique1mod1 tst-unique1mod2 \ tst-unique2mod1 tst-unique2mod2 \ tst-auditmod9a tst-auditmod9b \ - tst-auditmod18a tst-audit18bmod tst-auditmod18b \ + tst-auditmod18a tst-audit18bmod tst-auditmod18b tst-auditmod19 \ $(if $(CXX),tst-unique3lib tst-unique3lib2 tst-unique4lib \ tst-nodelete-uniquemod tst-nodelete-rtldmod \ tst-nodelete-zmod \ @@ -1502,6 +1502,9 @@ LDFLAGS-tst-audit18bmod.so = -Wl,-z,now LDFLAGS-tst-audit18b = -Wl,-z,now tst-audit18b-ENV = LD_AUDIT=$(objpfx)tst-auditmod18b.so +$(objpfx)tst-audit19.out: $(objpfx)tst-auditmod19.so +tst-audit19-ENV = LD_AUDIT=$(objpfx)tst-auditmod19.so + # tst-sonamemove links against an older implementation of the library. LDFLAGS-tst-sonamemove-linkmod1.so = \ -Wl,--version-script=tst-sonamemove-linkmod1.map \ diff --git a/elf/dl-open.c b/elf/dl-open.c index 66ec9d7ed5..696de8172f 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -916,8 +916,6 @@ no more namespaces available for dlmopen()")); the flag here. */ } - assert (_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT); - /* Release the lock. */ __rtld_lock_unlock_recursive (GL(dl_load_lock)); diff --git a/elf/tst-audit19.c b/elf/tst-audit19.c new file mode 100644 index 0000000000..6f39ccee86 --- /dev/null +++ b/elf/tst-audit19.c @@ -0,0 +1,25 @@ +/* Check dlopen failure on audit modules. + 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-auditmod19.c b/elf/tst-auditmod19.c new file mode 100644 index 0000000000..c57e50ee4e --- /dev/null +++ b/elf/tst-auditmod19.c @@ -0,0 +1,57 @@ +/* Check dlopen failure on audit modules. + 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 + . */ + +#include +#include +#include + +unsigned int +la_version (unsigned int v) +{ + return LAV_CURRENT; +} + +static void +check (void) +{ + { + void *mod = dlopen ("nonexistent.so", RTLD_NOW); + if (mod != NULL) + abort (); + } + + { + void *mod = dlmopen (LM_ID_BASE, "nonexistent.so", RTLD_NOW); + if (mod != NULL) + abort (); + } +} + +void +la_activity (uintptr_t *cookie, unsigned int flag) +{ + if (flag != LA_ACT_CONSISTENT) + return; + check (); +} + +void +la_preinit (uintptr_t *cookie) +{ + check (); +}