From 04e0acd935dc79a8426198af2ed82fc9fec4c4c9 Mon Sep 17 00:00:00 2001 From: emaste Date: Sun, 4 Nov 2018 19:21:12 +0000 Subject: [PATCH] rtld: move relro enforcement after ifunc processing Previously the combination of relro (implicit), -z now and ifunc use resulted in a segfault when applying ifuncs after relro (test binary here just calls amd64_get_fsbase()): | % env LD_DEBUG=1 libexec/rtld-elf/obj/ld-elf.so.1 a.out | ... | enforcing main obj relro | ... | resolving ifuncs | reloc_jmpslot: *0x203198 = 0x189368ea4570 | zsh: bus error (core dumped) LD_DEBUG=1 obj/ld-elf.so.1 ~/a.out Reported by: Shawn Webb Reviewed by: kib Sponsored by: The FreeBSD Foundation --- libexec/rtld-elf/rtld.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 72d8f07c6b88..8c034305f7d7 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -700,10 +700,6 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) if (do_copy_relocations(obj_main) == -1) rtld_die(); - dbg("enforcing main obj relro"); - if (obj_enforce_relro(obj_main) == -1) - rtld_die(); - if (getenv(_LD("DUMP_REL_POST")) != NULL) { dump_relocations(obj_main); exit (0); @@ -739,6 +735,10 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) NULL) == -1) rtld_die(); + dbg("enforcing main obj relro"); + if (obj_enforce_relro(obj_main) == -1) + rtld_die(); + if (!obj_main->crt_no_init) { /* * Make sure we don't call the main program's init and fini