git: c9f833abf1d7 - main - rtld: Round down relro_size
Konstantin Belousov
kib at FreeBSD.org
Fri Aug 13 09:58:59 UTC 2021
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=c9f833abf1d76ea194b82caafa06a0627790ad97
commit c9f833abf1d76ea194b82caafa06a0627790ad97
Author: Konstantin Belousov <kib at FreeBSD.org>
AuthorDate: 2021-08-12 02:45:15 +0000
Commit: Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-08-13 09:58:53 +0000
rtld: Round down relro_size
lld rounds up p_memsz(PT_GNU_RELRO) to satisfy common-page-size. If the
page size is smaller than common-page-size, rounding up relro_size may
incorrectly make some RW pages read-only.
GNU ld, gold, and ld.lld ensures p_vaddr+p_memsz is a multiple of
common-page-size. While max-page-size >= system the page size,
common-page-size can be smaller than the system page size.
Submitted by: MaskRay
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D31498
---
libexec/rtld-elf/map_object.c | 3 ++-
libexec/rtld-elf/rtld.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c
index 273e477fbda5..b725fe93b8f6 100644
--- a/libexec/rtld-elf/map_object.c
+++ b/libexec/rtld-elf/map_object.c
@@ -325,7 +325,8 @@ map_object(int fd, const char *path, const struct stat *sb)
}
obj->stack_flags = stack_flags;
obj->relro_page = obj->relocbase + trunc_page(relro_page);
- obj->relro_size = round_page(relro_size);
+ obj->relro_size = trunc_page(relro_page + relro_size) -
+ trunc_page(relro_page);
if (note_start < note_end)
digest_notes(obj, note_start, note_end);
if (note_map != NULL)
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index f60872f12c52..eaad89339d07 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -1557,7 +1557,8 @@ digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t entry, const char *path)
case PT_GNU_RELRO:
obj->relro_page = obj->relocbase + trunc_page(ph->p_vaddr);
- obj->relro_size = round_page(ph->p_memsz);
+ obj->relro_size = trunc_page(ph->p_vaddr + ph->p_memsz) -
+ trunc_page(ph->p_vaddr);
break;
case PT_NOTE:
More information about the dev-commits-src-main
mailing list