From patchwork Tue Sep 3 16:05:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 96984 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 52C22386481A for ; Tue, 3 Sep 2024 16:05:49 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 19DCB386482B for ; Tue, 3 Sep 2024 16:05:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19DCB386482B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 19DCB386482B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379517; cv=none; b=bItbATY3o7wkqOF5j07gMe0jzG0jAnOPPQc3/V5/M+lTVNqfULHuVW5RmHlbZRzarpEcfDTRGmT1KD+r4vExQQxaz2F29rLrTIQbhJfgUaFI6IDn9tNfg6fgJwtgR1i30y5KR6M1VUuCfg6QerJ4AGaPVxXTEuX+JXRxE3Gu/+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379517; c=relaxed/simple; bh=pYuZJtghEW8o5Qwj0dwYCvmEHlJGRANv527EavtqlAI=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=FVXFcVqVVo47ZhMhfGB/qRKzpxs+31rngCrIkx2jpJEG8EoAlqbFQAB+GlPDAiLmGcipKhBULjFUb9U4qqvy5uTufeJsZ7O3S4hpxWT5wj4nwcFJgmocOELEtc4keoJ1u0TeJxEUmt8CykO/OzlbJuBKha+/RhThsqAZ+HUdEls= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725379513; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0IOh7CQBAVD8FBAGcEc45Iu6Jqwx6tbSn+fnvc9cZkU=; b=DJKX/iuxPMX/kKzqliMM/6QjoDdY/27gP/C3wdbOlWPOxYxD7PzUXlugNm8yigGBNoekFb GxX5aiTgjJuT/zWJTWdDM6WlIcfJhB9TA3RqYCEg4EZIhnqqOVZ6gyJ+5zW8BRynlHIE/A +Sn59dSSwjg+Sh7PQ8/1dJYAzJr3RWE= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-ob1sU0RDOACLqOJkJBuiZQ-1; Tue, 03 Sep 2024 12:05:12 -0400 X-MC-Unique: ob1sU0RDOACLqOJkJBuiZQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D31D718EA898 for ; Tue, 3 Sep 2024 16:05:11 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.4]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EDBE519560AA for ; Tue, 3 Sep 2024 16:05:10 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 4/4] elf: Reorder audit events in dlcose to match _dl_fini (bug 32066) In-Reply-To: Message-ID: <38f5e72ebdc198e2c949cd498f9572f3bed8be30.1725379370.git.fweimer@redhat.com> References: X-From-Line: 38f5e72ebdc198e2c949cd498f9572f3bed8be30 Mon Sep 17 00:00:00 2001 Date: Tue, 03 Sep 2024 18:05:08 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This was discovered after extending elf/tst-audit23 to cover dlclose of the dlmopen namespace. Auditors already experience the new order during process shutdown (_dl_fini), so no LAV_CURRENT bump or backwards compatibility code seems necessary. --- elf/dl-close.c | 14 ++++++++------ elf/tst-audit23.c | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/elf/dl-close.c b/elf/dl-close.c index 88226245eb..432a35b141 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -264,6 +264,12 @@ _dl_close_worker (struct link_map *map, bool force) _dl_catch_exception (NULL, _dl_call_fini, imap); #ifdef SHARED + /* Auditing checkpoint: we will start deleting objects. + This is supposed to happen before la_objclose (see _dl_fini), + but only once per non-recursive dlclose call. */ + if (!unload_any) + _dl_audit_activity_nsid (nsid, LA_ACT_DELETE); + /* Auditing checkpoint: we remove an object. */ _dl_audit_objclose (imap); #endif @@ -424,12 +430,8 @@ _dl_close_worker (struct link_map *map, bool force) if (!unload_any) goto out; -#ifdef SHARED - /* Auditing checkpoint: we will start deleting objects. */ - _dl_audit_activity_nsid (nsid, LA_ACT_DELETE); -#endif - - /* Notify the debugger we are about to remove some loaded objects. */ + /* Notify the debugger we are about to remove some loaded objects. + LA_ACT_DELETE has already been signalled above for !unload_any. */ struct r_debug *r = _dl_debug_update (nsid); r->r_state = RT_DELETE; _dl_debug_state (); diff --git a/elf/tst-audit23.c b/elf/tst-audit23.c index 71adbe6942..bf8c825551 100644 --- a/elf/tst-audit23.c +++ b/elf/tst-audit23.c @@ -30,16 +30,21 @@ #include #include #include +#include static int restart; +static int do_dlclose; #define CMDLINE_OPTIONS \ - { "restart", no_argument, &restart, 1 }, + { "restart", no_argument, &restart, 1 }, \ + { "dlclose", no_argument, &do_dlclose, 1 }, \ static int handle_restart (void) { xdlopen ("tst-audit23mod.so", RTLD_NOW); - xdlmopen (LM_ID_NEWLM, LIBC_SO, RTLD_NOW); + void *handle = xdlmopen (LM_ID_NEWLM, LIBC_SO, RTLD_NOW); + if (do_dlclose) + xdlclose (handle); return 0; } @@ -67,8 +72,8 @@ is_vdso (const char *str) || startswith (str, "linux-vdso"); } -static int -do_test (int argc, char *argv[]) +static void +do_one_test (int argc, char *argv[], bool pass_dlclose_flag) { /* We must have either: - One or four parameters left if called initially: @@ -76,16 +81,15 @@ do_test (int argc, char *argv[]) + "--library-path" optional + the library path optional + the application name */ - if (restart) - return handle_restart (); - - char *spargv[9]; + char *spargv[10]; TEST_VERIFY_EXIT (((argc - 1) + 3) < array_length (spargv)); int i = 0; for (; i < argc - 1; i++) spargv[i] = argv[i + 1]; spargv[i++] = (char *) "--direct"; spargv[i++] = (char *) "--restart"; + if (pass_dlclose_flag) + spargv[i++] = (char *) "--dlclose"; spargv[i] = NULL; setenv ("LD_AUDIT", "tst-auditmod23.so", 0); @@ -151,8 +155,14 @@ do_test (int argc, char *argv[]) /* The cookie identifies the object at the head of the link map, so we only add a new namespace if it changes from the previous - one. This works since dlmopen is the last in the test body. */ - if (cookie != last_act_cookie && last_act_cookie != -1) + one. This works since dlmopen is the last in the test body. + + Currently, this does not work as expected because there + is no head link map if a namespace is completely deleted. + No LA_ACT_CONSISTENT event is generated in that case. + See the comment in _dl_audit_activity_nsid and bug 32068. */ + if (cookie != last_act_cookie && last_act_cookie != -1 + && !pass_dlclose_flag) TEST_COMPARE (last_act, LA_ACT_CONSISTENT); if (this_act == LA_ACT_ADD && acts[nacts] != cookie) @@ -270,7 +280,16 @@ do_test (int argc, char *argv[]) free (buffer); xfclose (out); +} + +static int +do_test (int argc, char *argv[]) +{ + if (restart) + return handle_restart (); + do_one_test (argc, argv, false); + do_one_test (argc, argv, true); return 0; }