From dc29eaa0d06616df0a37a4e2a6fe6768072e7c6c Mon Sep 17 00:00:00 2001 From: emaste Date: Wed, 7 Nov 2018 18:12:18 +0000 Subject: [PATCH] MFC r340137: 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 --- 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 9332dec38dd..a755b4fdcce 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -705,10 +705,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); @@ -743,6 +739,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 -- 2.45.0