public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stas Sergeev <stsp2@yandex.ru>
To: libc-alpha@sourceware.org
Cc: Stas Sergeev <stsp2@yandex.ru>
Subject: [PATCH 02/14] use initial mmap also for ET_EXEC
Date: Thu, 18 May 2023 13:28:42 +0500	[thread overview]
Message-ID: <20230518082854.3903342-3-stsp2@yandex.ru> (raw)
In-Reply-To: <20230518082854.3903342-1-stsp2@yandex.ru>

This allows to replace the further anonymous mmaps with mprotect.
Which, in turn, will allow to split the protection stage in the
subsequent patches.

The test-suite was run on x86_64/64 and showed no regressions.

Signed-off-by: Stas Sergeev <stsp2@yandex.ru>
---
 elf/dl-map-segments.h | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index ed7675cabf..6a6127f773 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -129,7 +129,12 @@ _dl_map_segments (struct link_map *l, int fd,
   else
     {
       /* Remember which part of the address space this object uses.  */
-      l->l_map_start = c->mapstart + l->l_addr;
+      l->l_map_start = (ElfW(Addr)) __mmap ((caddr_t) l->l_addr + c->mapstart,
+                                            maplength, PROT_NONE,
+                                            MAP_ANON|MAP_PRIVATE|MAP_FIXED,
+                                            -1, 0);
+      if (__glibc_unlikely ((void *) l->l_map_start == MAP_FAILED))
+        return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT;
       l->l_map_end = l->l_map_start + maplength;
       l->l_contiguous = !has_holes;
     }
@@ -182,13 +187,11 @@ _dl_map_segments (struct link_map *l, int fd,
 
           if (zeroend > zeropage)
             {
-              /* Map the remaining zero pages in from the zero fill FD.  */
-              caddr_t mapat;
-              mapat = __mmap ((caddr_t) zeropage, zeroend - zeropage,
-                              c->prot, MAP_ANON|MAP_PRIVATE|MAP_FIXED,
-                              -1, 0);
-              if (__glibc_unlikely (mapat == MAP_FAILED))
-                return DL_MAP_SEGMENTS_ERROR_MAP_ZERO_FILL;
+              /* Protect the remaining zero pages.  */
+              if (__glibc_unlikely (__mprotect ((caddr_t) zeropage,
+                                                zeroend - zeropage,
+                                                c->prot) < 0))
+                return DL_MAP_SEGMENTS_ERROR_MPROTECT;
             }
         }
 
-- 
2.39.2


  parent reply	other threads:[~2023-05-18  8:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-18  8:28 [PATCH 00/14] implement RTLD_NORELOCATE api [BZ #30007] Stas Sergeev
2023-05-18  8:28 ` [PATCH 01/14] elf: switch _dl_map_segment() to anonymous mapping Stas Sergeev
2023-05-18  8:28 ` Stas Sergeev [this message]
2023-05-18  8:28 ` [PATCH 03/14] rework maphole Stas Sergeev
2023-05-18  8:28 ` [PATCH 04/14] split do_reloc_1() from dl_open_worker_begin() Stas Sergeev
2023-05-18  8:28 ` [PATCH 05/14] split do_reloc_2() out of do_open_worker() Stas Sergeev
2023-05-18  8:28 ` [PATCH 06/14] move relocation into _dl_object_reloc() func Stas Sergeev
2023-05-18  8:28 ` [PATCH 07/14] split out _dl_finalize_segments() Stas Sergeev
2023-05-18  8:28 ` [PATCH 08/14] finalize elf segments on a relocation step Stas Sergeev
2023-05-18  8:28 ` [PATCH 09/14] implement RTLD_NORELOCATE dlopen() flag Stas Sergeev
2023-05-18  8:28 ` [PATCH 10/14] add test-case for RTLD_NORELOCATE Stas Sergeev
2023-05-18  8:28 ` [PATCH 11/14] implement dlrelocate() function Stas Sergeev
2023-05-18  8:28 ` [PATCH 12/14] implement RTLD_DI_MAPINFO dlinfo() request Stas Sergeev
2023-05-18  8:28 ` [PATCH 13/14] implement dlset_object_base() function Stas Sergeev
2023-05-18  8:28 ` [PATCH 14/14] implement RTLD_DI_DEPLIST dlinfo() request Stas Sergeev

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230518082854.3903342-3-stsp2@yandex.ru \
    --to=stsp2@yandex.ru \
    --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).