From: guenther Date: Wed, 10 Aug 2016 02:58:44 +0000 (+0000) Subject: Cover your kid's remaining eye and lock up the pets for the great old ones X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7310f5ffd2bd10e53f6320b063e2fe1b96b1e682;p=openbsd Cover your kid's remaining eye and lock up the pets for the great old ones have been disturbed: rework the linker script and then enable RELRO support on all but mips64 (something something padding) and m88k (untested). This extends the RO coverage from just .got and .cdtors to also include .openbsd.randomdata, .jcr, .dynamic, and .data.rel.ro., and moves more segments from the text section to the rodata section. Depends on the previous csu and ld.so work; reinstall those *before* rebuilding ld, or just get a snapshot. clues from kettenis assistance testing and ok deraadt@ --- diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh index a2f193b7546..13a9239f8f7 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/armelf_obsd.sh @@ -1,8 +1,10 @@ . ${srcdir}/emulparams/armelf.sh -. ${srcdir}/emulparams/elf_obsd.sh MAXPAGESIZE=0x8000 +COMMONPAGESIZE=0x1000 TEXT_START_ADDR=0x00008000 TARGET2_TYPE=got-rel unset EMBEDDED + +. ${srcdir}/emulparams/elf_obsd.sh diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh index 5fbc163f875..4620a7ac1df 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf32ppc_obsd.sh @@ -1,7 +1,14 @@ -. ${srcdir}/emulparams/elf32ppccommon.sh -# We deliberately keep the traditional OpenBSD W^X layout for both the -# old BSS-PLT and the new Secure-PLT ABI. -BSS_PLT= -OTHER_TEXT_SECTIONS="*(.glink)" -EXTRA_EM_FILE=ppc32elf +. ${srcdir}/emulparams/elf32ppc.sh . ${srcdir}/emulparams/elf_obsd.sh + +# override these to put the padding *in* the output section +sdata_GOT=".got ${RELOCATING-0} : SPECIAL { + *(.got) + ${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));} + }" +bss_PLT=" + .plt ${RELOCATING-0} : SPECIAL { + ${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));} + *(.plt) + ${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));} + }" diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh index f34e0ececd7..71dad530261 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64btsmip_obsd.sh @@ -1,5 +1,6 @@ . ${srcdir}/emulparams/elf64btsmip.sh MAXPAGESIZE=0x10000 +COMMONPAGESIZE=0x1000 TEXT_START_ADDR="0x10000000" . ${srcdir}/emulparams/elf_obsd.sh # XXX causes GOT oflows diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh index f2561ea766e..dfe851cd26d 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/elf64ltsmip_obsd.sh @@ -1,5 +1,6 @@ . ${srcdir}/emulparams/elf64ltsmip.sh MAXPAGESIZE=0x10000 +COMMONPAGESIZE=0x1000 TEXT_START_ADDR="0x10000000" . ${srcdir}/emulparams/elf_obsd.sh # XXX causes GOT oflows diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh index 16f5a62ba40..32ac7ca268c 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/hppaobsd.sh @@ -7,6 +7,7 @@ OUTPUT_FORMAT="elf32-hppa" # other necessary defines, similar but not the same as linux. MAXPAGESIZE=0x1000 +COMMONPAGESIZE=0x1000 ENTRY="__start" MACHINE=hppa1.1 # We use 1.1 specific features. OTHER_READONLY_SECTIONS=".PARISC.unwind ${RELOCATING-0} : { *(.PARISC.unwind) }" diff --git a/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh b/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh index 2fa0f7157dc..262fe529ef7 100644 --- a/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh +++ b/gnu/usr.bin/binutils-2.17/ld/emulparams/shelf_obsd.sh @@ -2,11 +2,11 @@ # shlelf_obsd.sh . ${srcdir}/emulparams/shelf.sh -. ${srcdir}/emulparams/elf_obsd.sh OUTPUT_FORMAT="elf32-sh-obsd" TEXT_START_ADDR=0x400000 MAXPAGESIZE=0x10000 +COMMONPAGESIZE=0x1000 DATA_START_SYMBOLS='__data_start = . ;'; @@ -14,3 +14,8 @@ ENTRY=__start unset EMBEDDED unset OTHER_SECTIONS + +. ${srcdir}/emulparams/elf_obsd.sh + +# No nx bit, so don't bother to pad between .text and .rodata +unset PAD_RO diff --git a/gnu/usr.bin/binutils-2.17/ld/ldmain.c b/gnu/usr.bin/binutils-2.17/ld/ldmain.c index e927bc97f16..fc82e3e401b 100644 --- a/gnu/usr.bin/binutils-2.17/ld/ldmain.c +++ b/gnu/usr.bin/binutils-2.17/ld/ldmain.c @@ -299,7 +299,11 @@ main (int argc, char **argv) link_info.new_dtags = FALSE; link_info.combreloc = TRUE; link_info.eh_frame_hdr = FALSE; +#if defined(__mips64__) || defined(__m88k__) link_info.relro = FALSE; +#else + link_info.relro = TRUE; +#endif link_info.strip_discarded = TRUE; link_info.strip = strip_none; link_info.discard = discard_sec_merge; diff --git a/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc b/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc index d036c6318f0..c92ea878340 100644 --- a/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc +++ b/gnu/usr.bin/binutils-2.17/ld/scripttempl/elf.sc @@ -193,8 +193,8 @@ RODATA_ALIGN_ADD_VAL="${CREATE_SHLIB-${RODATA_ALIGN_ADD:-0}} ${CREATE_SHLIB+0}" test "$LD_FLAG" = "n" || test "$LD_FLAG" = "N" || test "${LD_FLAG%%(cpie|pie)}" = "Z" || NO_PAD="y" if test "$NO_PAD" = "y" ; then PAD_RO0="${RELOCATING+${RODATA_ALIGN} + ${RODATA_ALIGN_ADD_VAL};}" - PAD_PLT0="${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));} .pltpad0 ${RELOCATING-0} : { ${RELOCATING+__plt_start = .;} }" - PAD_PLT1=".pltpad1 ${RELOCATING-0} : { ${RELOCATING+__plt_end = .;}} ${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));}" + PAD_PLT0="${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));}" + PAD_PLT1="${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));}" PAD_GOT0="${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));} .gotpad0 ${RELOCATING-0} : { ${RELOCATING+__got_start = .;} }" PAD_GOT1=".gotpad1 ${RELOCATING-0} : { ${RELOCATING+__got_end = .;}} ${RELOCATING+. = ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1));}" test "$NO_PAD_CDTOR" = "y" || PAD_CDTOR= @@ -248,6 +248,8 @@ else fi cat <