From patchwork Sun Feb 2 21:13:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 105880 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 D94A33858C41 for ; Sun, 2 Feb 2025 21:19:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D94A33858C41 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ea1hWdZE 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 354AD3858D1E for ; Sun, 2 Feb 2025 21:13:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 354AD3858D1E 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 354AD3858D1E 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=1738530825; cv=none; b=ffb7owHvMuzE4ECfw4qQogFMwKv2Kls5Qn3YJSpdKaJHPnydYDMXx2HMoo/VeMCvVQ6t1QwJKzpKqW8rN28GcgILtOJ2/O/LWDo+11IvFA5yKq+6H4DTL0ozb0DhPlEOapvJ6Z53d3XACLtBRh8gMtaH8QStDlE4/VeYMUb51ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738530825; c=relaxed/simple; bh=81TuKzXIm6WdBT0Hw/yZq7zUF/2FJwlnMFzLL60WaIY=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=FeJNfI0uOx9dgJVkgNzPBSWqyngdq/0UW/TBeMk37kTjAnEr8qXTz8Z01plPJ9w6BuMGswwEaQhRb658Olz44/LyHxUQVKm+/eaiWyOlyqGXFeRvhZ/PSNTH7F+QTzD4wWta2/iQcu55vL8eug/B3uZhoMntcx2vQG6tGF/nJoQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 354AD3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738530825; 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=fU4x3+3yg6FrsPc2F27nKj5dugQbv6G1aAjP30nqcWM=; b=Ea1hWdZE/zuPRyNF4wnAwFi7FPen2ovHSjX/xkb1borcOblmFqvKMQs+vIXyyrnNFGvMt1 qedphV145ZBdzYeuzF6+c+bexUtEIkbzd0Old2pyW+2YxUO2igymBsu0Z7zMAVVu529b8Y vaFwJoBunMC5Y4it14AlQEt148UZCkU= 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-522-P52rhJGDO4qN_EZDdNT99g-1; Sun, 02 Feb 2025 16:13:43 -0500 X-MC-Unique: P52rhJGDO4qN_EZDdNT99g-1 X-Mimecast-MFC-AGG-ID: P52rhJGDO4qN_EZDdNT99g Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 BA93B1956080 for ; Sun, 2 Feb 2025 21:13:42 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.2]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C40DF180035E for ; Sun, 2 Feb 2025 21:13:41 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v4 09/14] elf: Introduce GLPM accessor for the protected memory area In-Reply-To: Message-ID: References: X-From-Line: f61a140e7b885524911e21f4f3cfe56b9a9e40d1 Mon Sep 17 00:00:00 2001 Date: Sun, 02 Feb 2025 22:13:38 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MmfgQMeBDOOiEp7ibU7KslmOI4sPr4mmf0cuAJv-7KM_1738530822 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_H2, 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~patchwork=sourceware.org@sourceware.org The memory area is still allocated in the data segment, so this change is preparatory only. --- elf/dl-load.c | 10 +-- elf/rtld.c | 129 +++++++++++++++++++------------------ elf/setup-vdso.h | 4 +- sysdeps/generic/ldsodefs.h | 22 +++++-- 4 files changed, 91 insertions(+), 74 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 2e6c58dfcc..06cbedd8a7 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -733,7 +733,7 @@ _dl_init_paths (const char *llp, const char *source, l = GL(dl_ns)[LM_ID_BASE]._ns_loaded; #ifdef SHARED if (l == NULL) - l = &_dl_rtld_map; + l = &GLPM(dl_rtld_map); #endif assert (l->l_type != lt_loaded); @@ -988,8 +988,8 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, /* When loading into a namespace other than the base one we must avoid loading ld.so since there can only be one copy. Ever. */ if (__glibc_unlikely (nsid != LM_ID_BASE) - && (_dl_file_id_match_p (&id, &_dl_rtld_map.l_file_id) - || _dl_name_match_p (name, &_dl_rtld_map))) + && (_dl_file_id_match_p (&id, &GLPM(dl_rtld_map).l_file_id) + || _dl_name_match_p (name, &GLPM(dl_rtld_map)))) { /* This is indeed ld.so. Create a new link_map which refers to the real one for almost everything. */ @@ -998,7 +998,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, goto fail_new; /* Refer to the real descriptor. */ - l->l_real = &_dl_rtld_map; + l->l_real = &GLPM(dl_rtld_map); /* Copy l_addr and l_ld to avoid a GDB warning with dlmopen(). */ l->l_addr = l->l_real->l_addr; @@ -2034,7 +2034,7 @@ _dl_map_new_object (struct link_map *loader, const char *name, l = (loader ?: GL(dl_ns)[LM_ID_BASE]._ns_loaded # ifdef SHARED - ?: &_dl_rtld_map + ?: &GLPM(dl_rtld_map) # endif ); diff --git a/elf/rtld.c b/elf/rtld.c index 1bb369ef2b..0bc7d9dbcd 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -345,6 +345,7 @@ struct rtld_global _rtld_global = extern struct rtld_global _rtld_local __attribute__ ((alias ("_rtld_global"), visibility ("hidden"))); +struct rtld_protmem _rtld_protmem; /* This variable is similar to _rtld_local, but all values are read-only after relocation. */ @@ -466,9 +467,9 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) struct link_map_rw l; struct auditstate _dl_rtld_auditstate[DL_NNS]; } rtld_map_rw; - _dl_rtld_map.l_rw = &rtld_map_rw.l; + GLPM(dl_rtld_map).l_rw = &rtld_map_rw.l; #if NO_TLS_OFFSET != 0 - _dl_rtld_map.l_rw->l_tls_offset = NO_TLS_OFFSET; + GLPM(dl_rtld_map).l_rw->l_tls_offset = NO_TLS_OFFSET; #endif /* If it hasn't happen yet record the startup time. */ @@ -479,21 +480,22 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) /* Transfer data about ourselves to the permanent link_map structure. */ #ifndef DONT_USE_BOOTSTRAP_MAP - _dl_rtld_map.l_addr = info->l.l_addr; - _dl_rtld_map.l_ld = info->l.l_ld; - _dl_rtld_map.l_ld_readonly = info->l.l_ld_readonly; - memcpy (_dl_rtld_map.l_info, info->l.l_info, sizeof _dl_rtld_map.l_info); - _dl_rtld_map.l_mach = info->l.l_mach; - _dl_rtld_map.l_relocated = 1; + GLPM(dl_rtld_map).l_addr = info->l.l_addr; + GLPM(dl_rtld_map).l_ld = info->l.l_ld; + GLPM(dl_rtld_map).l_ld_readonly = info->l.l_ld_readonly; + memcpy (GLPM(dl_rtld_map).l_info, info->l.l_info, + sizeof GLPM(dl_rtld_map).l_info); + GLPM(dl_rtld_map).l_mach = info->l.l_mach; + GLPM(dl_rtld_map).l_relocated = 1; #endif - _dl_setup_hash (&_dl_rtld_map); - _dl_rtld_map.l_real = &_dl_rtld_map; - _dl_rtld_map.l_map_start = (ElfW(Addr)) &__ehdr_start; - _dl_rtld_map.l_map_end = (ElfW(Addr)) _end; + _dl_setup_hash (&GLPM(dl_rtld_map)); + GLPM(dl_rtld_map).l_real = &GLPM(dl_rtld_map); + GLPM(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start; + GLPM(dl_rtld_map).l_map_end = (ElfW(Addr)) _end; /* Copy the TLS related data if necessary. */ #ifndef DONT_USE_BOOTSTRAP_MAP # if NO_TLS_OFFSET != 0 - _dl_rtld_map.l_rw->l_tls_offset = NO_TLS_OFFSET; + GLPM(dl_rtld_map).l_rw->l_tls_offset = NO_TLS_OFFSET; # endif #endif @@ -520,7 +522,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) } #ifdef DONT_USE_BOOTSTRAP_MAP -# define bootstrap_map _dl_rtld_map +# define bootstrap_map GLPM(dl_rtld_map) #else # define bootstrap_map info.l #endif @@ -1024,8 +1026,8 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d); /* The dynamic linker link map is statically allocated, so the cookie in _dl_new_object has not happened. */ - link_map_audit_state (&_dl_rtld_map, GLRO (dl_naudit))->cookie - = (intptr_t) &_dl_rtld_map; + link_map_audit_state (&GLPM(dl_rtld_map), GLRO (dl_naudit))->cookie + = (intptr_t) &GLPM(dl_rtld_map); ++GLRO(dl_naudit); @@ -1052,7 +1054,7 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list) if (GLRO(dl_naudit) > 0) { _dl_audit_objopen (main_map, LM_ID_BASE); - _dl_audit_objopen (&_dl_rtld_map, LM_ID_BASE); + _dl_audit_objopen (&GLPM(dl_rtld_map), LM_ID_BASE); } } @@ -1062,7 +1064,7 @@ static void rtld_chain_load (struct link_map *main_map, char *argv0) { /* The dynamic loader run against itself. */ - const char *rtld_soname = l_soname (&_dl_rtld_map); + const char *rtld_soname = l_soname (&GLPM(dl_rtld_map)); if (l_soname (main_map) != NULL && strcmp (rtld_soname, l_soname (main_map)) == 0) _dl_fatal_printf ("%s: loader cannot load itself\n", rtld_soname); @@ -1149,7 +1151,7 @@ rtld_setup_main_map (struct link_map *main_map) _dl_rtld_libname.name = ((const char *) main_map->l_addr + ph->p_vaddr); /* _dl_rtld_libname.next = NULL; Already zero. */ - _dl_rtld_map.l_libname = &_dl_rtld_libname; + GLPM(dl_rtld_map).l_libname = &_dl_rtld_libname; has_interp = true; break; @@ -1231,16 +1233,16 @@ rtld_setup_main_map (struct link_map *main_map) = (char *) main_map->l_tls_initimage + main_map->l_addr; if (! main_map->l_map_end) main_map->l_map_end = ~0; - if (! _dl_rtld_map.l_libname && _dl_rtld_map.l_name) + if (! GLPM(dl_rtld_map).l_libname && GLPM(dl_rtld_map).l_name) { /* We were invoked directly, so the program might not have a PT_INTERP. */ - _dl_rtld_libname.name = _dl_rtld_map.l_name; + _dl_rtld_libname.name = GLPM(dl_rtld_map).l_name; /* _dl_rtld_libname.next = NULL; Already zero. */ - _dl_rtld_map.l_libname = &_dl_rtld_libname; + GLPM(dl_rtld_map).l_libname = &_dl_rtld_libname; } else - assert (_dl_rtld_map.l_libname); /* How else did we get here? */ + assert (GLPM(dl_rtld_map).l_libname); /* How else did we get here? */ return has_interp; } @@ -1352,7 +1354,7 @@ dl_main (const ElfW(Phdr) *phdr, char **orig_argv = _dl_argv; /* Note the place where the dynamic linker actually came from. */ - _dl_rtld_map.l_name = rtld_progname; + GLPM(dl_rtld_map).l_name = rtld_progname; while (_dl_argc > 1) if (! strcmp (_dl_argv[1], "--list")) @@ -1636,22 +1638,22 @@ dl_main (const ElfW(Phdr) *phdr, /* If the current libname is different from the SONAME, add the latter as well. */ { - const char *soname = l_soname (&_dl_rtld_map); + const char *soname = l_soname (&GLPM(dl_rtld_map)); if (soname != NULL - && strcmp (_dl_rtld_map.l_libname->name, soname) != 0) + && strcmp (GLPM(dl_rtld_map).l_libname->name, soname) != 0) { static struct libname_list newname; newname.name = soname; newname.next = NULL; newname.dont_free = 1; - assert (_dl_rtld_map.l_libname->next == NULL); - _dl_rtld_map.l_libname->next = &newname; + assert (GLPM(dl_rtld_map).l_libname->next == NULL); + GLPM(dl_rtld_map).l_libname->next = &newname; } } /* The ld.so must be relocated since otherwise loading audit modules will fail since they reuse the very same ld.so. */ - assert (_dl_rtld_map.l_relocated); + assert (GLPM(dl_rtld_map).l_relocated); if (! rtld_is_main) { @@ -1681,7 +1683,7 @@ dl_main (const ElfW(Phdr) *phdr, _exit (has_interp ? 0 : 2); } - struct link_map **first_preload = &_dl_rtld_map.l_next; + struct link_map **first_preload = &GLPM(dl_rtld_map).l_next; /* Set up the data structures for the system-supplied DSO early, so they can influence _dl_init_paths. */ setup_vdso (main_map, &first_preload); @@ -1694,20 +1696,20 @@ dl_main (const ElfW(Phdr) *phdr, call_init_paths (&state); /* Initialize _r_debug_extended. */ - struct r_debug *r = _dl_debug_initialize (_dl_rtld_map.l_addr, + struct r_debug *r = _dl_debug_initialize (GLPM(dl_rtld_map).l_addr, LM_ID_BASE); r->r_state = RT_CONSISTENT; /* Put the link_map for ourselves on the chain so it can be found by name. Note that at this point the global chain of link maps contains exactly one element, which is pointed to by dl_loaded. */ - if (! _dl_rtld_map.l_name) + if (! GLPM(dl_rtld_map).l_name) /* If not invoked directly, the dynamic linker shared object file was found by the PT_INTERP name. */ - _dl_rtld_map.l_name = (char *) _dl_rtld_map.l_libname->name; - _dl_rtld_map.l_type = lt_library; - main_map->l_next = &_dl_rtld_map; - _dl_rtld_map.l_prev = main_map; + GLPM(dl_rtld_map).l_name = (char *) GLPM(dl_rtld_map).l_libname->name; + GLPM(dl_rtld_map).l_type = lt_library; + main_map->l_next = &GLPM(dl_rtld_map); + GLPM(dl_rtld_map).l_prev = main_map; ++GL(dl_ns)[LM_ID_BASE]._ns_nloaded; ++GL(dl_load_adds); @@ -1725,8 +1727,8 @@ dl_main (const ElfW(Phdr) *phdr, const ElfW(Phdr) *rtld_phdr = (const void *) rtld_ehdr + rtld_ehdr->e_phoff; - _dl_rtld_map.l_phdr = rtld_phdr; - _dl_rtld_map.l_phnum = rtld_ehdr->e_phnum; + GLPM(dl_rtld_map).l_phdr = rtld_phdr; + GLPM(dl_rtld_map).l_phnum = rtld_ehdr->e_phnum; /* PT_GNU_RELRO is usually the last phdr. */ @@ -1734,15 +1736,15 @@ dl_main (const ElfW(Phdr) *phdr, while (cnt-- > 0) if (rtld_phdr[cnt].p_type == PT_GNU_RELRO) { - _dl_rtld_map.l_relro_addr = rtld_phdr[cnt].p_vaddr; - _dl_rtld_map.l_relro_size = rtld_phdr[cnt].p_memsz; + GLPM(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr; + GLPM(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz; break; } /* Add the dynamic linker to the TLS list if it also uses TLS. */ - if (_dl_rtld_map.l_tls_blocksize != 0) + if (GLPM(dl_rtld_map).l_tls_blocksize != 0) /* Assign a module ID. Do this before loading any audit modules. */ - _dl_assign_tls_modid (&_dl_rtld_map); + _dl_assign_tls_modid (&GLPM(dl_rtld_map)); audit_list_add_dynamic_tag (&state.audit_list, main_map, DT_AUDIT); audit_list_add_dynamic_tag (&state.audit_list, main_map, DT_DEPAUDIT); @@ -1935,30 +1937,30 @@ dl_main (const ElfW(Phdr) *phdr, for (i = main_map->l_searchlist.r_nlist; i > 0; ) main_map->l_searchlist.r_list[--i]->l_global = 1; - /* Remove _dl_rtld_map from the chain. */ - _dl_rtld_map.l_prev->l_next = _dl_rtld_map.l_next; - if (_dl_rtld_map.l_next != NULL) - _dl_rtld_map.l_next->l_prev = _dl_rtld_map.l_prev; + /* Remove GLPM(dl_rtld_map) from the chain. */ + GLPM(dl_rtld_map).l_prev->l_next = GLPM(dl_rtld_map).l_next; + if (GLPM(dl_rtld_map).l_next != NULL) + GLPM(dl_rtld_map).l_next->l_prev = GLPM(dl_rtld_map).l_prev; for (i = 1; i < main_map->l_searchlist.r_nlist; ++i) - if (is_rtld_link_map (main_map->l_searchlist.r_list[i])) + if (main_map->l_searchlist.r_list[i] == &GLPM(dl_rtld_map)) break; /* Insert the link map for the dynamic loader into the chain in symbol search order because gdb uses the chain's order as its symbol search order. */ - _dl_rtld_map.l_prev = main_map->l_searchlist.r_list[i - 1]; + GLPM(dl_rtld_map).l_prev = main_map->l_searchlist.r_list[i - 1]; if (__glibc_likely (state.mode == rtld_mode_normal)) { - _dl_rtld_map.l_next = (i + 1 < main_map->l_searchlist.r_nlist - ? main_map->l_searchlist.r_list[i + 1] - : NULL); + GLPM(dl_rtld_map).l_next = (i + 1 < main_map->l_searchlist.r_nlist + ? main_map->l_searchlist.r_list[i + 1] + : NULL); #ifdef NEED_DL_SYSINFO_DSO if (GLRO(dl_sysinfo_map) != NULL - && _dl_rtld_map.l_prev->l_next == GLRO(dl_sysinfo_map) - && _dl_rtld_map.l_next != GLRO(dl_sysinfo_map)) - _dl_rtld_map.l_prev = GLRO(dl_sysinfo_map); + && (GLPM(dl_rtld_map).l_prev->l_next == GLRO(dl_sysinfo_map)) + && (GLPM(dl_rtld_map).l_next != GLRO(dl_sysinfo_map))) + GLPM(dl_rtld_map).l_prev = GLRO(dl_sysinfo_map); #endif } else @@ -1967,14 +1969,14 @@ dl_main (const ElfW(Phdr) *phdr, In this case it doesn't matter much where we put the interpreter object, so we just initialize the list pointer so that the assertion below holds. */ - _dl_rtld_map.l_next = _dl_rtld_map.l_prev->l_next; + GLPM(dl_rtld_map).l_next = GLPM(dl_rtld_map).l_prev->l_next; - assert (_dl_rtld_map.l_prev->l_next == _dl_rtld_map.l_next); - _dl_rtld_map.l_prev->l_next = &_dl_rtld_map; - if (_dl_rtld_map.l_next != NULL) + assert (GLPM(dl_rtld_map).l_prev->l_next == GLPM(dl_rtld_map).l_next); + GLPM(dl_rtld_map).l_prev->l_next = &GLPM(dl_rtld_map); + if (GLPM(dl_rtld_map).l_next != NULL) { - assert (_dl_rtld_map.l_next->l_prev == _dl_rtld_map.l_prev); - _dl_rtld_map.l_next->l_prev = &_dl_rtld_map; + assert (GLPM(dl_rtld_map).l_next->l_prev == GLPM(dl_rtld_map).l_prev); + GLPM(dl_rtld_map).l_next->l_prev = &GLPM(dl_rtld_map); } /* Now let us see whether all libraries are available in the @@ -2116,7 +2118,7 @@ dl_main (const ElfW(Phdr) *phdr, while (i-- > 0) { struct link_map *l = main_map->l_initfini[i]; - if (l != &_dl_rtld_map && ! l->l_faked) + if (l != &GLPM(dl_rtld_map) && ! l->l_faked) { args.l = l; _dl_receive_error (print_unresolved, relocate_doit, @@ -2315,7 +2317,8 @@ dl_main (const ElfW(Phdr) *phdr, { RTLD_TIMING_VAR (start); rtld_timer_start (&start); - _dl_relocate_object_no_relro (&_dl_rtld_map, main_map->l_scope, 0, 0); + _dl_relocate_object_no_relro (&GLPM(dl_rtld_map), main_map->l_scope, + 0, 0); rtld_timer_accum (&relocate_time, start); __rtld_mutex_init (); @@ -2323,7 +2326,7 @@ dl_main (const ElfW(Phdr) *phdr, } /* All ld.so initialization is complete. Apply RELRO. */ - _dl_protect_relro (&_dl_rtld_map); + _dl_protect_relro (&GLPM(dl_rtld_map)); /* Relocation is complete. Perform early libc initialization. This is the initial libc, even if audit modules have been loaded with diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h index 935d9e3baf..fd5a1314bd 100644 --- a/elf/setup-vdso.h +++ b/elf/setup-vdso.h @@ -92,8 +92,8 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)), /* Rearrange the list so this DSO appears after rtld_map. */ assert (l->l_next == NULL); assert (l->l_prev == main_map); - _dl_rtld_map.l_next = l; - l->l_prev = &_dl_rtld_map; + GLPM(dl_rtld_map).l_next = l; + l->l_prev = &GLPM(dl_rtld_map); *first_preload = &l->l_next; # else GL(dl_nns) = 1; diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 6973fe6dbe..ac71668f29 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -508,6 +508,23 @@ extern struct rtld_global _rtld_global __rtld_global_attribute__; # undef __rtld_global_attribute__ #endif +#ifdef SHARED +/* Implementation structure for the protected memory area. */ +struct rtld_protmem +{ + /* Structure describing the dynamic linker itself. */ + struct link_map _dl_rtld_map; +}; +extern struct rtld_protmem _rtld_protmem attribute_hidden; +#endif /* SHARED */ + +/* GLPM(FIELD) denotes the FIELD in the protected memory area. */ +#ifdef SHARED +# define GLPM(name) _rtld_protmem._##name +#else +# define GLPM(name) _##name +#endif + #ifndef SHARED # define GLRO(name) _##name #else @@ -1325,9 +1342,6 @@ rtld_active (void) return GLRO(dl_init_all_dirs) != NULL; } -/* Pre-allocated link map for the dynamic linker itself. */ -extern struct link_map _dl_rtld_map attribute_hidden; - /* Used to store the audit information for the link map of the dynamic loader. */ extern struct auditstate _dl_rtld_auditstate[DL_NNS] attribute_hidden; @@ -1336,7 +1350,7 @@ extern struct auditstate _dl_rtld_auditstate[DL_NNS] attribute_hidden; static inline bool is_rtld_link_map (const struct link_map *l) { - return l == &_dl_rtld_map; + return l == &GLPM(dl_rtld_map); } static inline struct auditstate *