From patchwork Tue Sep 3 16:04:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 96982 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 AB39A384F02C for ; Tue, 3 Sep 2024 16:05:29 +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 5D2D7384F00E for ; Tue, 3 Sep 2024 16:04:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D2D7384F00E 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 5D2D7384F00E 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=1725379500; cv=none; b=lIsWHL87l6SOgT8uDlummPzL4rJh18ewbGHpdEi1iQeMVu/AQbWhw1V8IpAOG0S+0k29Ap1T3Pc1dzGjFUW0sueVp/xeo0EM6oLwqme25w6CE5Y1mgg9t0FlzWlLpklEVQj7Zu/EUZqF7CM8HR9t6GcMgw/tQ+B9e/e6Xei/eBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379500; c=relaxed/simple; bh=Sz22P1yst+Oi7XaayJ+V6Jr0LQ6UFrpPeRtLd80eDUc=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=tGKXMRgmjRlGdAx2Ji6GFvP7aCX9CJLvRs2OFJu6jHx6VSVuMDGqjCkPwO9tT7UIq5VdbuVPced0fnSGw9Kh0Pv7uxljbu3z+wV4qE7jddCmDVteUvf5RZ2mt4lM40zhEPXQPqKXS8AEXU67x8cuWcKmHKBzV7s2KxCidPSaIfg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725379499; 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=2QaDWykisl+HrD+Qs5vQZjz1Io2juPRrwhYTfEIbzPM=; b=ablVi6UH24xThg9pFDMddnhzBPO4oNXo5mO9wH5lCkeu0M+2+9HtlFq8c8aIiCngSAnaOV nqklZpBQyZ/qR4LWT23ddSkG6tvzUqhUStifn7kp+ckUASEqhugg01dWOEdf85xZuLxG/z T6U5jlhduFMs73Z4Uvf1PN1VgJpYGsI= Received: from mx-prod-mc-05.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-601-Ia3YyYAOPWuHb1XIagQfCw-1; Tue, 03 Sep 2024 12:04:58 -0400 X-MC-Unique: Ia3YyYAOPWuHb1XIagQfCw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4E3011977030 for ; Tue, 3 Sep 2024 16:04:57 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A33BB1956048 for ; Tue, 3 Sep 2024 16:04:56 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 1/4] elf: Always write audit log to elf/tst-audit23.out In-Reply-To: Message-ID: <525b784edd12948565604c56f036309e61c8c428.1725379370.git.fweimer@redhat.com> References: X-From-Line: 525b784edd12948565604c56f036309e61c8c428 Mon Sep 17 00:00:00 2001 Date: Tue, 03 Sep 2024 18:04:53 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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 Hopefully, this will simplify debugging test failures. --- elf/tst-audit23.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/elf/tst-audit23.c b/elf/tst-audit23.c index d2640fe8b2..ca4219c82b 100644 --- a/elf/tst-audit23.c +++ b/elf/tst-audit23.c @@ -85,6 +85,20 @@ do_test (int argc, char *argv[]) = support_capture_subprogram (spargv[0], spargv, NULL); support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr); + { + FILE *fp = fmemopen (result.err.buffer, result.err.length, "r"); + TEST_VERIFY (fp != NULL); + unsigned int line = 0; + char *buffer = NULL; + size_t buffer_length = 0; + puts ("info: *** audit log start ***"); + while (xgetline (&buffer, &buffer_length, fp)) + printf ("%6u\t%s", ++line, buffer); + puts ("info: *** audit log end ***"); + free (buffer); + xfclose (fp); + } + /* The expected la_objopen/la_objclose: 1. executable 2. loader @@ -115,8 +129,10 @@ do_test (int argc, char *argv[]) TEST_VERIFY (out != NULL); char *buffer = NULL; size_t buffer_length = 0; + unsigned int line = 0; while (xgetline (&buffer, &buffer_length, out)) { + ++line; if (startswith (buffer, "la_activity: ")) { uintptr_t cookie; @@ -174,8 +190,8 @@ do_test (int argc, char *argv[]) if (is_vdso (lname)) continue; if (nobjs == max_objs) - FAIL_EXIT1 ("non expected la_objopen: %s %"PRIxPTR" %ld", - lname, laddr, lmid); + FAIL_EXIT1 ("(line %u) non expected la_objopen: %s %"PRIxPTR" %ld", + line, lname, laddr, lmid); objs[nobjs].lname = lname; objs[nobjs].laddr = laddr; objs[nobjs].lmid = lmid; From patchwork Tue Sep 3 16:04:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 96983 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 4B55F384DEE6 for ; Tue, 3 Sep 2024 16:05:36 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 5AA00385EC2F for ; Tue, 3 Sep 2024 16:05:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AA00385EC2F 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 5AA00385EC2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379506; cv=none; b=x/VV3ieGZatiyQwJ+HDaOpVSStagwJzySXEsG1H+KA55xhc9tPDofyXV+kjr/l9Dm0a7gig2JDuaY2VsQpaR4avK4YqhFuj/euRriP0DO6P0c+z5Kxf7vhReSrJnVUL30l3UfcAb53V95YHy6wVU+67dTUCHN4xwdmKby5jKfuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379506; c=relaxed/simple; bh=KQ3CTIhkYICLYhoyPyi0z250Q8SpvK8sL7TPEzuzbF4=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=m5AvhUSruGhx3EwMHqKLtZMicOGmQ+HU3r85vRnX7oYUZ6pvGp3o+j9+2dNal8juoxmiaN6Ssg8wRoADdRRz1oFpT9TBMcd5jJ64mcOeP10QZRU5bsFJQctey4tKYSxjQwEW6PWuzfyei5dbavaM9lbEZN/4nfnZiu+Z98hcXRA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725379504; 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=Ju1CVqbYYbv82rZJkVajrJcKT9eKcS5BAqbhs3Pcs5U=; b=NrRGevMF2ezO/PjRe711jlV/bZn/BlWQHjymM0YtjUq7/yIkJm6fyLbQxJYF6Sui+uXKYN 6ir5Jjg6nzZQ/d+Xm+CH44PG/G8lmLkh/bXi04Y91iliBMOGIw5hdBCMbS6WioVDH8ybGp nv6A2G1sO68cEGpj+XnSn5wBUw004Y8= 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-424-i3XC5pq1NhaDwOg3sZHp5g-1; Tue, 03 Sep 2024 12:05:02 -0400 X-MC-Unique: i3XC5pq1NhaDwOg3sZHp5g-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 210F91955D4C for ; Tue, 3 Sep 2024 16:05:02 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 46B991956052 for ; Tue, 3 Sep 2024 16:05:01 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 2/4] elf: Signal la_objopen for the proxy link map in dlmopen (bug 31985) In-Reply-To: Message-ID: References: X-From-Line: c8c06c0be4c0ae2232942db13f0bc2233390341b Mon Sep 17 00:00:00 2001 Date: Tue, 03 Sep 2024 18:04:58 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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_H4, 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 --- elf/dl-load.c | 61 ++++++++++++++++++++++++++--------------------- elf/tst-audit23.c | 12 +++++++++- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 8a89b71016..54c9c4d779 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -918,6 +918,37 @@ _dl_process_pt_gnu_property (struct link_map *l, int fd, const ElfW(Phdr) *ph) } } +static void +_dl_notify_new_object (int mode, Lmid_t nsid, struct link_map *l) +{ + /* Signal that we are going to add new objects. */ + struct r_debug *r = _dl_debug_update (nsid); + if (r->r_state == RT_CONSISTENT) + { +#ifdef SHARED + /* Auditing checkpoint: we are going to add new objects. Since this + is called after _dl_add_to_namespace_list the namespace is guaranteed + to not be empty. */ + if ((mode & __RTLD_AUDIT) == 0) + _dl_audit_activity_nsid (nsid, LA_ACT_ADD); +#endif + + /* Notify the debugger we have added some objects. We need to + call _dl_debug_initialize in a static program in case dynamic + linking has not been used before. */ + r->r_state = RT_ADD; + _dl_debug_state (); + LIBC_PROBE (map_start, 2, nsid, r); + } + else + assert (r->r_state == RT_ADD); + +#ifdef SHARED + /* Auditing checkpoint: we have a new object. */ + if (!GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing) + _dl_audit_objopen (l, nsid); +#endif +} /* Map in the shared object NAME, actually located in REALNAME, and already opened on FD. */ @@ -1018,6 +1049,8 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, /* Add the map for the mirrored object to the object list. */ _dl_add_to_namespace_list (l, nsid); + _dl_notify_new_object (mode, nsid, l); + return l; } #endif @@ -1442,33 +1475,7 @@ cannot enable executable stack as shared object requires"); if (mode & __RTLD_SPROF) return l; - /* Signal that we are going to add new objects. */ - struct r_debug *r = _dl_debug_update (nsid); - if (r->r_state == RT_CONSISTENT) - { -#ifdef SHARED - /* Auditing checkpoint: we are going to add new objects. Since this - is called after _dl_add_to_namespace_list the namespace is guaranteed - to not be empty. */ - if ((mode & __RTLD_AUDIT) == 0) - _dl_audit_activity_nsid (nsid, LA_ACT_ADD); -#endif - - /* Notify the debugger we have added some objects. We need to - call _dl_debug_initialize in a static program in case dynamic - linking has not been used before. */ - r->r_state = RT_ADD; - _dl_debug_state (); - LIBC_PROBE (map_start, 2, nsid, r); - } - else - assert (r->r_state == RT_ADD); - -#ifdef SHARED - /* Auditing checkpoint: we have a new object. */ - if (!GL(dl_ns)[l->l_ns]._ns_loaded->l_auditing) - _dl_audit_objopen (l, nsid); -#endif + _dl_notify_new_object (mode, nsid, l); return l; } diff --git a/elf/tst-audit23.c b/elf/tst-audit23.c index ca4219c82b..55929c2fd4 100644 --- a/elf/tst-audit23.c +++ b/elf/tst-audit23.c @@ -52,6 +52,14 @@ startswith (const char *str, const char *pre) return lenstr >= lenpre && memcmp (pre, str, lenpre) == 0; } +static inline bool +endswith (const char *str, const char *suf) +{ + size_t lensuf = strlen (suf); + size_t lenstr = strlen (str); + return lenstr >= lensuf && memcmp (suf, str + lenstr - lensuf, lensuf) == 0; +} + static inline bool is_vdso (const char *str) { @@ -235,7 +243,9 @@ do_test (int argc, char *argv[]) for (size_t i = 0; i < nobjs; i++) { - TEST_COMPARE (objs[i].closed, true); + /* This subtest currently does not pass because of bug 32065. */ + if (! (endswith (objs[i].lname, LD_SO) && objs[i].lmid != LM_ID_BASE)) + TEST_COMPARE (objs[i].closed, true); free (objs[i].lname); } From patchwork Tue Sep 3 16:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 96985 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 6D832386100A for ; Tue, 3 Sep 2024 16:06:20 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 20A35384F027 for ; Tue, 3 Sep 2024 16:05:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20A35384F027 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 20A35384F027 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379511; cv=none; b=RT7wV7bSBIt2nh1bfEMNx2CtImOm1c3cY6izBKXe5IkVRFjGAxlixWetYyklO9UInPtMgNtMtpkWg8S/4mVbAelk1HKMxy+gFGs64HSnys0T7nxBhMeF5ZmROlQMp7zwaebZUc9V1/hbBHBhPaZRWb4v7NS/OHovMIKCe6z6ljs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725379511; c=relaxed/simple; bh=+4DQeHQvGA0ztjd4r981abM8MCe08QkqHE+ZhQ3IrP4=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=xc4D2TLmDsLwh6Mv24KitwgblGKmpWJKCPEUs8Gp2G1sA7czL6Reir2oqR0ANhssGBkRJBSpcmAURnohCcY56HjCV5pyA24ZjhXJl5GbMVu7p6yGOQ3ywtv20JydCD0ADaXF2nLtCeHOWVVcYnIpJ8kBuVeMmCSFSUbbaxPxPb4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725379508; 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=XReK8a0FTqADISTP1ULJK/LmeHMfZ9LCkjHzvoqehAw=; b=L4CJZHZjn3KU9AgXFiOudwnaW6zVG/zCnhk0ytBqNOq1/l+zjdG/3drLAH1LXAYhxfOc6W fVo5zSkvYS4CRf2QXgtedrkZ9U7uyBlp5+jPykP8uCRa7ApWi4uuuuvR/mGkuNwO7VJ4S1 LmdL2RLlbQxVDiAzviflJM5gLnPOsKg= Received: from mx-prod-mc-03.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-650-RgFRgjVRPUKor53soxfVxg-1; Tue, 03 Sep 2024 12:05:07 -0400 X-MC-Unique: RgFRgjVRPUKor53soxfVxg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CD5081955BF6 for ; Tue, 3 Sep 2024 16:05:06 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DD0651955F1B for ; Tue, 3 Sep 2024 16:05:05 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 3/4] elf: Call la_objclose for proxy link maps in _dl_fini (bug 32065) In-Reply-To: Message-ID: <075f5d6cae8dc081de56048134dd53da6a29b605.1725379370.git.fweimer@redhat.com> References: X-From-Line: 075f5d6cae8dc081de56048134dd53da6a29b605 Mon Sep 17 00:00:00 2001 Date: Tue, 03 Sep 2024 18:05:03 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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_H4, 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 --- elf/dl-fini.c | 9 +++++++++ elf/tst-audit23.c | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/elf/dl-fini.c b/elf/dl-fini.c index db996270de..a1a4c25829 100644 --- a/elf/dl-fini.c +++ b/elf/dl-fini.c @@ -69,6 +69,7 @@ _dl_fini (void) unsigned int i; struct link_map *l; + struct link_map *proxy_link_map = NULL; assert (nloaded != 0 || GL(dl_ns)[ns]._ns_loaded == NULL); for (l = GL(dl_ns)[ns]._ns_loaded, i = 0; l != NULL; l = l->l_next) /* Do not handle ld.so in secondary namespaces. */ @@ -84,6 +85,11 @@ _dl_fini (void) are not dlclose()ed from underneath us. */ ++l->l_direct_opencount; } + else + /* Used below to call la_objclose for the ld.so proxy + link map. */ + proxy_link_map = l; + assert (ns != LM_ID_BASE || i == nloaded); assert (ns == LM_ID_BASE || i == nloaded || i == nloaded - 1); unsigned int nmaps = i; @@ -122,6 +128,9 @@ _dl_fini (void) --l->l_direct_opencount; } + if (proxy_link_map != NULL) + _dl_audit_objclose (proxy_link_map); + #ifdef SHARED _dl_audit_activity_nsid (ns, LA_ACT_CONSISTENT); #endif diff --git a/elf/tst-audit23.c b/elf/tst-audit23.c index 55929c2fd4..71adbe6942 100644 --- a/elf/tst-audit23.c +++ b/elf/tst-audit23.c @@ -241,13 +241,26 @@ do_test (int argc, char *argv[]) } } + Lmid_t lmid_other = LM_ID_NEWLM; + unsigned int other_namespace_count = 0; for (size_t i = 0; i < nobjs; i++) { - /* This subtest currently does not pass because of bug 32065. */ - if (! (endswith (objs[i].lname, LD_SO) && objs[i].lmid != LM_ID_BASE)) - TEST_COMPARE (objs[i].closed, true); + if (objs[i].lmid != LM_ID_BASE) + { + if (lmid_other == LM_ID_NEWLM) + lmid_other = objs[i].lmid; + TEST_COMPARE (objs[i].lmid, lmid_other); + ++other_namespace_count; + if (!(endswith (objs[i].lname, "/" LIBC_SO) + || endswith (objs[i].lname, "/" LD_SO))) + FAIL ("unexpected object in secondary namespace: %s", + objs[i].lname); + } + TEST_COMPARE (objs[i].closed, true); free (objs[i].lname); } + /* Both libc.so and ld.so should be present. */ + TEST_COMPARE (other_namespace_count, 2); /* la_activity(LA_ACT_CONSISTENT) should be the last callback received. Since only one link map may be not-CONSISTENT at a time, this also 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; }