From: guenther Date: Mon, 4 Jul 2016 21:15:06 +0000 (+0000) Subject: Remove prebind support: binding to symbol table indices is too fragile X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0ed603803bd6dc07f99143a60676a221afb2e407;p=openbsd Remove prebind support: binding to symbol table indices is too fragile for our development process. ok kettenis@ deraadt@ --- diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile index 5c6da586143..5405845fa6d 100644 --- a/libexec/ld.so/Makefile +++ b/libexec/ld.so/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.61 2016/05/07 19:05:23 guenther Exp $ +# $OpenBSD: Makefile,v 1.62 2016/07/04 21:15:06 guenther Exp $ SUBDIR=ldconfig ldd MAN= ld.so.1 @@ -17,7 +17,7 @@ ELF_LDFLAGS+=--version-script=${VERSION_SCRIPT} VPATH=${.CURDIR}/../../lib/libc/string SRCS= ldasm.S boot.c loader.c resolve.c dlfcn.c dl_printf.c rtld_machine.c -SRCS+= path.c util.c sod.c strsep.c strtol.c dir.c library_subr.c dl_prebind.c +SRCS+= path.c util.c sod.c strsep.c strtol.c dir.c library_subr.c SRCS+= dl_realpath.c dl_uname.c dl_dirname.c strlcat.c strlen.c trace.c SRCS+= malloc.c reallocarray.c tib.c diff --git a/libexec/ld.so/alpha/syscall.h b/libexec/ld.so/alpha/syscall.h index 8005b3e3307..562db2e718f 100644 --- a/libexec/ld.so/alpha/syscall.h +++ b/libexec/ld.so/alpha/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.33 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.34 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -61,10 +61,4 @@ int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/amd64/syscall.h b/libexec/ld.so/amd64/syscall.h index 270e9bb2468..b64012d817d 100644 --- a/libexec/ld.so/amd64/syscall.h +++ b/libexec/ld.so/amd64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.22 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -61,10 +61,4 @@ int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/arm/syscall.h b/libexec/ld.so/arm/syscall.h index d74a9e26c3d..24321b86117 100644 --- a/libexec/ld.so/arm/syscall.h +++ b/libexec/ld.so/arm/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.22 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -61,10 +61,4 @@ int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/dl_prebind.c b/libexec/ld.so/dl_prebind.c deleted file mode 100644 index 5f3ccf1b9d5..00000000000 --- a/libexec/ld.so/dl_prebind.c +++ /dev/null @@ -1,640 +0,0 @@ -/* $OpenBSD: dl_prebind.c,v 1.18 2015/10/14 17:29:44 tobias Exp $ */ -/* - * Copyright (c) 2006 Dale Rahn - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "syscall.h" -#include "archdep.h" -#include "resolve.h" -#include "sod.h" -#include "stdlib.h" -#include "dl_prebind.h" - -void elf_dump_footer(struct prebind_footer *footer); -void dump_prelink(Elf_Addr base, u_long size); -void prebind_dump_footer(struct prebind_footer *footer, char *file); -void prebind_dump_symcache(struct symcachetab *symcachetab, u_int32_t cnt); -void prebind_dump_nameidx(struct nameidx *nameidx, u_int32_t numblibs, - char *nametab); -void prebind_dump_fixup(struct fixup *fixup, u_int32_t numfixups); -void prebind_dump_libmap(u_int32_t *libmap, u_int32_t numlibs); -struct prebind_footer *_dl_prebind_data_to_footer(void *data); - -char *_dl_prog_prebind_map; -struct prebind_footer *prog_footer; -extern char *_dl_noprebind; -extern char *_dl_prebind_validate; - -int _dl_prebind_match_failed; /* = 0 */ - -char *prebind_bind_now = "prebind"; - -struct prebind_footer * -_dl_prebind_data_to_footer(void *prebind_data) -{ - u_int32_t *poffset, offset; - struct prebind_footer *footer; - char *c; - - poffset = prebind_data; - c = prebind_data; - offset = *poffset; - c += offset; - footer = (void *)c; - return footer; -} - -void -prebind_load_exe(Elf_Phdr *phdp, elf_object_t *exe_obj) -{ - struct prebind_footer *footer; - - exe_obj->prebind_data = (void *)phdp->p_vaddr; - _dl_prog_prebind_map = exe_obj->prebind_data; - - footer = _dl_prebind_data_to_footer(_dl_objects->prebind_data); - - if (footer->bind_id[0] == BIND_ID0 && - footer->bind_id[1] == BIND_ID1 && - footer->bind_id[2] == BIND_ID2 && - footer->bind_id[3] == BIND_ID3 && - footer->prebind_version == PREBIND_VERSION) { - prog_footer = footer; - if (_dl_bindnow == NULL) - _dl_bindnow = prebind_bind_now; - } else { - DL_DEB(("prebind data missing\n")); - _dl_prog_prebind_map = NULL; - } - if (_dl_noprebind != NULL) { - /*prog_footer is valid, we should free it */ - _dl_prog_prebind_map = NULL; - prog_footer = NULL; - exe_obj->prebind_data = NULL; - if (_dl_bindnow == prebind_bind_now) - _dl_bindnow = NULL; - } -#if 0 - else if (_dl_debug) - dump_prelink((long)_dl_prog_prebind_map, - prog_footer->prebind_size); -#endif -} - -void * -prebind_load_fd(int fd, const char *name) -{ - struct prebind_footer footer; - struct nameidx *nameidx; - void *prebind_data; - char *nametab; - ssize_t len; - int idx; - - if (_dl_prog_prebind_map == NULL || _dl_prebind_match_failed) - return 0; - - _dl_lseek(fd, -(off_t)sizeof(struct prebind_footer), SEEK_END); - len = _dl_read(fd, (void *)&footer, sizeof(struct prebind_footer)); - - if (len != sizeof(struct prebind_footer) || - footer.bind_id[0] != BIND_ID0 || - footer.bind_id[1] != BIND_ID1 || - footer.bind_id[2] != BIND_ID2 || - footer.bind_id[3] != BIND_ID3 || - footer.prebind_version != PREBIND_VERSION) { - _dl_prebind_match_failed = 1; - DL_DEB(("prebind match failed %s\n", name)); - return (NULL); - } - - prebind_data = _dl_mmap(0, footer.prebind_size, PROT_READ, - MAP_FILE, fd, footer.prebind_base); - if (_dl_mmap_error(prebind_data)) { - _dl_prebind_match_failed = 1; - DL_DEB(("prebind match failed %s\n", name)); - return (NULL); - } - - DL_DEB(("prebind_load_fd for lib %s\n", name)); - - nameidx = (void *)(_dl_prog_prebind_map + prog_footer->nameidx_idx); - nametab = (void *)(_dl_prog_prebind_map + prog_footer->nametab_idx); - - /* libraries are loaded in random order, so we just have - * to look thru the list to find ourselves - */ - for (idx = 0; idx < prog_footer->numlibs; idx++) { - if (_dl_strcmp(nametab + nameidx[idx].name, name) == 0) - break; - } - - if (idx == prog_footer->numlibs) { - _dl_prebind_match_failed = 1; /* not found */ - } else if (footer.id0 != nameidx[idx].id0 || - footer.id1 != nameidx[idx].id1) { - _dl_prebind_match_failed = 1; - DL_DEB(("prebind match id0 %d pid0 %d id1 %d pid1 %d\n", - footer.id0, nameidx[idx].id0, - footer.id1, nameidx[idx].id1)); - } - - if (_dl_prebind_match_failed == 1) { - DL_DEB(("prebind match failed for %s\n", name)); - } - - return prebind_data; -} -#define NUM_STATIC_OBJS 10 -elf_object_t *objarray_static[NUM_STATIC_OBJS]; -elf_object_t **objarray; - -void -prebind_symcache(elf_object_t *object, int plt) -{ - u_int32_t *fixupidx, *fixupcnt, *libmap, *idxtolib; - u_int32_t *poffset, offset, symcache_cnt; - struct symcachetab *symcachetab; - struct prebind_footer *footer; - int i = 0, cur_obj = -1, idx; - char *prebind_map; - char *c; - struct fixup *fixup; - elf_object_t *obj; - - struct symcachetab *s; - - if (object->prebind_data == NULL) - return; -// DL_DEB(("prebind symcache %s\n", object->load_name)); - - obj = _dl_objects; - while (obj != NULL) { - if (obj == object) - cur_obj = i; - i++; - obj = obj->next; - } - - if (cur_obj == -1) - return; /* unable to find object ? */ - - if (objarray == NULL) { - if (i <= NUM_STATIC_OBJS) { - objarray = &objarray_static[0]; - } else { - objarray = _dl_reallocarray(NULL, i, - sizeof(elf_object_t *)); - if (objarray == NULL) - _dl_exit(20); - } - - obj = _dl_objects; - i = 0; - while (obj != NULL) { - objarray[i] = obj; - i++; - obj = obj->next; - } - } - - poffset = (u_int32_t *)object->prebind_data; - c = object->prebind_data; - offset = *poffset; - c += offset; - - footer = (void *)c; - prebind_map = (void *)object->prebind_data; - - if (plt) { - symcachetab = (void *)(prebind_map + footer->pltsymcache_idx); - symcache_cnt = footer->pltsymcache_cnt; -// DL_DEB(("loading plt %d\n", symcache_cnt)); - } else { - symcachetab = (void *)(prebind_map + footer->symcache_idx); - symcache_cnt = footer->symcache_cnt; -// DL_DEB(("loading got %d\n", symcache_cnt)); - } - - libmap = (void *)(_dl_prog_prebind_map + prog_footer->libmap_idx); - idxtolib = (void *)(_dl_prog_prebind_map + libmap[cur_obj]); - - for (i = 0; i < symcache_cnt; i++) { - struct elf_object *tobj; - const Elf_Sym *sym; -#ifdef DEBUG2 - const char *str; -#endif - - s = &(symcachetab[i]); - if (cur_obj == 0) - idx = s->obj_idx; - else - idx = idxtolib[s->obj_idx]; - - if (idx == -1) /* somehow an invalid object ref happend */ - continue; -#if 0 - DL_DEB(("%s:", object->load_name)); - DL_DEB(("symidx %d: obj %d %d sym %d flags %x\n", - s->idx, s->obj_idx, idx, s->sym_idx, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt)); -#endif - tobj = objarray[idx]; - sym = tobj->dyn.symtab + s->sym_idx; -#ifdef DEBUG2 - str = tobj->dyn.strtab + sym->st_name; - DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n", - s->idx, s->obj_idx, tobj->load_name, - s->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, - object->obj_base + sym->st_value)); -#endif - _dl_symcache[s->idx].obj = tobj; - _dl_symcache[s->idx].sym = sym; - _dl_symcache[s->idx].flags = - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt; - } - - if (!plt) { - fixupidx = (void *)(_dl_prog_prebind_map + - prog_footer->fixup_idx); - fixup = (void *)(_dl_prog_prebind_map + - fixupidx[2*cur_obj]); - fixupcnt = (void *)(_dl_prog_prebind_map + - prog_footer->fixupcnt_idx); - - for (i = 0; i < fixupcnt[2*cur_obj]; i++) { - struct fixup *f; - struct elf_object *tobj; - const Elf_Sym *sym; -#ifdef DEBUG2 - const char *str; -#endif - - f = &(fixup[i]); -#if 0 - DL_DEB(("symidx %d: obj %d sym %d flags %x\n", - f->sym, f->obj_idx, f->sym_idx, f->flags)); -#endif - tobj = objarray[f->obj_idx]; - sym = tobj->dyn.symtab + f->sym_idx; -#ifdef DEBUG2 - str = tobj->dyn.strtab + sym->st_name; - DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n", - f->sym, f->obj_idx, tobj->load_name, - f->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, - object->obj_base + sym->st_value)); -#endif - _dl_symcache[f->sym].obj = tobj; - _dl_symcache[f->sym].sym = sym; - _dl_symcache[f->sym].flags = - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt; - } - } else { - - fixupidx = (void *)(_dl_prog_prebind_map + - prog_footer->fixup_idx); - fixup = (void *)(_dl_prog_prebind_map + - fixupidx[2*cur_obj+1]); - fixupcnt = (void *)(_dl_prog_prebind_map + - prog_footer->fixupcnt_idx); - -#if 0 - DL_DEB(("prebind loading symbols fixup plt %s\n", - object->load_name)); -#endif - for (i = 0; i < fixupcnt[2*cur_obj+1]; i++) { - struct fixup *f; - struct elf_object *tobj; - const Elf_Sym *sym; -#ifdef DEBUG2 - const char *str; -#endif - - f = &(fixup[i]); -#if 0 - DL_DEB(("symidx %d: obj %d sym %d flags %x\n", - f->sym, f->obj_idx, f->sym_idx, - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt)); -#endif - tobj = objarray[f->obj_idx]; - sym = tobj->dyn.symtab + f->sym_idx; -#ifdef DEBUG2 - str = tobj->dyn.strtab + sym->st_name; - DL_DEB(("symidx %d: obj %d %s sym %d %s flags %d %x\n", - f->sym, f->obj_idx, tobj->load_name, - f->sym_idx, str, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt, - object->obj_base + sym->st_value)); -#endif - _dl_symcache[f->sym].obj = tobj; - _dl_symcache[f->sym].sym = sym; - _dl_symcache[f->sym].flags = - SYM_SEARCH_ALL|SYM_WARNNOTFOUND|plt; - } - } -// DL_DEB(("prebind_data loaded\n")); -} - -void -prebind_free(elf_object_t *object) -{ - struct prebind_footer *footer; - - if (object->prebind_data == NULL) - return; -#ifdef DEBUG1 - DL_DEB(("prebind_free for %s %p\n", object->load_name, - object->prebind_data)); -#endif - if (object->prebind_data != 0) { - footer = _dl_prebind_data_to_footer(object->prebind_data); - -#ifdef DEBUG1 - DL_DEB(("freeing prebind data sz %x\n", footer->prebind_size)); -#endif - - _dl_munmap((void *)ELF_TRUNC((long)object->prebind_data, _dl_pagesz), - ELF_ROUND((long)object->prebind_data+footer->prebind_size, - _dl_pagesz) - ELF_TRUNC((long)object->prebind_data, _dl_pagesz)); - - object->prebind_data = NULL; - _dl_prog_prebind_map = NULL; - - if (_dl_bindnow == prebind_bind_now) - _dl_bindnow = NULL; - } -} - -int validate_errs; - -struct timeval beforetp; - -void -_dl_prebind_pre_resolve() -{ - struct prebind_footer *footer; - elf_object_t *object; - struct nameidx *nameidx; - char *nametab, *name; - int idx; - - if (_dl_prog_prebind_map != NULL) { - nameidx = (void *)(_dl_prog_prebind_map + - prog_footer->nameidx_idx); - nametab = (void *)(_dl_prog_prebind_map + - prog_footer->nametab_idx); - for (idx = 1, object = _dl_objects->next; object != NULL; - object = object->next, idx++) { - if (object->prebind_data == NULL) { - /* ld.so doesn't have prebind data */ - if (object->next == NULL) - continue; - DL_DEB(("missing prebind data %s\n", - object->load_name)); - _dl_prebind_match_failed = 1; - break; - } - footer = _dl_prebind_data_to_footer( - object->prebind_data); - if (footer == NULL || - nameidx[idx].id0 != footer->id0 || - nameidx[idx].id1 != footer->id1) { - DL_DEB(("invalid prebind data %s\n", - object->load_name)); - _dl_prebind_match_failed = 1; - break; - } - name = object->load_name; - if (_dl_strcmp(nametab + nameidx[idx].name, name) - != 0) { - DL_DEB(("invalid prebind name %s\n", - object->load_name)); - _dl_prebind_match_failed = 1; - break; - } - } - } - - if (_dl_prebind_match_failed) { - for (object = _dl_objects; object != NULL; - object = object->next) - prebind_free(object); - if (_dl_bindnow == prebind_bind_now) - _dl_bindnow = NULL; - } - - if (_dl_debug) - _dl_gettimeofday(&beforetp, NULL); -} - -void -_dl_prebind_post_resolve() -{ - char buf[7]; - int i; - struct timeval after_tp; - struct timeval diff_tp; - elf_object_t *object; - - if (_dl_debug) { - _dl_gettimeofday(&after_tp, NULL); - - timersub(&after_tp, &beforetp, &diff_tp); - - for (i = 0; i < 6; i++) { - buf[5-i] = (diff_tp.tv_usec % 10) + '0'; - diff_tp.tv_usec /= 10; - } - buf[6] = '\0'; - - /* - * _dl_printf lacks %lld support; therefore assume - * relocation takes less than 2^31 seconds - */ - _dl_printf("relocation took %d.%s\n", (int)diff_tp.tv_sec, buf); - } - - for (object = _dl_objects; object != NULL; object = object->next) - prebind_free(object); - - if (_dl_prebind_validate) { - if (validate_errs) { - _dl_printf("validate_errs %d\n", validate_errs); - _dl_exit(20); - } else { - _dl_exit(0); - } - } -} - -void -prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, - const Elf_Sym *ref_sym) -{ - const Elf_Sym *sym, **this; - const elf_object_t *sobj; - const char *symn; - - /* Don't verify non-matching flags*/ - - sym = req_obj->dyn.symtab; - sym += symidx; - symn = req_obj->dyn.strtab + sym->st_name; - this = &sym; - - //_dl_printf("checking %s\n", symn); - _dl_find_symbol(symn, this, flags, ref_sym, req_obj, &sobj); - - if (_dl_symcache[symidx].sym != *this || - _dl_symcache[symidx].obj != sobj) { - _dl_printf("symbol %d mismatch on sym %s req_obj %s,\n" - "should be obj %s is obj %s\n", - symidx, symn, req_obj->load_name, sobj->load_name, - _dl_symcache[symidx].obj->load_name); - if (req_obj == sobj) - _dl_printf("obj %p %p\n", _dl_symcache[symidx].obj, sobj); - sym = _dl_symcache[symidx].obj->dyn.symtab; - sym += symidx; - symn = _dl_symcache[symidx].obj->dyn.strtab + sym->st_name; - _dl_printf("obj %s name %s\n", - _dl_symcache[symidx].obj->load_name, - symn); - } -} - -#ifdef DEBUG1 -void -prebind_dump_symcache(struct symcachetab *symcachetab, u_int32_t cnt) -{ - struct symcachetab *s; - int i; - - _dl_printf("cache: cnt %d\n", cnt); - for (i = 0; i < cnt; i++) { - s = &(symcachetab[i]); - _dl_printf("symidx %d: obj %d sym %d\n", - s->idx, s->obj_idx, s->sym_idx); - } -} - -void -prebind_dump_nameidx(struct nameidx *nameidx, u_int32_t numlibs, char *nametab) -{ - struct nameidx *n; - int i; - - _dl_printf("libs:\n"); - for (i = 0; i < numlibs; i++) { - _dl_printf("lib %d offset %d id0 %d, id1 %d\n", i, - nameidx[i].name, nameidx[i].id0, nameidx[i].id1); - } - for (i = 0; i < numlibs; i++) { - n = &(nameidx[i]); - _dl_printf("nametab %p n %d\n", nametab, n->name); - _dl_printf("lib %s %x %x\n", nametab + n->name, n->id0, n->id1); - } -} - -void -prebind_dump_fixup(struct fixup *fixup, u_int32_t numfixups) -{ - struct fixup *f; - int i; - - _dl_printf("fixup: %d\n", numfixups); - for (i = 0; i < numfixups; i++) { - f = &(fixup[i]); - - _dl_printf("idx %d obj %d sym idx %d\n", - f->sym, f->obj_idx, f->sym_idx); - - } -} - -void -prebind_dump_libmap(u_int32_t *libmap, u_int32_t numlibs) -{ - int i; - - for (i = 0; i < numlibs; i++) { - //_dl_printf("lib%d off %d %s\n", i, libmap[i], strtab+libmap[i]); - _dl_printf("lib%d off %d\n", i, libmap[i]); - } -} - -void -dl_dump_footer(struct prebind_footer *footer) -{ -// _dl_printf("base %qd\n", (long long)footer->prebind_base); - _dl_printf("nameidx_idx %d\n", footer->nameidx_idx); - _dl_printf("symcache_idx %d\n", footer->symcache_idx); - _dl_printf("fixupcnt_idx %d\n", footer->fixupcnt_idx); - _dl_printf("fixup_cnt %d\n", footer->fixup_cnt); - _dl_printf("nametab_idx %d\n", footer->nametab_idx); - _dl_printf("symcache_cnt %d\n", footer->symcache_cnt); - _dl_printf("fixup_cnt %d\n", footer->fixup_cnt); - _dl_printf("numlibs %d\n", footer->numlibs); - _dl_printf("id0 %d\n", footer->id0); - _dl_printf("id1 %d\n", footer->id1); -// _dl_printf("orig_size %lld\n", (long long)footer->orig_size); - _dl_printf("version %d\n", footer->prebind_version); - _dl_printf("bind_id %c%c%c%c\n", footer->bind_id[0], - footer->bind_id[1], footer->bind_id[2], footer->bind_id[3]); -} -void -dump_prelink(Elf_Addr base, u_long size) -{ - u_int32_t *fixupidx, *fixupcnt, *libmap; - struct symcachetab *symcachetab; - struct prebind_footer *footer; - struct nameidx *nameidx; - struct fixup *fixup; - char *nametab, *id; - void *prebind_map; - int i; - - id = (char *) (base+size); - id -= 4; - DL_DEB(("id %c %c %c %c\n", id[0], id[1], id[2], id[3])); - footer = (void *) (base+size - sizeof (struct prebind_footer)); - dl_dump_footer(footer); - - prebind_map = (void *)base; - nameidx = prebind_map + footer->nameidx_idx; - symcachetab = prebind_map + footer->symcache_idx; - fixupidx = prebind_map + footer->fixup_idx; - nametab = prebind_map + footer->nametab_idx; - fixupcnt = prebind_map + footer->fixupcnt_idx; - libmap = prebind_map + footer->libmap_idx; - - prebind_dump_symcache(symcachetab, footer->symcache_cnt); - prebind_dump_nameidx(nameidx, footer->numlibs, nametab); - for (i = 0; i < footer->fixup_cnt; i++) { - _dl_printf("fixup %d cnt %d idx %d\n", i, fixupcnt[i], fixupidx[i]); - fixup = prebind_map + fixupidx[i]; - prebind_dump_fixup(fixup, fixupcnt[i]); - } - prebind_dump_libmap(libmap, footer->numlibs); -} -#endif /* DEBUG1 */ diff --git a/libexec/ld.so/dl_prebind.h b/libexec/ld.so/dl_prebind.h deleted file mode 100644 index 618817b826c..00000000000 --- a/libexec/ld.so/dl_prebind.h +++ /dev/null @@ -1,35 +0,0 @@ -/* $OpenBSD: dl_prebind.h,v 1.3 2015/11/02 07:19:14 guenther Exp $ */ -/* - * Copyright (c) 2006 Dale Rahn - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include "resolve.h" -#include "prebind.h" - -extern char *_dl_noprebind; -extern char *_dl_prebind_validate; -void _dl_prebind_pre_resolve(void); -void _dl_prebind_post_resolve(void); -void *prebind_load_fd(int fd, const char *name); -void prebind_load_exe(Elf_Phdr *phdp, elf_object_t *exe_obj); - -void prebind_validate(elf_object_t *req_obj, unsigned int symidx, int flags, - const Elf_Sym *ref_sym); - -void prebind_symcache(elf_object_t *object, int pltflag); -void prebind_free(elf_object_t *object); - -extern struct prebind_footer *footer; diff --git a/libexec/ld.so/hppa/syscall.h b/libexec/ld.so/hppa/syscall.h index 270e9bb2468..b64012d817d 100644 --- a/libexec/ld.so/hppa/syscall.h +++ b/libexec/ld.so/hppa/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.21 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.22 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -61,10 +61,4 @@ int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/i386/syscall.h b/libexec/ld.so/i386/syscall.h index 9b8a4bc352a..6d423ca3020 100644 --- a/libexec/ld.so/i386/syscall.h +++ b/libexec/ld.so/i386/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.25 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.26 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -61,10 +61,4 @@ int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/ld.so.1 b/libexec/ld.so/ld.so.1 index 9f8aa76c6cd..6095068269b 100644 --- a/libexec/ld.so/ld.so.1 +++ b/libexec/ld.so/ld.so.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ld.so.1,v 1.21 2014/02/22 02:54:36 guenther Exp $ +.\" $OpenBSD: ld.so.1,v 1.22 2016/07/04 21:15:06 guenther Exp $ .\" $NetBSD: rtld.1,v 1.2 1995/10/08 23:43:28 pk Exp $ .\" .\" Copyright (c) 1995 Paul Kranenburg @@ -29,7 +29,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: February 22 2014 $ +.Dd $Mdocdate: July 4 2016 $ .Dt LD.SO 1 .Os .Sh NAME @@ -161,13 +161,6 @@ are recognised and have their usual meaning. When set, be verbose about what .Nm does. -.Pp -.It Ev LD_NOPREBIND -When set, ignore any prebind data associated with the program or libraries. -.Pp -.It Ev LD_PREBINDVALIDATE -When set, perform symbol relocation of the given binary and the associated -libraries, compare the results against the prebind values, then exit. .El .Sh FILES .Bl -tag -width /var/run/ld.so.hintsXXX -compact diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c index 455b95f18a9..ff80119a6dd 100644 --- a/libexec/ld.so/library.c +++ b/libexec/ld.so/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.76 2016/06/08 11:58:59 kettenis Exp $ */ +/* $OpenBSD: library.c,v 1.77 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -32,7 +32,6 @@ #include #include #include -#include "dl_prebind.h" #include "syscall.h" #include "archdep.h" @@ -106,7 +105,6 @@ _dl_tryload_shlib(const char *libname, int type, int flags) Elf_Phdr *phdp; Elf_Phdr *ptls = NULL; struct stat sb; - void *prebind_data; #define ROUND_PG(x) (((x) + align) & ~(align)) #define TRUNC_PG(x) ((x) & ~(align)) @@ -288,8 +286,6 @@ _dl_tryload_shlib(const char *libname, int type, int flags) } } - prebind_data = prebind_load_fd(libfile, libname); - _dl_close(libfile); dynp = (Elf_Dyn *)((unsigned long)dynp + loff); @@ -297,7 +293,6 @@ _dl_tryload_shlib(const char *libname, int type, int flags) (Elf_Phdr *)((char *)libaddr + ehdr->e_phoff), ehdr->e_phnum,type, libaddr, loff); if (object) { - object->prebind_data = prebind_data; object->load_size = maxva - minva; /*XXX*/ object->load_list = load_list; /* set inode, dev from stat info */ diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index 870f54d7065..7a214da55b5 100644 --- a/libexec/ld.so/library_mquery.c +++ b/libexec/ld.so/library_mquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_mquery.c,v 1.53 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.54 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -32,7 +32,6 @@ #include #include #include -#include "dl_prebind.h" #include "syscall.h" #include "archdep.h" @@ -110,7 +109,6 @@ _dl_tryload_shlib(const char *libname, int type, int flags) Elf_Addr align = _dl_pagesz - 1, off, size; Elf_Phdr *ptls = NULL; struct stat sb; - void *prebind_data; char hbuf[4096]; #define ROUND_PG(x) (((x) + align) & ~(align)) @@ -304,8 +302,6 @@ retry: _dl_randombuf((char *)(phdp->p_vaddr + LOFF), phdp->p_memsz); - prebind_data = prebind_load_fd(libfile, libname); - _dl_close(libfile); dynp = (Elf_Dyn *)((unsigned long)dynp + LOFF); @@ -313,7 +309,6 @@ retry: (Elf_Phdr *)((char *)lowld->start + ehdr->e_phoff), ehdr->e_phnum, type, (Elf_Addr)lowld->start, LOFF); if (object) { - object->prebind_data = prebind_data; object->load_size = (Elf_Addr)load_end - (Elf_Addr)lowld->start; object->load_list = lowld; /* set inode, dev from stat info */ diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index e9aaa592873..691bbbf4d77 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.161 2016/06/08 11:58:59 kettenis Exp $ */ +/* $OpenBSD: loader.c,v 1.162 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -44,7 +44,6 @@ #include "resolve.h" #include "sod.h" #include "stdlib.h" -#include "dl_prebind.h" /* * Local decls. @@ -65,8 +64,6 @@ char *_dl_bindnow; char *_dl_traceld; char *_dl_debug; char *_dl_showmap; -char *_dl_noprebind; -char *_dl_prebind_validate; char *_dl_tracefmt1, *_dl_tracefmt2, *_dl_traceprog; int _dl_trust; @@ -220,8 +217,6 @@ _dl_setup_env(const char *argv0, char **envp) _dl_tracefmt1 = _dl_getenv("LD_TRACE_LOADED_OBJECTS_FMT1", envp); _dl_tracefmt2 = _dl_getenv("LD_TRACE_LOADED_OBJECTS_FMT2", envp); _dl_traceprog = _dl_getenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", envp); - _dl_noprebind = _dl_getenv("LD_NOPREBIND", envp); - _dl_prebind_validate = _dl_getenv("LD_PREBINDVALIDATE", envp); /* * Don't allow someone to change the search paths if he runs @@ -474,11 +469,6 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) next_load->start = (char *)TRUNC_PG(phdp->p_vaddr) + exe_loff; next_load->size = (phdp->p_vaddr & align) + phdp->p_filesz; next_load->prot = PFLAGS(phdp->p_flags); - - if (phdp->p_flags & 0x08000000) { -// dump_prelink(phdp->p_vaddr + exe_loff, phdp->p_memsz); - prebind_load_exe(phdp, exe_obj); - } break; case PT_TLS: if (phdp->p_filesz > phdp->p_memsz) { @@ -537,14 +527,10 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) * Everything should be in place now for doing the relocation * and binding. Call _dl_rtld to do the job. Fingers crossed. */ - - _dl_prebind_pre_resolve(); failed = 0; if (_dl_traceld == NULL) failed = _dl_rtld(_dl_objects); - _dl_prebind_post_resolve(); - if (_dl_debug || _dl_traceld) { if (_dl_traceld) _dl_pledge("stdio rpath", NULL); @@ -665,14 +651,12 @@ _dl_rtld(elf_object_t *object) _dl_symcache = NULL; } } - prebind_symcache(object, SYM_NOTPLT); /* * Do relocation information first, then GOT. */ fails =_dl_md_reloc(object, DT_REL, DT_RELSZ); fails += _dl_md_reloc(object, DT_RELA, DT_RELASZ); - prebind_symcache(object, SYM_PLT); fails += _dl_md_reloc_got(object, !(_dl_bindnow || object->obj_flags & DF_1_NOW)); diff --git a/libexec/ld.so/m88k/syscall.h b/libexec/ld.so/m88k/syscall.h index d1de184c957..43a3b6b4727 100644 --- a/libexec/ld.so/m88k/syscall.h +++ b/libexec/ld.so/m88k/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.17 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.18 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -60,12 +60,6 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - static inline void * _dl_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { diff --git a/libexec/ld.so/mips64/syscall.h b/libexec/ld.so/mips64/syscall.h index 8b85bed5124..20727d99028 100644 --- a/libexec/ld.so/mips64/syscall.h +++ b/libexec/ld.so/mips64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.23 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.24 2016/07/04 21:15:07 guenther Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -60,12 +60,6 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); -static inline off_t -_dl_lseek(int fd, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fd, 0, offset, whence); -} - static inline void * _dl_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h index 42dbcfd57c2..aa927445622 100644 --- a/libexec/ld.so/powerpc/syscall.h +++ b/libexec/ld.so/powerpc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.41 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.42 2016/07/04 21:15:07 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -61,10 +61,4 @@ ssize_t _dl_write(int, const char *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/prebind.h b/libexec/ld.so/prebind.h deleted file mode 100644 index 369308a8ca0..00000000000 --- a/libexec/ld.so/prebind.h +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: prebind.h,v 1.2 2006/05/12 22:14:04 drahn Exp $ */ -/* - * Copyright (c) 2006 Dale Rahn - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define PREBIND_VERSION 2 -struct prebind_footer { - off_t prebind_base; - u_int32_t nameidx_idx; - u_int32_t symcache_idx; - u_int32_t pltsymcache_idx; - u_int32_t fixup_idx; - u_int32_t nametab_idx; - u_int32_t fixupcnt_idx; - u_int32_t libmap_idx; - - u_int32_t symcache_cnt; - u_int32_t pltsymcache_cnt; - u_int32_t fixup_cnt; - u_int32_t numlibs; - u_int32_t prebind_size; - - u_int32_t id0; - u_int32_t id1; - /* do not modify or add fields below this point in the struct */ - off_t orig_size; - u_int32_t prebind_version; - char bind_id[4]; -#define BIND_ID0 'P' -#define BIND_ID1 'R' -#define BIND_ID2 'E' -#define BIND_ID3 'B' -}; - - -struct nameidx { - u_int32_t name; - u_int32_t id0; - u_int32_t id1; -}; - -struct symcachetab { - u_int32_t idx; - u_int32_t obj_idx; - u_int32_t sym_idx; -}; - -struct fixup { - u_int32_t sym; - u_int32_t obj_idx; - u_int32_t sym_idx; -}; diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c index 345fbcd2d7c..d6c2e525c6e 100644 --- a/libexec/ld.so/resolve.c +++ b/libexec/ld.so/resolve.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.c,v 1.72 2016/03/20 02:29:51 guenther Exp $ */ +/* $OpenBSD: resolve.c,v 1.73 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -37,7 +37,6 @@ #include "archdep.h" #include "path.h" #include "resolve.h" -#include "dl_prebind.h" /* substitution types */ typedef enum { @@ -498,8 +497,6 @@ _dl_find_symbol_bysym(elf_object_t *req_obj, unsigned int symidx, *this = _dl_symcache[symidx].sym; if (pobj) *pobj = sobj; - if (_dl_prebind_validate) /* XXX */ - prebind_validate(req_obj, symidx, flags, ref_sym); return sobj->obj_base; } diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h index 7881b4a89a5..ace0e960b1a 100644 --- a/libexec/ld.so/resolve.h +++ b/libexec/ld.so/resolve.h @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.h,v 1.77 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: resolve.h,v 1.78 2016/07/04 21:15:06 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -137,8 +137,6 @@ struct elf_object { elf_object_t *load_object; struct sod sod; - void *prebind_data; - /* for object confirmation */ dev_t dev; ino_t inode; diff --git a/libexec/ld.so/sh/syscall.h b/libexec/ld.so/sh/syscall.h index c98b8e11cec..3b02caa2423 100644 --- a/libexec/ld.so/sh/syscall.h +++ b/libexec/ld.so/sh/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.19 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.20 2016/07/04 21:15:07 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -61,10 +61,4 @@ int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/sparc/syscall.h b/libexec/ld.so/sparc/syscall.h index a1f1cff714c..87515b784b6 100644 --- a/libexec/ld.so/sparc/syscall.h +++ b/libexec/ld.so/sparc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.26 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.27 2016/07/04 21:15:07 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -60,10 +60,4 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/sparc64/syscall.h b/libexec/ld.so/sparc64/syscall.h index 6fc3aa31934..7507dd1d662 100644 --- a/libexec/ld.so/sparc64/syscall.h +++ b/libexec/ld.so/sparc64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.33 2016/05/07 19:05:23 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.34 2016/07/04 21:15:07 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -60,10 +60,4 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); -static inline off_t -_dl_lseek(int fildes, off_t offset, int whence) -{ - return _dl__syscall((quad_t)SYS_lseek, fildes, 0, offset, whence); -} - #endif /*__DL_SYSCALL_H__*/