From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 26B6F3858C56 for ; Tue, 12 Apr 2022 18:42:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 26B6F3858C56 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-uVNnhIQQP_W6ENnpVdMnlA-1; Tue, 12 Apr 2022 14:42:45 -0400 X-MC-Unique: uVNnhIQQP_W6ENnpVdMnlA-1 Received: by mail-qk1-f198.google.com with SMTP id bq6-20020a05620a468600b00699e63cfda4so10223094qkb.20 for ; Tue, 12 Apr 2022 11:42:45 -0700 (PDT) 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=rbgloM8DjvbIyiizmBMD47ntKnRJ2IgefwYa7DopL8I=; b=g6vAVol1HENBm9rxtEeCcFeJ5Zr+69xZn7fJk5kMk9Z99ctK/m7WqyA984RWmHh67v Xnv2yUYRQ5WVMPl5SVrGL1nVz3TUDz3khxevCGJbbaRHxPVa1KxcEWTHt/mG0eCjRfOZ vLJLXIS2Za4S5RlvrnNGz3De7LV4lQYPpSYzvmbwfOKSqkhPZhjBDUPFIK4zkpLhh0Rp NRp018tpWg7RkYZiCIRBDMfkFDMpIRrVXYxKLSOiKT2U9t1/AuYl54W3sPadMIO+Cr9Q 80WRDhLT+bndH1IaGpOSGJWiLz5TO45UwUgubabIN5NsyDdEn6TB7JqV0Mt0jC1idnXY XhAQ== X-Gm-Message-State: AOAM530KLZNJ44u8lPZGa/dOeDqj35ofOrc7EYz/bVWvQJ4oBFH0VXoz b7OX9FazwK4PhfM+Wng93/sOalBMdTpTyZW0hV+ZK5k53Xevv8VkW2iD2bHRSHeZP9s8OHDawgb jIwkNQmSGVjqoLri7EISURjQ9OxaCUFRsvC0FEDYEUbGOqwF6Zt2UfZgDeqN3et3bL8I/j3I= X-Received: by 2002:a05:6214:2524:b0:444:3a35:d4d4 with SMTP id gg4-20020a056214252400b004443a35d4d4mr13159576qvb.55.1649788964540; Tue, 12 Apr 2022 11:42:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOb/Q2fCtamF4yA9GRKJGHoBGY90uaca3acP4N96aiHfv8Hj5tjAeA78VPAXCu6BqRoq+Wbw== X-Received: by 2002:a05:6214:2524:b0:444:3a35:d4d4 with SMTP id gg4-20020a056214252400b004443a35d4d4mr13159556qvb.55.1649788964274; Tue, 12 Apr 2022 11:42:44 -0700 (PDT) Received: from athas.redhat.com (135-23-175-80.cpe.pppoe.ca. [135.23.175.80]) by smtp.gmail.com with ESMTPSA id j19-20020a05622a039300b002ecc2ebfd87sm10953840qtx.32.2022.04.12.11.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 11:42:43 -0700 (PDT) From: Carlos O'Donell To: libc-stable@sourceware.org Cc: Adhemerval Zanella , Florian Weimer Subject: [PATCH 19/27] elf: Do not fail for failed dlmopen on audit modules (BZ #28061) Date: Tue, 12 Apr 2022 14:41:57 -0400 Message-Id: <20220412184205.3343677-20-carlos@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412184205.3343677-1-carlos@redhat.com> References: <20220412184205.3343677-1-carlos@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: application/octet-stream; x-default=true X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 18:42:48 -0000 From: Adhemerval Zanella 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 RT_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 be seen if the state is consistent, since _dt_main resets it. This patch removes the assert. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Florian Weimer (cherry picked from commit 484e672ddabe0a919a692520e6ac8f2580866235) Resolved conflicts: elf/Makefile elf/dl-open.c --- elf/Makefile | 5 ++++ elf/dl-open.c | 2 -- elf/tst-audit20.c | 25 +++++++++++++++++++ elf/tst-auditmod20.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 elf/tst-audit20.c create mode 100644 elf/tst-auditmod20.c diff --git a/elf/Makefile b/elf/Makefile index b3ccd21872..1445604b1f 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -355,6 +355,7 @@ tests += \ tst-audit17 \ tst-audit18 \ tst-audit19b \ + tst-audit20 \ tst-audit22 \ tst-auditmany \ tst-auxobj \ @@ -634,6 +635,7 @@ modules-names = \ tst-auditmod18 \ tst-auditmod19a \ tst-auditmod19b \ + tst-auditmod20 \ tst-auditmod22 \ tst-auxvalmod \ tst-big-note-lib \ @@ -1993,6 +1995,9 @@ $(objpfx)tst-audit19b.out: $(objpfx)tst-auditmod19b.so $(objpfx)tst-audit19b: $(objpfx)tst-audit19bmod.so tst-audit19b-ARGS = -- $(host-test-program-cmd) +$(objpfx)tst-audit20.out: $(objpfx)tst-auditmod20.so +tst-audit20-ENV = LD_AUDIT=$(objpfx)tst-auditmod20.so + $(objpfx)tst-audit22.out: $(objpfx)tst-auditmod22.so tst-audit22-ARGS = -- $(host-test-program-cmd) diff --git a/elf/dl-open.c b/elf/dl-open.c index 3f01aa4807..bc68726328 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -914,8 +914,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-audit20.c b/elf/tst-audit20.c new file mode 100644 index 0000000000..6f39ccee86 --- /dev/null +++ b/elf/tst-audit20.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-auditmod20.c b/elf/tst-auditmod20.c new file mode 100644 index 0000000000..c57e50ee4e --- /dev/null +++ b/elf/tst-auditmod20.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 (); +} -- 2.35.1