public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: H.J. Lu <hjl@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] ld.so: Always use MAP_COPY to map the first segment [BZ #30452] Date: Fri, 30 Jun 2023 17:43:14 +0000 (GMT) [thread overview] Message-ID: <20230630174314.972CB3858C27@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6259ab39410cdefc80077afea48ca9cb057f6005 commit 6259ab39410cdefc80077afea48ca9cb057f6005 Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Jun 22 14:30:31 2023 -0700 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. Diff: --- elf/dl-map-segments.h | 2 +- sysdeps/x86_64/64/Makefile | 7 +++++++ sysdeps/x86_64/64/tst-map-32bit-2.c | 1 + sysdeps/x86_64/64/tst-map-32bit-mod-2.c | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) 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; diff --git a/sysdeps/x86_64/64/Makefile b/sysdeps/x86_64/64/Makefile index 73fcfe0bb0..17f0081b19 100644 --- a/sysdeps/x86_64/64/Makefile +++ b/sysdeps/x86_64/64/Makefile @@ -3,13 +3,16 @@ ifeq ($(subdir),elf) tests-map-32bit = \ tst-map-32bit-1a \ tst-map-32bit-1b \ + tst-map-32bit-2 \ # tests-map-32bit tst-map-32bit-1a-no-pie = yes tst-map-32bit-1b-no-pie = yes +tst-map-32bit-2-no-pie = yes tests += $(tests-map-32bit) modules-map-32bit = \ tst-map-32bit-mod \ + tst-map-32bit-mod-2 \ # modules-map-32bit modules-names += $(modules-map-32bit) @@ -18,5 +21,9 @@ tst-map-32bit-1a-ENV = LD_PREFER_MAP_32BIT_EXEC=1 $(objpfx)tst-map-32bit-1a: $(objpfx)tst-map-32bit-mod.so tst-map-32bit-1b-ENV = GLIBC_TUNABLES=glibc.cpu.prefer_map_32bit_exec=1 $(objpfx)tst-map-32bit-1b: $(objpfx)tst-map-32bit-mod.so +LDFLAGS-tst-map-32bit-mod-2.so += -Wl,-z,max-page-size=0x200000 +$(objpfx)tst-map-32bit-mod-2.so: $(libsupport) +tst-map-32bit-2-ENV = LD_PREFER_MAP_32BIT_EXEC=1 +$(objpfx)tst-map-32bit-2: $(objpfx)tst-map-32bit-mod-2.so endif diff --git a/sysdeps/x86_64/64/tst-map-32bit-2.c b/sysdeps/x86_64/64/tst-map-32bit-2.c new file mode 100644 index 0000000000..34ab01c773 --- /dev/null +++ b/sysdeps/x86_64/64/tst-map-32bit-2.c @@ -0,0 +1 @@ +#include "tst-map-32bit-1a.c" diff --git a/sysdeps/x86_64/64/tst-map-32bit-mod-2.c b/sysdeps/x86_64/64/tst-map-32bit-mod-2.c new file mode 100644 index 0000000000..69e795c024 --- /dev/null +++ b/sysdeps/x86_64/64/tst-map-32bit-mod-2.c @@ -0,0 +1 @@ +#include "tst-map-32bit-mod.c"
reply other threads:[~2023-06-30 17:43 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230630174314.972CB3858C27@sourceware.org \ --to=hjl@sourceware.org \ --cc=glibc-cvs@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: linkBe 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).