ld.so: Always use MAP_COPY to map the first segment [BZ #30452]
commit6259ab39410cdefc80077afea48ca9cb057f6005
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 22 Jun 2023 21:30:31 +0000 (22 14:30 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 30 Jun 2023 17:42:42 +0000 (30 10:42 -0700)
treef8f3550b1563e2312598dc5618f6d2ab4f48ee0a
parent9401024e5e6be0e1c3870e185daae865cd4501f4
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.
elf/dl-map-segments.h
sysdeps/x86_64/64/Makefile
sysdeps/x86_64/64/tst-map-32bit-2.c [new file with mode: 0644]
sysdeps/x86_64/64/tst-map-32bit-mod-2.c [new file with mode: 0644]