Skip to content

Commit

Permalink
rtld: map without PROT_EXEC for relocation
Browse files Browse the repository at this point in the history
This makes text segment relocation work under W^X.

Submitted by:	Greg V <greg_unrelenting.technology>
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27953
  • Loading branch information
emaste committed Jan 4, 2021
1 parent de058e1 commit 138b363
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libexec/rtld-elf/rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 138b363

Please sign in to comment.