From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH v3 17/32] elf: Allocate auditor state after read-write link map
Date: Thu, 07 Dec 2023 11:32:07 +0100 [thread overview]
Message-ID: <2135e6ae1fe527d3aa74666e6d609972a147f587.1701944612.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1701944612.git.fweimer@redhat.com>
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 25a9c8aa58..b2f0b478bb 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 220926248c..c752bc2cb7 100644
--- a/include/link.h
+++ b/include/link.h
@@ -372,15 +372,16 @@ l_next (struct link_map_private *l)
#include <dl-relocate-ld.h>
-/* 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
- <ldsodefs.h>. */
+/* 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 53cc428421..d6d45f8c69 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
--
2.43.0
next prev parent reply other threads:[~2023-12-07 10:32 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 10:30 [PATCH v3 00/32] RELRO linkmaps Florian Weimer
2023-12-07 10:30 ` [PATCH v3 01/32] support: Add <support/memprobe.h> for protection flags probing Florian Weimer
2024-02-22 22:39 ` Joseph Myers
2023-12-07 10:30 ` [PATCH v3 02/32] misc: Enable internal use of memory protection keys Florian Weimer
2024-02-22 1:06 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 03/32] elf: Remove _dl_sysdep_open_object hook function Florian Weimer
2024-01-31 13:10 ` Joseph Myers
2024-03-11 17:19 ` Florian Weimer
2024-03-11 17:33 ` Joseph Myers
2024-03-11 17:46 ` Florian Weimer
2024-03-11 18:02 ` Joseph Myers
2024-03-11 18:16 ` Florian Weimer
2023-12-07 10:31 ` [PATCH v3 04/32] elf: Eliminate second loop in find_version in dl-version.c Florian Weimer
2024-02-19 22:17 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 05/32] elf: In rtld_setup_main_map, assume ld.so has a DYNAMIC segment Florian Weimer
2024-02-19 22:18 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 06/32] elf: Remove version assert in check_match in elf/dl-lookup.c Florian Weimer
2024-03-04 23:22 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 07/32] elf: Disambiguate some failures in _dl_load_cache_lookup Florian Weimer
2024-02-19 23:07 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 08/32] elf: Eliminate alloca in open_verify Florian Weimer
2024-02-19 23:26 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 09/32] Do not export <alloc_buffer.h> functions from libc Florian Weimer
2024-02-21 17:13 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 10/32] elf: Make <alloc_buffer.h> usable in ld.so Florian Weimer
2024-02-21 17:19 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 11/32] elf: Merge the three implementations of _dl_dst_substitute Florian Weimer
2024-02-28 17:52 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 12/32] elf: Move __rtld_malloc_init_stubs call into _dl_start_final Florian Weimer
2024-02-22 22:30 ` Joseph Myers
2024-02-22 23:06 ` Andreas Schwab
2023-12-07 10:31 ` [PATCH v3 13/32] elf: Merge __dl_libc_freemem into __rtld_libc_freeres Florian Weimer
2024-02-22 23:23 ` Joseph Myers
2023-12-07 10:31 ` [PATCH v3 14/32] elf: Use struct link_map_private for the internal link map Florian Weimer
2024-02-22 23:36 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 15/32] elf: Remove run-time-writable fields from struct link_map_private Florian Weimer
2024-02-23 0:09 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 16/32] elf: Move l_tls_offset into read-write part of link map Florian Weimer
2024-02-26 21:57 ` Joseph Myers
2023-12-07 10:32 ` Florian Weimer [this message]
2024-02-26 22:01 ` [PATCH v3 17/32] elf: Allocate auditor state after read-write " Joseph Myers
2023-12-07 10:32 ` [PATCH v3 18/32] elf: Move link map fields used by dependency sorting to writable part Florian Weimer
2024-02-27 17:51 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 19/32] elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object Florian Weimer
2024-02-27 17:56 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 20/32] elf: Add l_soname accessor function for DT_SONAME values Florian Weimer
2024-02-27 22:14 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 21/32] elf: _dl_rtld_map should not exist in static builds Florian Weimer
2024-02-28 12:38 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 22/32] elf: Introduce GLPM accessor for the protected memory area Florian Weimer
2024-02-28 12:44 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 23/32] elf: Bootstrap allocation for future protected memory allocator Florian Weimer
2024-02-28 15:04 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 24/32] elf: Implement a basic " Florian Weimer
2024-02-28 18:46 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 25/32] elf: Move most of the _dl_find_object data to the protected heap Florian Weimer
2024-02-28 19:06 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 26/32] elf: Switch to a region-based protected memory allocator Florian Weimer
2024-03-05 23:36 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 27/32] elf: Determine the caller link map in _dl_open Florian Weimer
2024-02-28 19:23 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 28/32] elf: Add fast path to dlopen for fully-opened maps Florian Weimer
2024-02-28 19:26 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 29/32] elf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen Florian Weimer
2024-02-28 19:27 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 30/32] elf: Put critical _dl_find_object pointers into protected memory area Florian Weimer
2024-03-04 21:39 ` Joseph Myers
2023-12-07 10:32 ` [PATCH v3 31/32] elf: Add hash tables to speed up DT_NEEDED, dlopen lookups Florian Weimer
2024-03-06 0:04 ` Joseph Myers
2023-12-07 10:33 ` [PATCH v3 32/32] elf: Use memory protection keys for the protected memory allocator Florian Weimer
2024-03-06 0:11 ` Joseph Myers
2023-12-07 10:53 ` [PATCH v3 00/32] RELRO linkmaps Andreas Schwab
2023-12-07 10:56 ` Florian Weimer
2023-12-07 11:34 ` Andreas Schwab
2024-03-01 14:45 ` Adhemerval Zanella Netto
2024-03-11 17:24 ` Florian Weimer
2024-03-12 12:51 ` Adhemerval Zanella Netto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2135e6ae1fe527d3aa74666e6d609972a147f587.1701944612.git.fweimer@redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).