aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2021-01-04 18:55:44 +0000
committerEd Maste <emaste@FreeBSD.org>2021-01-05 15:57:14 +0000
commit613a08cfa2e0fb1b99906961c7a676d527e17f05 (patch)
treee53c5998548f58adfa12469af4e08a6634732f0b
parentbed70f83ac77b4d948fad9f198b6b39a5110c2af (diff)
downloadsrc-613a08cfa2e0fb1b99906961c7a676d527e17f05.tar.gz
src-613a08cfa2e0fb1b99906961c7a676d527e17f05.zip
rtld: map without PROT_EXEC for relocation
This makes text segment relocation work under W^X. Submitted by: Greg V <greg@unrelenting.technology> (original version) Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27953
-rw-r--r--libexec/rtld-elf/rtld.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 27262ab9dbc5..7b8bfba84d7d 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -2982,7 +2982,8 @@ reloc_textrel_prot(Obj_Entry *obj, bool before)
base = obj->relocbase + trunc_page(ph->p_vaddr);
sz = round_page(ph->p_vaddr + ph->p_filesz) -
trunc_page(ph->p_vaddr);
- prot = convert_prot(ph->p_flags) | (before ? PROT_WRITE : 0);
+ prot = before ? (PROT_READ | PROT_WRITE) :
+ convert_prot(ph->p_flags);
if (mprotect(base, sz, prot) == -1) {
_rtld_error("%s: Cannot write-%sable text segment: %s",
obj->path, before ? "en" : "dis",