From patchwork Tue Jul 4 20:03:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1803382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=kidXfXBA; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QwYlc5s7zz20Pg for ; Wed, 5 Jul 2023 06:09:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D6593898C67 for ; Tue, 4 Jul 2023 20:08:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D6593898C67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688501338; bh=jzzF3qca2rZsoVMTCEhtYkgqpeOudIiBPSGSxOF+FHI=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=kidXfXBAG7oeS2Vh2RPolAaGndvHANQB1316xhLBh6+ScG+2joLI+gNI49iZ0siv0 th/NUfQv0oxX+zmxL+7R8Ueo9yCG4+Q9fEvhXWOeLqOxUEDKmQt5k3C896qhisev0B G9E2KNxGWh/MDqfjMUxf34RQxcUGYzSXAp7KkLOU= 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 ESMTPS id CB32D3870C2C for ; Tue, 4 Jul 2023 20:03:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB32D3870C2C Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-269-PYwrRjMHN_yD49F1Zo48Tw-1; Tue, 04 Jul 2023 16:03:39 -0400 X-MC-Unique: PYwrRjMHN_yD49F1Zo48Tw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 164618007CE for ; Tue, 4 Jul 2023 20:03:39 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FE4D1121315 for ; Tue, 4 Jul 2023 20:03:38 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 18/33] elf: Allocate auditor state after read-write link map In-Reply-To: Message-ID: <24eccac223a694152ea6d39cb281db9823648314.1688499219.git.fweimer@redhat.com> References: X-From-Line: 24eccac223a694152ea6d39cb281db9823648314 Mon Sep 17 00:00:00 2001 Date: Tue, 04 Jul 2023 22:03:36 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.5 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, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Auditors can write to the cookie member, so it has to remain read-write even if other parts of the link map are write-protected. --- elf/dl-object.c | 6 +++--- elf/rtld.c | 9 +++++++-- include/link.h | 9 +++++---- sysdeps/generic/ldsodefs.h | 17 +++-------------- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/elf/dl-object.c b/elf/dl-object.c index 1a9b04dd3c..0741371b80 100644 --- a/elf/dl-object.c +++ b/elf/dl-object.c @@ -89,12 +89,12 @@ _dl_new_object (char *realname, const char *libname, int type, # define audit_space 0 #endif - new = calloc (sizeof (*new) + audit_space + new = calloc (sizeof (*new) + sizeof (struct link_map_private *) + sizeof (*newname) + libname_len, 1); if (new == NULL) return NULL; - new->l_rw = calloc (1, sizeof (*new->l_rw)); + new->l_rw = calloc (1, sizeof (*new->l_rw) + audit_space); if (new->l_rw == NULL) { free (new); @@ -103,7 +103,7 @@ _dl_new_object (char *realname, const char *libname, int type, new->l_real = new; new->l_symbolic_searchlist.r_list - = (struct link_map_private **) ((char *) (new + 1) + audit_space); + = (struct link_map_private **) ((char *) (new + 1)); new->l_libname = newname = (struct libname_list *) (new->l_symbolic_searchlist.r_list + 1); diff --git a/elf/rtld.c b/elf/rtld.c index 3bdf3d814e..f086ee1712 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -458,8 +458,13 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) interfere with __rtld_static_init. */ GLRO (dl_find_object) = &_dl_find_object; - static struct link_map_rw rtld_map_rw; - GL (dl_rtld_map).l_rw = &rtld_map_rw; + /* Pre-allocated read-write status of the ld.so link map. */ + static struct + { + struct link_map_rw l; + struct auditstate _dl_rtld_auditstate[DL_NNS]; + } rtld_map_rw; + GL (dl_rtld_map).l_rw = &rtld_map_rw.l; #if NO_TLS_OFFSET != 0 GL (dl_rtld_map).l_rw->l_tls_offset = NO_TLS_OFFSET; #endif diff --git a/include/link.h b/include/link.h index 1c0170372e..181cd2e444 100644 --- a/include/link.h +++ b/include/link.h @@ -374,15 +374,16 @@ l_next (struct link_map_private *l) #include -/* Information used by audit modules. For most link maps, this data - immediate follows the link map in memory. For the dynamic linker, - it is allocated separately. See link_map_audit_state in - . */ +/* Information used by audit modules. An array of size GLRO (naudit) + elements follows the l_rw link map data in memory (in some cases + conservatively extended to to DL_NNS). */ struct auditstate { uintptr_t cookie; unsigned int bindflags; }; +_Static_assert (__alignof (struct auditstate) <= __alignof (struct link_map_rw), + "auditstate alignment compatible with link_map_rw alignment"); /* This is the hidden instance of struct r_debug_extended used by the diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 12271c37f3..cdba342f99 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -396,11 +396,6 @@ struct rtld_global /* Structure describing the dynamic linker itself. */ EXTERN struct link_map_private _dl_rtld_map; -#ifdef SHARED - /* Used to store the audit information for the link map of the - dynamic loader. */ - struct auditstate _dl_rtld_auditstate[DL_NNS]; -#endif #if !PTHREAD_IN_LIBC && defined SHARED \ && defined __rtld_lock_default_lock_recursive @@ -1323,15 +1318,9 @@ rtld_active (void) static inline struct auditstate * link_map_audit_state (struct link_map_private *l, size_t index) { - if (l == &GL (dl_rtld_map)) - /* The auditstate array is stored separately. */ - return &GL (dl_rtld_auditstate) [index]; - else - { - /* The auditstate array follows the link map in memory. */ - struct auditstate *base = (struct auditstate *) (l + 1); - return &base[index]; - } + /* The auditstate array follows the read-write link map part in memory. */ + struct auditstate *base = (struct auditstate *) (l->l_rw + 1); + return &base[index]; } /* Call the la_objsearch from the audit modules from the link map L. If