From patchwork Tue Nov 9 18:33:28 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: 47300 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 927BE385801C for ; Tue, 9 Nov 2021 18:35:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 927BE385801C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636482946; bh=QtQcIeq2cRsvyR96cuHvlOVH6zztTehMBATH041V7JY=; 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=eOf2od5+PpvoioI9+VdB0ypqiDYBzfKXr0wGuTd4Z/zH1dIHFjn6Ew/t8XBzazmt+ QS1ROemATlvm3vf9hu0Ou0069UkDazxG4wRzOGcOwwM80SHYdzcdAdCYhT1ymzG3Km 2JrJfOpTVfpZhQYz9FIadYUHGAMxjNEGtH2aSJ+w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 9C2B03858417 for ; Tue, 9 Nov 2021 18:34:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C2B03858417 Received: by mail-pg1-x52c.google.com with SMTP id p8so17946599pgh.11 for ; Tue, 09 Nov 2021 10:34: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=QtQcIeq2cRsvyR96cuHvlOVH6zztTehMBATH041V7JY=; b=bm9ZW+03ZoPmVOBlSRcxHMgi7V6WvJhzI6Clo6LxkuI0wl3d3DeBCDl9fR4wr95Hkg IGV9zRCuPv2kodJ+PUGzbumukcJOGV3qR/3FoabjNkTgbyUKdutbDB4cVouBPOlCOeRZ NpHPCTJ8RkIV48ITTvDXHluqp1+DyL+V+6mciTGAi4xkWJ74EVLEpReHBjZ51xJWUMMi lJNhCAuEsmKiv1iBiB+jLXfvfF8PmOIm6QtzW4uIDKPbiwn89PV/Mw7iThI9tSM9VhS7 9BmJwnxsWQadRDB67CWFD/1LeuYWyEBHTmDKkT1T5Zas92zI4qxsLuQc7Ox/j/xwG+Ty Au7g== X-Gm-Message-State: AOAM530+s03mP/Rfa2g8Vg6vYCfZG0PSDW0PnR2QHiGHauPTSJFKRyWh TICleW0LNg9kCLKgx9tCuKQuFv/wOFJEog== X-Google-Smtp-Source: ABdhPJy9rTVwhvEIYjctOM7z3A3ndJFKHwXvlfWKdDDKOYOA8P5dbKfj533c6Ja1FA4c9Jxag9cGkA== X-Received: by 2002:a62:30c7:0:b0:44c:1ec3:bc31 with SMTP id w190-20020a6230c7000000b0044c1ec3bc31mr94331337pfw.21.1636482839413; Tue, 09 Nov 2021 10:33:59 -0800 (PST) Received: from birita.. ([2804:431:c7cb:55a:94d0:2630:9b29:e621]) by smtp.gmail.com with ESMTPSA id ep15sm3761884pjb.3.2021.11.09.10.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 10:33:59 -0800 (PST) To: libc-alpha@sourceware.org, Florian Weimer Subject: [PATCH v5 03/22] elf: Do not fail for failed dlopem on audit modules (BZ #28061) Date: Tue, 9 Nov 2021 15:33:28 -0300 Message-Id: <20211109183347.2943786-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211109183347.2943786-1-adhemerval.zanella@linaro.org> References: <20211109183347.2943786-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 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 Netto 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, i686-linux-gnu, and aarch64-linux-gnu. --- elf/Makefile | 5 ++++ elf/dl-open.c | 2 -- elf/tst-audit19.c | 25 +++++++++++++++++++ elf/tst-auditmod19.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 elf/tst-audit19.c create mode 100644 elf/tst-auditmod19.c diff --git a/elf/Makefile b/elf/Makefile index bd1a0f79b4..96db0b4322 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -226,6 +226,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-dlopenfail-2 \ tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen \ tst-audit18a 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 \ @@ -315,6 +316,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-unique2mod1 tst-unique2mod2 \ tst-auditmod9a tst-auditmod9b \ tst-auditmod18a tst-auditmod18b tst-audit18bmod \ + tst-auditmod19 \ $(if $(CXX),tst-unique3lib tst-unique3lib2 tst-unique4lib \ tst-nodelete-uniquemod tst-nodelete-rtldmod \ tst-nodelete-zmod \ @@ -1560,6 +1562,9 @@ $(objpfx)tst-audit18b.out: $(objpfx)tst-auditmod18b.so $(objpfx)tst-audit18b: $(objpfx)tst-audit18bmod.so tst-audit18b-ARGS = -- $(host-test-program-cmd) +$(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 6ea5dd2457..00f6d8cfcc 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -932,8 +932,6 @@ no more namespaces available for dlmopen()")); the flag here. */ } - assert (_dl_debug_update (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 (); +}