From patchwork Thu Aug 8 11:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1970512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KmMzPZvB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WflTy3MdSz1yfC for ; Thu, 8 Aug 2024 21:40:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C028B3858429 for ; Thu, 8 Aug 2024 11:40:35 +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 AF0BC3858D28 for ; Thu, 8 Aug 2024 11:40:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF0BC3858D28 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 AF0BC3858D28 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=1723117221; cv=none; b=umoeWK5Fsj0UzuRS/y7uD07T74gOJezbhNoufYbrqLZVyCTBFUC9cCf2gUVzERR/PTiu4LJsHEClNkyPChb5IzXdkoCOY9ExHRC2WECHSUmT9W7Cv5MkYwr0j6bnOW9FUJaUjpEcrOp5p/lZsw5HiMfRhg7DEkozqzFhjILtKGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723117221; c=relaxed/simple; bh=8ufK7m0CU9ve8fySktV7HVUkv98OY5KBwpzwoQd4Sys=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=xGPiGup9+TxunAKRhDIXgA6Lucsh6YpTWgS5bDGcfq/aJqTpBeQLmQGvKZLW51+wTTkOrkKnQugNxbX5iltUxcrLtidLTjhKjSaGIK1GrPcoGerK/yLeIx5Y7ZnFrQmWOokZ8AvWKE8asVXApra/JSNP3j3Ot6PRjNe/I4rPJ4w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723117219; 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=G5v7untkRDMJ8UNg+9j+CW0p88LfQg22LU2i2DQn1B0=; b=KmMzPZvBbOTH1v78MLI1UBhhrByRSzE8mGDwUbQiLLj6dYZs5xpM6R6UXJyO8KostzAUrW e2zUIXxuGthQpWfTEavpuYIK53RbgDRNmN3/dVnBg9WnpfP/JVpyjCMWMAkHfdPPqY5RyB wUkTCFY3HzWPWetBn1e/N7p2+ABicd4= Received: from mx-prod-mc-01.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-688-8N3mn8KdOlSj6P3fkvlxIw-1; Thu, 08 Aug 2024 07:40:18 -0400 X-MC-Unique: 8N3mn8KdOlSj6P3fkvlxIw-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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 23F2D1920C16 for ; Thu, 8 Aug 2024 11:40:15 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.45.224.76]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A0EA1953976 for ; Thu, 8 Aug 2024 11:40:13 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 2/3] elf: Signal LA_ACT_CONSISTENT to auditors after RT_CONSISTENT switch In-Reply-To: Message-ID: <3238d4cc26934a86acd8b8f3e01a6dcc33ab798e.1723116962.git.fweimer@redhat.com> References: X-From-Line: 3238d4cc26934a86acd8b8f3e01a6dcc33ab798e Mon Sep 17 00:00:00 2001 Date: Thu, 08 Aug 2024 13:40:10 +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=-10.8 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, SPF_HELO_NONE, SPF_NONE, TXREP 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~incoming=patchwork.ozlabs.org@sourceware.org Auditors can call into the dynamic loader again if LA_ACT_CONSISTENT, and those recursive calls could observe r_state != RT_CONSISTENT. We should consider failing dlopen/dlmopen/dlclose if r_state != RT_CONSISTENT. The dynamic linker is probably not in a state in which it can handle reentrant calls. This needs further investigation. Reviewed-by: Adhemerval Zanella --- elf/dl-close.c | 10 +++++----- elf/dl-open.c | 10 +++++----- elf/rtld.c | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/elf/dl-close.c b/elf/dl-close.c index 88226245eb..b6f4daac79 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -723,6 +723,11 @@ _dl_close_worker (struct link_map *map, bool force) /* TLS is cleaned up for the unloaded modules. */ __rtld_lock_unlock_recursive (GL(dl_load_tls_lock)); + /* Notify the debugger those objects are finalized and gone. */ + r->r_state = RT_CONSISTENT; + _dl_debug_state (); + LIBC_PROBE (unmap_complete, 2, nsid, r); + #ifdef SHARED /* Auditing checkpoint: we have deleted all objects. Also, do not notify auditors of the cleanup of a failed audit module loading attempt. */ @@ -735,11 +740,6 @@ _dl_close_worker (struct link_map *map, bool force) --GL(dl_nns); while (GL(dl_ns)[GL(dl_nns) - 1]._ns_loaded == NULL); - /* Notify the debugger those objects are finalized and gone. */ - r->r_state = RT_CONSISTENT; - _dl_debug_state (); - LIBC_PROBE (unmap_complete, 2, nsid, r); - /* Recheck if we need to retry, release the lock. */ out: if (dl_close_state == rerun) diff --git a/elf/dl-open.c b/elf/dl-open.c index 2c20aa1df9..5e74807d23 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -628,17 +628,17 @@ dl_open_worker_begin (void *a) #endif } -#ifdef SHARED - /* Auditing checkpoint: we have added all objects. */ - _dl_audit_activity_nsid (new->l_ns, LA_ACT_CONSISTENT); -#endif - /* Notify the debugger all new objects are now ready to go. */ struct r_debug *r = _dl_debug_update (args->nsid); r->r_state = RT_CONSISTENT; _dl_debug_state (); LIBC_PROBE (map_complete, 3, args->nsid, r, new); +#ifdef SHARED + /* Auditing checkpoint: we have added all objects. */ + _dl_audit_activity_nsid (new->l_ns, LA_ACT_CONSISTENT); +#endif + _dl_open_check (new); /* Print scope information. */ diff --git a/elf/rtld.c b/elf/rtld.c index 1e2e9ad5a8..0dd64de13a 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2393,9 +2393,6 @@ dl_main (const ElfW(Phdr) *phdr, _dl_relocate_object might need to call `mprotect' for DT_TEXTREL. */ _dl_sysdep_start_cleanup (); - /* Auditing checkpoint: we have added all objects. */ - _dl_audit_activity_nsid (LM_ID_BASE, LA_ACT_CONSISTENT); - /* Notify the debugger all new objects are now ready to go. We must re-get the address since by now the variable might be in another object. */ r = _dl_debug_update (LM_ID_BASE); @@ -2403,6 +2400,9 @@ dl_main (const ElfW(Phdr) *phdr, _dl_debug_state (); LIBC_PROBE (init_complete, 2, LM_ID_BASE, r); + /* Auditing checkpoint: we have added all objects. */ + _dl_audit_activity_nsid (LM_ID_BASE, LA_ACT_CONSISTENT); + #if defined USE_LDCONFIG && !defined MAP_COPY /* We must munmap() the cache file. */ _dl_unload_cache ();