diff options
author | 2018-11-16 21:15:47 +0000 | |
---|---|---|
committer | 2018-11-16 21:15:47 +0000 | |
commit | 252050682a87ce44092ddc6588d4cdbd16b96613 (patch) | |
tree | c145a0e2b2ee75c1c920af1a126ac64d0d68ab18 | |
parent | Fix DTLS. Because the DTLS code is strange. I am really coming around to (diff) | |
download | wireguard-openbsd-252050682a87ce44092ddc6588d4cdbd16b96613.tar.xz wireguard-openbsd-252050682a87ce44092ddc6588d4cdbd16b96613.zip |
Finish ld.so's transition to GNU_RELRO: eliminate support for using
__got_{start,end} to find a region to mark read-only. It was only used
for binaries that didn't have a GNU_RELRO segment, but all archs have
been using that for over a year. Since support for insecure-PLT layouts
on powerpc and alpha have been removed, all archs handle GNU_RELRO the
same way and the support can be moved from the MD code to the MI code.
ok mpi@
-rw-r--r-- | libexec/ld.so/aarch64/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/alpha/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/amd64/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/arm/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/hppa/rtld_machine.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/i386/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/loader.c | 13 | ||||
-rw-r--r-- | libexec/ld.so/m88k/rtld_machine.c | 37 | ||||
-rw-r--r-- | libexec/ld.so/mips64/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/powerpc/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/resolve.c | 71 | ||||
-rw-r--r-- | libexec/ld.so/resolve.h | 5 | ||||
-rw-r--r-- | libexec/ld.so/sh/rtld_machine.c | 5 | ||||
-rw-r--r-- | libexec/ld.so/sparc64/rtld_machine.c | 5 |
14 files changed, 38 insertions, 139 deletions
diff --git a/libexec/ld.so/aarch64/rtld_machine.c b/libexec/ld.so/aarch64/rtld_machine.c index cfd3f474d7f..7630b58d85f 100644 --- a/libexec/ld.so/aarch64/rtld_machine.c +++ b/libexec/ld.so/aarch64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.6 2018/10/25 16:41:38 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.7 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -310,9 +310,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) pltgot[2] = (Elf_Addr)_dl_bind_start; } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c index ca18c487bfb..0cb712d2533 100644 --- a/libexec/ld.so/alpha/rtld_machine.c +++ b/libexec/ld.so/alpha/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.63 2018/11/12 02:33:42 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.64 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -294,9 +294,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) pltgot[1] = (Elf_Addr)object; } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/amd64/rtld_machine.c b/libexec/ld.so/amd64/rtld_machine.c index dd14f4b6b66..156ed28a9b6 100644 --- a/libexec/ld.so/amd64/rtld_machine.c +++ b/libexec/ld.so/amd64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.29 2018/10/25 16:41:38 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.30 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -413,8 +413,5 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) } } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/arm/rtld_machine.c b/libexec/ld.so/arm/rtld_machine.c index e4fbea70ebc..797f09c8e7a 100644 --- a/libexec/ld.so/arm/rtld_machine.c +++ b/libexec/ld.so/arm/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.27 2018/10/25 16:41:38 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.28 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -373,9 +373,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) pltgot[2] = (Elf_Addr)_dl_bind_start; } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/hppa/rtld_machine.c b/libexec/ld.so/hppa/rtld_machine.c index 46c91d9139c..0c11b75c269 100644 --- a/libexec/ld.so/hppa/rtld_machine.c +++ b/libexec/ld.so/hppa/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.36 2017/01/24 07:48:37 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.37 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -428,10 +428,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) } } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", - PROT_READ|PROT_EXEC); - return (fails); } diff --git a/libexec/ld.so/i386/rtld_machine.c b/libexec/ld.so/i386/rtld_machine.c index a420f670114..5c35ac02523 100644 --- a/libexec/ld.so/i386/rtld_machine.c +++ b/libexec/ld.so/i386/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.38 2018/10/25 16:41:38 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.39 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -440,8 +440,5 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) } } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index 625adb75412..abbe1f05051 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.174 2018/10/23 04:01:45 guenther Exp $ */ +/* $OpenBSD: loader.c,v 1.175 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -689,6 +689,17 @@ _dl_rtld(elf_object_t *object) object->obj_flags & DF_1_NOW)); /* + * Handle GNU_RELRO + */ + if (object->relro_addr != 0 && object->relro_size != 0) { + Elf_Addr addr = object->relro_addr; + + DL_DEB(("protect RELRO [0x%lx,0x%lx) in %s\n", + addr, addr + object->relro_size, object->load_name)); + _dl_mprotect((void *)addr, object->relro_size, PROT_READ); + } + + /* * Look for W&X segments and make them read-only. */ for (llist = object->load_list; llist != NULL; llist = llist->next) { diff --git a/libexec/ld.so/m88k/rtld_machine.c b/libexec/ld.so/m88k/rtld_machine.c index 3579ebcc349..c818426f23b 100644 --- a/libexec/ld.so/m88k/rtld_machine.c +++ b/libexec/ld.so/m88k/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.22 2018/11/09 06:16:37 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.23 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -282,7 +282,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) int fails = 0; Elf_Addr *pltgot = (Elf_Addr *)object->Dyn.info[DT_PLTGOT]; Elf_Addr plt_start, plt_end; - size_t plt_size; if (pltgot == NULL) return (0); @@ -296,19 +295,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) if (object->traced) lazy = 1; - plt_start = object->Dyn.info[DT_88K_PLTSTART - DT_LOPROC + DT_NUM]; - plt_end = object->Dyn.info[DT_88K_PLTEND - DT_LOPROC + DT_NUM]; - - /* - * GOT relocation will require PLT to be writeable. - */ - if ((!lazy || object->obj_base != 0) && plt_start != 0 && - plt_end != 0) { - plt_size = plt_end - plt_start; - plt_start += object->obj_base; - } else - plt_size = 0; - if (!lazy) { fails = _dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ); } else { @@ -330,15 +316,18 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) } } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - - if (plt_size != 0) { - /* - * Force a cache sync on the whole plt here, - * otherwise I$ might have stale information. - */ - _dl_cacheflush(plt_start, plt_size); + /* + * Force a cache sync here on the whole PLT if we updated it + * (and have the DT entries to find what we need to flush), + * otherwise I$ might have stale information. + */ + plt_start = object->Dyn.info[DT_88K_PLTSTART - DT_LOPROC + DT_NUM]; + plt_end = object->Dyn.info[DT_88K_PLTEND - DT_LOPROC + DT_NUM]; + if ((!lazy || object->obj_base != 0) && plt_start != 0 && + plt_end != 0) { + size_t plt_size = plt_end - plt_start; + if (plt_size != 0) + _dl_cacheflush(plt_start + object->obj_base, plt_size); } return (fails); diff --git a/libexec/ld.so/mips64/rtld_machine.c b/libexec/ld.so/mips64/rtld_machine.c index fbc6d93a173..2e14ec9f0a9 100644 --- a/libexec/ld.so/mips64/rtld_machine.c +++ b/libexec/ld.so/mips64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.28 2018/01/18 08:17:39 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.29 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1998-2004 Opsycon AB, Sweden. @@ -254,9 +254,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) } object->status |= STAT_GOT_DONE; - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (0); } diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c index 7bf409bf4dd..8601401551d 100644 --- a/libexec/ld.so/powerpc/rtld_machine.c +++ b/libexec/ld.so/powerpc/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.64 2018/11/09 05:31:57 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.65 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -377,9 +377,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) plt[i] += object->obj_base; } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c index 0f192982d00..e1df6956e4b 100644 --- a/libexec/ld.so/resolve.c +++ b/libexec/ld.so/resolve.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.c,v 1.85 2018/11/16 05:05:44 guenther Exp $ */ +/* $OpenBSD: resolve.c,v 1.86 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -468,70 +468,6 @@ _dl_remove_object(elf_object_t *object) free_objects = object; } -/* - * mprotect a segment to the indicated protection. If 'addr' is non-zero, - * then it's the start address, else the value of 'start_sym' is the start. - * The value of 'end_sym' is the end address. The start is rounded down - * and the end is rounded up to page boundaries. Returns 'addr' or the - * address of the start symbol. - */ -void * -_dl_protect_segment(elf_object_t *object, Elf_Addr addr, - const char *start_sym, const char *end_sym, int prot) -{ - const Elf_Sym *this; - Elf_Addr ooff, start, end; - - if (addr == 0 && start_sym[2] == 'g' && - (addr = object->relro_addr) != 0) { - DL_DEB(("protect start RELRO = 0x%lx in %s\n", - addr, object->load_name)); - } - else if (addr == 0) { - this = NULL; - ooff = _dl_find_symbol(start_sym, &this, - SYM_SEARCH_OBJ | SYM_NOWARNNOTFOUND | SYM_PLT, NULL, - object, NULL); - /* If not found, nothing to do */ - if (this == NULL) { - DL_DEB(("protect start \"%s\" not found in %s\n", - start_sym, object->load_name)); - return (NULL); - } - addr = ooff + this->st_value; - DL_DEB(("protect start \"%s\" to %x = 0x%lx in %s\n", - start_sym, prot, addr, object->load_name)); - } - - if (object->relro_addr != 0 && start_sym[2] == 'g') { - end = object->relro_addr + object->relro_size; - DL_DEB(("protect end RELRO = 0x%lx in %s\n", - end, object->load_name)); - } else { - this = NULL; - ooff = _dl_find_symbol(end_sym, &this, - SYM_SEARCH_OBJ | SYM_NOWARNNOTFOUND | SYM_PLT, NULL, - object, NULL); - if (this == NULL) { - DL_DEB(("protect end \"%s\" not found in %s\n", - end_sym, object->load_name)); - addr = 0; - } else { - end = ooff + this->st_value; - DL_DEB(("protect end \"%s\" = 0x%lx in %s\n", - end_sym, end, object->load_name)); - } - } - - if (addr != 0 && addr < end) { - start = ELF_TRUNC(addr, _dl_pagesz); - end = ELF_ROUND(end, _dl_pagesz); - _dl_mprotect((void *)start, end - start, prot); - } - - return ((void *)addr); -} - sym_cache *_dl_symcache; int _dl_symcachestat_hits; @@ -684,10 +620,7 @@ _dl_find_symbol(const char *name, const Elf_Sym **this, if (_dl_find_symbol_obj(req_obj, &sl)) goto found; - if (flags & SYM_SEARCH_OBJ) { - _dl_find_symbol_obj(req_obj, &sl); - /* always just fallthrough to 'found' */ - } else if (flags & SYM_DLSYM) { + if (flags & SYM_DLSYM) { if (_dl_find_symbol_obj(req_obj, &sl)) goto found; diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 89e34b9cd85..ff0738dfa6a 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.85 2018/10/23 04:01:45 guenther Exp $ */ +/* $OpenBSD: resolve.h,v 1.86 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -197,8 +197,6 @@ elf_object_t *_dl_finalize_object(const char *objname, Elf_Dyn *dynp, const long obase); void _dl_remove_object(elf_object_t *object); void _dl_cleanup_objects(void); -void *_dl_protect_segment(elf_object_t *_object, Elf_Addr _addr, - const char *_start_sym, const char *_end_sym, int _prot); elf_object_t *_dl_load_shlib(const char *, elf_object_t *, int, int); elf_object_t *_dl_tryload_shlib(const char *libname, int type, int flags); @@ -230,7 +228,6 @@ Elf_Addr _dl_find_symbol_bysym(elf_object_t *req_obj, unsigned int symidx, #define SYM_SEARCH_SELF 0x01 #define SYM_SEARCH_OTHER 0x02 #define SYM_SEARCH_NEXT 0x04 -#define SYM_SEARCH_OBJ 0x08 /* warnnotfound */ #define SYM_NOWARNNOTFOUND 0x00 #define SYM_WARNNOTFOUND 0x10 diff --git a/libexec/ld.so/sh/rtld_machine.c b/libexec/ld.so/sh/rtld_machine.c index bf13720dffb..37fbabf0718 100644 --- a/libexec/ld.so/sh/rtld_machine.c +++ b/libexec/ld.so/sh/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.26 2018/10/25 16:41:38 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.27 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -825,9 +825,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) pltgot[2] = (Elf_Addr)_dl_bind_start; } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c index 02a4ba2c9c3..f106011606e 100644 --- a/libexec/ld.so/sparc64/rtld_machine.c +++ b/libexec/ld.so/sparc64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.62 2018/10/25 16:41:38 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.63 2018/11/16 21:15:47 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -850,8 +850,5 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) pltgot[8] = (Elf_Addr)object; } - /* mprotect the GOT */ - _dl_protect_segment(object, 0, "__got_start", "__got_end", PROT_READ); - return (fails); } |