Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Nov 2018 19:21:13 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340137 - head/libexec/rtld-elf
Message-ID:  <201811041921.wA4JLDCa011480@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Sun Nov  4 19:21:12 2018
New Revision: 340137
URL: https://svnweb.freebsd.org/changeset/base/340137

Log:
  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

Modified:
  head/libexec/rtld-elf/rtld.c

Modified: head/libexec/rtld-elf/rtld.c
==============================================================================
--- head/libexec/rtld-elf/rtld.c	Sun Nov  4 19:11:32 2018	(r340136)
+++ head/libexec/rtld-elf/rtld.c	Sun Nov  4 19:21:12 2018	(r340137)
@@ -700,10 +700,6 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
     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);
@@ -737,6 +733,10 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
     if (resolve_objects_ifunc(obj_main,
       ld_bind_now != NULL && *ld_bind_now != '\0', SYMLOOK_EARLY,
       NULL) == -1)
+	rtld_die();
+
+    dbg("enforcing main obj relro");
+    if (obj_enforce_relro(obj_main) == -1)
 	rtld_die();
 
     if (!obj_main->crt_no_init) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811041921.wA4JLDCa011480>