about summary refs log tree commit diff
path: root/elf
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2023-06-22 14:30:31 -0700
committerH.J. Lu <hjl.tools@gmail.com>2023-06-30 10:42:42 -0700
commit6259ab39410cdefc80077afea48ca9cb057f6005 (patch)
treef8f3550b1563e2312598dc5618f6d2ab4f48ee0a /elf
parent9401024e5e6be0e1c3870e185daae865cd4501f4 (diff)
downloadglibc-6259ab39410cdefc80077afea48ca9cb057f6005.tar.gz
glibc-6259ab39410cdefc80077afea48ca9cb057f6005.tar.xz
glibc-6259ab39410cdefc80077afea48ca9cb057f6005.zip
ld.so: Always use MAP_COPY to map the first segment [BZ #30452]
The first segment in a shared library may be read-only, not executable.
To support LD_PREFER_MAP_32BIT_EXEC on such shared libraries, we also
check MAP_DENYWRITE to decide if MAP_32BIT should be passed to mmap.
Normally the first segment is mapped with MAP_COPY, which is defined
as (MAP_PRIVATE | MAP_DENYWRITE).  But if the segment alignment is
greater than the page size, MAP_COPY isn't used to allocate enough
space to ensure that the segment can be properly aligned.  Map the
first segment with MAP_COPY in this case to fix BZ #30452.
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-map-segments.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index 504cfc0a41..ac10182d58 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -36,7 +36,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref,
 		       : (2 * c->mapalign));
   ElfW(Addr) map_start = (ElfW(Addr)) __mmap ((void *) mappref, maplen,
 					      PROT_NONE,
-					      MAP_ANONYMOUS|MAP_PRIVATE,
+					      MAP_ANONYMOUS|MAP_COPY,
 					      -1, 0);
   if (__glibc_unlikely ((void *) map_start == MAP_FAILED))
     return map_start;