diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2017-01-24 07:48:38 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2017-01-24 07:48:38 +0000 |
commit | c66416e633310f06dfbeaa655d3e2826d4c42dc6 (patch) | |
tree | 871022ef5bc45fdadb9027dd35c237840f023803 | |
parent | a25395adead1f5541203d945e1c673202a0c6395 (diff) |
On fatal errors, kill ourselves with thrkill(0,9,NULL) instead of
simply exiting, via helper functions _dl_die(), _dl_diedie(), and
_dl_oom().
prompted by a complaint from jsing@
ok jsing@ deraadt@
54 files changed, 278 insertions, 323 deletions
diff --git a/libexec/ld.so/aarch64/archdep.h b/libexec/ld.so/aarch64/archdep.h index 4b3b13b6d11..8610a62571d 100644 --- a/libexec/ld.so/aarch64/archdep.h +++ b/libexec/ld.so/aarch64/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.3 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.4 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -49,9 +49,6 @@ RELOC_DYN(Elf64_Rela *r, const Elf64_Sym *s, Elf64_Addr *p, unsigned long v) } else if (ELF64_R_TYPE(r->r_info) == R_AARCH64_ABS64) { *p = v + s->st_value + r->r_addend; } else { -#if !defined(RCRT0) - _dl_printf("unknown bootstrap relocation\n"); -#endif _dl_exit(6); } } diff --git a/libexec/ld.so/aarch64/ldasm.S b/libexec/ld.so/aarch64/ldasm.S index 491d05d5e17..785f5dec102 100644 --- a/libexec/ld.so/aarch64/ldasm.S +++ b/libexec/ld.so/aarch64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.1 2017/01/11 14:11:27 patrick Exp $ */ +/* $OpenBSD: ldasm.S,v 1.2 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2016 Dale Rahn @@ -154,6 +154,7 @@ DL_SYSCALL(pledge) DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) DL_SYSCALL2(set_tcb,__set_tcb) +DL_SYSCALL(thrkill) DL_SYSCALL(getdents) diff --git a/libexec/ld.so/aarch64/rtld_machine.c b/libexec/ld.so/aarch64/rtld_machine.c index d1926e9da78..9546590a79f 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.2 2017/01/23 10:30:15 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.3 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -120,10 +120,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) if (rels == NULL) return(0); - if (relrel > numrel) { - _dl_printf("relcount > numrel: %ld > %ld\n", relrel, numrel); - _dl_exit(20); - } + if (relrel > numrel) + _dl_die("relcount > numrel: %ld > %ld", relrel, numrel); /* * unprotect some segments if we need it. @@ -143,10 +141,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) Elf_Addr *where; #ifdef DEBUG - if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELCOUNT wrong\n"); - _dl_exit(20); - } + if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELCOUNT wrong"); #endif where = (Elf_Addr *)(rels->r_offset + loff); *where += loff; @@ -159,14 +155,10 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) type = ELF_R_TYPE(rels->r_info); - if (type >= nitems(reloc_target_flags)) { - _dl_printf(" bad relocation %ld %d\n", i, type); - _dl_exit(1); - } - if ((reloc_target_flags[type] & _RF_V)==0) { - _dl_printf(" bad relocation %ld %d\n", i, type); - _dl_exit(1); - } + if (type >= nitems(reloc_target_flags) || + (reloc_target_flags[type] & _RF_V) == 0) + _dl_die("bad relocation %ld %d", i, type); + if (type == R_TYPE(NONE)) continue; @@ -349,10 +341,8 @@ _dl_bind(elf_object_t *object, int relidx) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value; diff --git a/libexec/ld.so/aarch64/syscall.h b/libexec/ld.so/aarch64/syscall.h index 56d19a816f7..ae97f82f040 100644 --- a/libexec/ld.so/aarch64/syscall.h +++ b/libexec/ld.so/aarch64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.2 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.3 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -58,6 +58,8 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); +__dead +void _dl_thrkill(pid_t, int, void *); 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/alpha/archdep.h b/libexec/ld.so/alpha/archdep.h index 6bac4b9758f..36720e0d4d6 100644 --- a/libexec/ld.so/alpha/archdep.h +++ b/libexec/ld.so/alpha/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.19 2017/01/20 10:40:30 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.20 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -53,7 +53,6 @@ RELOC_DYN(Elf64_Rela *r, const Elf64_Sym *s, Elf64_Addr *p, unsigned long v) } else if (ELF64_R_TYPE(r->r_info) == RELOC_GLOB_DAT) { *p = v + s->st_value + r->r_addend; } else { - _dl_printf("unknown bootstrap relocation\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/alpha/ldasm.S b/libexec/ld.so/alpha/ldasm.S index 68b68fc419c..f447f2f37ae 100644 --- a/libexec/ld.so/alpha/ldasm.S +++ b/libexec/ld.so/alpha/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.38 2016/08/31 13:18:57 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.39 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -325,5 +325,6 @@ DL_SYSCALL(read) DL_SYSCALL(readlink) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(sysctl) +DL_SYSCALL(thrkill) DL_SYSCALL(utrace) DL_SYSCALL(write) diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c index 4a3fc307faf..21eb71213d3 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.59 2016/06/21 15:25:36 deraadt Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.60 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -69,10 +69,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) if (relas == NULL) return(0); - if (relrel > numrela) { - _dl_printf("relacount > numrel: %ld > %ld\n", relrel, numrela); - _dl_exit(20); - } + if (relrel > numrela) + _dl_die("relacount > numrel: %ld > %ld", relrel, numrela); /* * unprotect some segments if we need it. @@ -93,10 +91,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) Elf_Addr *r_addr; #ifdef DEBUG - if (ELF64_R_TYPE(relas->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELACOUNT wrong\n"); - _dl_exit(20); - } + if (ELF64_R_TYPE(relas->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELACOUNT wrong"); #endif r_addr = (Elf64_Addr *)(relas->r_offset + loff); @@ -180,11 +176,9 @@ _dl_printf("unaligned RELATIVE: %p type: %d %s 0x%lx -> 0x%lx\n", r_addr, case R_TYPE(NONE): break; default: - _dl_printf("%s:" - " %s: unsupported relocation '%s' %d at %lx\n", - __progname, object->load_name, symn, + _dl_die("%s: unsupported relocation '%s' %d at %lx", + object->load_name, symn, ELF64_R_TYPE(relas->r_info), r_addr ); - _dl_exit(1); } continue; resolve_failed: @@ -230,10 +224,8 @@ _dl_bind(elf_object_t *object, int reloff) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value + rela->r_addend; diff --git a/libexec/ld.so/alpha/syscall.h b/libexec/ld.so/alpha/syscall.h index 49203b0b761..4446d2bcbf2 100644 --- a/libexec/ld.so/alpha/syscall.h +++ b/libexec/ld.so/alpha/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.37 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.38 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -57,5 +57,7 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +__dead +void _dl_thrkill(pid_t, int, void *); #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/amd64/ldasm.S b/libexec/ld.so/amd64/ldasm.S index 76a1945733e..3407f0b0472 100644 --- a/libexec/ld.so/amd64/ldasm.S +++ b/libexec/ld.so/amd64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.25 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.26 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -101,6 +101,7 @@ DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL2(set_tcb,__set_tcb) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(sysctl) +DL_SYSCALL(thrkill) 1: /* error: result = -errno; - handled here. */ diff --git a/libexec/ld.so/amd64/rtld_machine.c b/libexec/ld.so/amd64/rtld_machine.c index 14de6c96ce9..7e6c65ed80b 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.27 2017/01/23 10:30:58 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.28 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -188,10 +188,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) if (rels == NULL) return(0); - if (relrel > numrel) { - _dl_printf("relacount > numrel: %ld > %ld\n", relrel, numrel); - _dl_exit(20); - } + if (relrel > numrel) + _dl_die("relacount > numrel: %ld > %ld", relrel, numrel); /* * unprotect some segments if we need it. @@ -209,10 +207,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) Elf_Addr *where; #ifdef DEBUG - if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELACOUNT wrong\n"); - _dl_exit(20); - } + if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELACOUNT wrong"); #endif where = (Elf_Addr *)(rels->r_offset + loff); *where = rels->r_addend + loff; @@ -225,10 +221,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) type = ELF_R_TYPE(rels->r_info); - if (RELOC_ERROR(type)) { - _dl_printf("relocation error %d idx %ld\n", type, i); - _dl_exit(20); - } + if (RELOC_ERROR(type)) + _dl_die("relocation error %d idx %ld", type, i); if (type == R_TYPE(NONE)) continue; @@ -362,10 +356,8 @@ _dl_bind(elf_object_t *object, int index) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value + rel->r_addend; diff --git a/libexec/ld.so/amd64/syscall.h b/libexec/ld.so/amd64/syscall.h index 0af7eefea86..4f992e0a031 100644 --- a/libexec/ld.so/amd64/syscall.h +++ b/libexec/ld.so/amd64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.24 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -58,6 +58,8 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); +__dead +void _dl_thrkill(pid_t, int, void *); 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/arm/archdep.h b/libexec/ld.so/arm/archdep.h index 20f45811f24..7ccdd1dc068 100644 --- a/libexec/ld.so/arm/archdep.h +++ b/libexec/ld.so/arm/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.11 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.12 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -53,8 +53,6 @@ RELOC_DYN(Elf_Rel *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v) } else if (ELF_R_TYPE(r->r_info) == R_ARM_ABS32) { *p += v + s->st_value; } else { - /* XXX - printf might not work here, but we give it a shot. */ - _dl_printf("Unknown bootstrap relocation.\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/arm/ldasm.S b/libexec/ld.so/arm/ldasm.S index 90e1acaf7c2..5d09a1cb623 100644 --- a/libexec/ld.so/arm/ldasm.S +++ b/libexec/ld.so/arm/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.24 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -134,6 +134,7 @@ DL_SYSCALL(pledge) DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) DL_SYSCALL2(set_tcb,__set_tcb) +DL_SYSCALL(thrkill) DL_SYSCALL(getdents) diff --git a/libexec/ld.so/arm/rtld_machine.c b/libexec/ld.so/arm/rtld_machine.c index eebe35483b5..ec66b58f015 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.24 2017/01/23 10:30:58 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -180,10 +180,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) if (rels == NULL) return(0); - if (relrel > numrel) { - _dl_printf("relcount > numrel: %ld > %ld\n", relrel, numrel); - _dl_exit(20); - } + if (relrel > numrel) + _dl_die("relcount > numrel: %ld > %ld", relrel, numrel); /* * unprotect some segments if we need it. @@ -203,10 +201,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) Elf_Addr *where; #ifdef DEBUG - if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELCOUNT wrong\n"); - _dl_exit(20); - } + if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELCOUNT wrong"); #endif where = (Elf_Addr *)(rels->r_offset + loff); *where += loff; @@ -219,10 +215,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) type = ELF_R_TYPE(rels->r_info); - if (reloc_target_flags[type] & _RF_E) { - _dl_printf(" bad relocation %ld %d\n", i, type); - _dl_exit(1); - } + if (reloc_target_flags[type] & _RF_E) + _dl_die("bad relocation %ld %d", i, type); if (type == R_TYPE(NONE)) continue; @@ -407,10 +401,8 @@ _dl_bind(elf_object_t *object, int relidx) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value; diff --git a/libexec/ld.so/arm/syscall.h b/libexec/ld.so/arm/syscall.h index 280d1474983..990adee20bd 100644 --- a/libexec/ld.so/arm/syscall.h +++ b/libexec/ld.so/arm/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.24 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -58,6 +58,8 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); +__dead +void _dl_thrkill(pid_t, int, void *); 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/dl_printf.c b/libexec/ld.so/dl_printf.c index 425974753f8..8514292b6bf 100644 --- a/libexec/ld.so/dl_printf.c +++ b/libexec/ld.so/dl_printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dl_printf.c,v 1.18 2017/01/23 13:00:09 guenther Exp $ */ +/* $OpenBSD: dl_printf.c,v 1.19 2017/01/24 07:48:36 guenther Exp $ */ /*- * Copyright (c) 1993 @@ -56,6 +56,7 @@ #include <sys/types.h> #include <stdarg.h> +#include "resolve.h" /* for __progname */ #include "syscall.h" #include "util.h" @@ -132,8 +133,10 @@ kdoprnt(int fd, const char *fmt, va_list ap) for (;;) { while ((ch = *fmt++) != '%') { - if (ch == '\0') + if (ch == '\0') { + _dl_flushbuf(); return; + } putcharfd(ch, fd); } lflag = 0; @@ -221,7 +224,6 @@ reswitch: putcharfd(ch, fd); } } - _dl_flushbuf(); } static void @@ -238,3 +240,30 @@ kprintn(int fd, unsigned long ul, int base) putcharfd(*--p, fd); } while (p > buf); } + +static char ldso[] = "ld.so: "; + +__dead void +_dl_die(const char *fmt, ...) +{ + va_list ap; + + _dl_printf("%s%s: ", ldso, __progname); + va_start(ap, fmt); + kdoprnt(2, fmt, ap); + _dl_write(2, "\n", 1); + va_end(ap); + + _dl_diedie(); +} + +__dead void +_dl_oom(void) +{ + static const char oom[] = ": out of memory\n"; + + _dl_write(2, ldso, sizeof(ldso) - 1); + _dl_write(2, __progname, _dl_strlen(__progname)); + _dl_write(2, oom, sizeof(oom) - 1); + _dl_diedie(); +} diff --git a/libexec/ld.so/hppa/archdep.h b/libexec/ld.so/hppa/archdep.h index 255c4850004..ad2cd198d55 100644 --- a/libexec/ld.so/hppa/archdep.h +++ b/libexec/ld.so/hppa/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.14 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.15 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -49,7 +49,6 @@ RELOC_JMPREL(Elf_RelA *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v, p[0] = v + s->st_value + r->r_addend; p[1] = (Elf_Addr)pltgot; } else { - _dl_printf("unknown bootstrap relocation\n"); _dl_exit(5); } } @@ -65,7 +64,6 @@ RELOC_DYN(Elf_RelA *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v) } else if (ELF_R_TYPE(r->r_info) == RELOC_PLABEL32) { *p = v + s->st_value + r->r_addend; } else { - _dl_printf("unknown bootstrap relocation\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/hppa/ldasm.S b/libexec/ld.so/hppa/ldasm.S index 967d95cf6e0..c060113d263 100644 --- a/libexec/ld.so/hppa/ldasm.S +++ b/libexec/ld.so/hppa/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.22 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.23 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -284,4 +284,10 @@ ENTRY(_dl_pledge,0) nop EXIT(_dl_pledge) +ENTRY(_dl_thrkill,0) + SYSCALL(thrkill) + bv r0(rp) + nop +EXIT(_dl_thrkill) + .end diff --git a/libexec/ld.so/hppa/rtld_machine.c b/libexec/ld.so/hppa/rtld_machine.c index 1f6a9c80a2e..46c91d9139c 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.35 2017/01/09 22:51:04 kettenis Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.36 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Michael Shalayeff @@ -91,7 +91,7 @@ _dl_md_plabel(Elf_Addr pc, Elf_Addr *sl) if (p == NULL) { p = _dl_malloc(sizeof(*p)); if (p == NULL) - _dl_exit(5); + _dl_oom(); p->pc = pc; p->sl = sl; SPLAY_INSERT(_dl_md_plabels, &_dl_md_plabel_root, p); @@ -462,10 +462,8 @@ _dl_bind(elf_object_t *object, int reloff) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); value = ooff + this->st_value + rela->r_addend; diff --git a/libexec/ld.so/hppa/syscall.h b/libexec/ld.so/hppa/syscall.h index 0af7eefea86..4f992e0a031 100644 --- a/libexec/ld.so/hppa/syscall.h +++ b/libexec/ld.so/hppa/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.24 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -58,6 +58,8 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); +__dead +void _dl_thrkill(pid_t, int, void *); 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/i386/archdep.h b/libexec/ld.so/i386/archdep.h index 69857cfa091..6ca4e73c3d2 100644 --- a/libexec/ld.so/i386/archdep.h +++ b/libexec/ld.so/i386/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.18 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.19 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -50,7 +50,6 @@ RELOC_DYN(Elf32_Rel *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v) } else if (ELF32_R_TYPE(r->r_info) == RELOC_32) { *p += v + s->st_value; } else { - _dl_printf("unknown bootstrap relocation\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/i386/ldasm.S b/libexec/ld.so/i386/ldasm.S index 28b074dd1ce..7505b25bcd9 100644 --- a/libexec/ld.so/i386/ldasm.S +++ b/libexec/ld.so/i386/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.28 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.29 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -97,6 +97,17 @@ __CONCAT(_dl_,n): ;\ jb .L_cerr ;\ ret +#define DL_SYSCALL(n) DL_SYSCALL2(n,n) +#define DL_SYSCALL2(n,c) \ + .section ".text" ;\ + .align 4 ;\ + .global __CONCAT(_dl_,n) ;\ + .type __CONCAT(_dl_,n),@function ;\ +__CONCAT(_dl_,n): ;\ + __DO_SYSCALL(c) ;\ + jb .L_cerr ;\ + ret + DL_SYSCALL(close) .section ".text" @@ -108,7 +119,6 @@ _dl_exit: int $0x80 ret - DL_SYSCALL(issetugid) DL_SYSCALL(getthrid) DL_SYSCALL2(_syscall,__syscall) @@ -127,6 +137,7 @@ DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) DL_SYSCALL(getdents) DL_SYSCALL2(set_tcb,__set_tcb) +DL_SYSCALL(thrkill) .L_cerr: /* error: result = -errno; - handled here. */ diff --git a/libexec/ld.so/i386/rtld_machine.c b/libexec/ld.so/i386/rtld_machine.c index f5d1521df13..027a7a389cc 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.35 2016/07/04 04:33:35 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.36 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -188,10 +188,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) if (rels == NULL) return(0); - if (relrel > numrel) { - _dl_printf("relcount > numrel: %ld > %ld\n", relrel, numrel); - _dl_exit(20); - } + if (relrel > numrel) + _dl_die("relcount > numrel: %ld > %ld", relrel, numrel); /* * unprotect some segments if we need it. @@ -209,10 +207,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) Elf_Addr *where; #ifdef DEBUG - if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELCOUNT wrong\n"); - _dl_exit(20); - } + if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELCOUNT wrong"); #endif where = (Elf_Addr *)(rels->r_offset + loff); *where += loff; @@ -386,10 +382,8 @@ _dl_bind(elf_object_t *object, int index) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value; diff --git a/libexec/ld.so/i386/syscall.h b/libexec/ld.so/i386/syscall.h index a4ec39e9026..a0a7f969236 100644 --- a/libexec/ld.so/i386/syscall.h +++ b/libexec/ld.so/i386/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.28 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.29 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -58,6 +58,8 @@ int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); void _dl_set_tcb(void *); +__dead +void _dl_thrkill(pid_t, int, void *); 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/library.c b/libexec/ld.so/library.c index ac63b964dd6..adb57041267 100644 --- a/libexec/ld.so/library.c +++ b/libexec/ld.so/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.79 2016/08/12 20:39:01 deraadt Exp $ */ +/* $OpenBSD: library.c,v 1.80 2017/01/24 07:48:36 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -236,7 +236,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags) res = NULL; /* silence gcc */ next_load = _dl_calloc(1, sizeof(struct load_list)); if (next_load == NULL) - _dl_exit(7); + _dl_oom(); next_load->next = load_list; load_list = next_load; next_load->start = start; diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index becf2735e16..65b04557a27 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.56 2016/08/12 20:39:01 deraadt Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.57 2017/01/24 07:48:36 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -176,7 +176,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags) if (size != 0) { ld = _dl_malloc(sizeof(struct load_list)); if (ld == NULL) - _dl_exit(7); + _dl_oom(); ld->start = NULL; ld->size = size; ld->moff = TRUNC_PG(phdp->p_vaddr); @@ -191,7 +191,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags) /* This phdr has a zfod section */ ld = _dl_calloc(1, sizeof(struct load_list)); if (ld == NULL) - _dl_exit(7); + _dl_oom(); ld->start = NULL; ld->size = ROUND_PG(off + phdp->p_memsz) - ROUND_PG(size); diff --git a/libexec/ld.so/library_subr.c b/libexec/ld.so/library_subr.c index da476b8d309..b51500e70cc 100644 --- a/libexec/ld.so/library_subr.c +++ b/libexec/ld.so/library_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library_subr.c,v 1.46 2017/01/22 01:20:36 guenther Exp $ */ +/* $OpenBSD: library_subr.c,v 1.47 2017/01/24 07:48:36 guenther Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -320,7 +320,7 @@ _dl_load_shlib(const char *libname, elf_object_t *parent, int type, int flags) char *lpath, *lname; lpath = _dl_strdup(libname); if (lpath == NULL) - _dl_exit(5); + _dl_oom(); lname = _dl_strrchr(lpath, '/'); if (lname == NULL) { _dl_free(lpath); @@ -437,7 +437,7 @@ _dl_link_dlopen(elf_object_t *dep) n = _dl_malloc(sizeof *n); if (n == NULL) - _dl_exit(5); + _dl_oom(); n->data = dep; TAILQ_INSERT_TAIL(&_dlopened_child_list, n, next_sib); @@ -500,7 +500,7 @@ _dl_link_grpref(elf_object_t *load_group, elf_object_t *load_object) n = _dl_malloc(sizeof *n); if (n == NULL) - _dl_exit(7); + _dl_oom(); n->data = load_group; TAILQ_INSERT_TAIL(&load_object->grpref_list, n, next_sib); load_group->grprefcount++; @@ -513,7 +513,7 @@ _dl_link_child(elf_object_t *dep, elf_object_t *p) n = _dl_malloc(sizeof *n); if (n == NULL) - _dl_exit(7); + _dl_oom(); n->data = dep; TAILQ_INSERT_TAIL(&p->child_list, n, next_sib); @@ -544,7 +544,7 @@ _dl_link_grpsym(elf_object_t *object, int checklist) n = _dl_malloc(sizeof *n); if (n == NULL) - _dl_exit(8); + _dl_oom(); n->data = object; TAILQ_INSERT_TAIL(&_dl_loading_object->grpsym_list, n, next_sib); } diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index 0ce7f59595a..f7718eded52 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.168 2017/01/09 22:51:04 kettenis Exp $ */ +/* $OpenBSD: loader.c,v 1.169 2017/01/24 07:48:36 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -189,19 +189,14 @@ _dl_dopreload(char *paths) elf_object_t *shlib; dp = paths = _dl_strdup(paths); - if (dp == NULL) { - _dl_printf("preload: out of memory"); - _dl_exit(1); - } + if (dp == NULL) + _dl_oom(); while ((cp = _dl_strsep(&dp, ":")) != NULL) { shlib = _dl_load_shlib(cp, _dl_objects, OBJTYPE_LIB, _dl_objects->obj_flags); - if (shlib == NULL) { - _dl_printf("%s: can't preload library '%s'\n", - __progname, cp); - _dl_exit(4); - } + if (shlib == NULL) + _dl_die("can't preload library '%s'", cp); _dl_add_object(shlib); _dl_link_child(shlib, _dl_objects); } @@ -308,7 +303,7 @@ _dl_load_dep_libs(elf_object_t *object, int flags, int booting) sizeof(int)); if (liblist == NULL || randomlist == NULL) - _dl_exit(5); + _dl_oom(); for (dynp = dynobj->load_dyn, loop = 0; dynp->d_tag; dynp++) @@ -341,17 +336,15 @@ _dl_load_dep_libs(elf_object_t *object, int flags, int booting) OBJTYPE_LIB, depflags); if (depobj == 0) { if (booting) { - _dl_printf( - "%s: can't load library '%s'\n", - __progname, libname); - _dl_exit(4); - } else { - DL_DEB(("dlopen: failed to open %s\n", - libname)); - _dl_free(liblist); - _dl_free(randomlist); - return (1); + _dl_die( + "can't load library '%s'", + libname); } + DL_DEB(("dlopen: failed to open %s\n", + libname)); + _dl_free(liblist); + _dl_free(randomlist); + return (1); } liblist[randomlist[loop]].depobj = depobj; } @@ -458,7 +451,7 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) next_load = _dl_calloc(1, sizeof(struct load_list)); if (next_load == NULL) - _dl_exit(5); + _dl_oom(); next_load->next = load_list; load_list = next_load; next_load->start = (char *)TRUNC_PG(phdp->p_vaddr) + exe_loff; @@ -466,11 +459,8 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) next_load->prot = PFLAGS(phdp->p_flags); break; case PT_TLS: - if (phdp->p_filesz > phdp->p_memsz) { - _dl_printf("%s: invalid tls data.\n", - __progname); - _dl_exit(5); - } + if (phdp->p_filesz > phdp->p_memsz) + _dl_die("invalid tls data"); ptls = phdp; break; case PT_GNU_RELRO: @@ -491,7 +481,7 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) n = _dl_malloc(sizeof *n); if (n == NULL) - _dl_exit(5); + _dl_oom(); n->data = exe_obj; TAILQ_INSERT_TAIL(&_dlopened_child_list, n, next_sib); exe_obj->opencount++; @@ -545,7 +535,7 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) if (map_link) { debug_map = _dl_malloc(sizeof(*debug_map)); if (debug_map == NULL) - _dl_exit(5); + _dl_oom(); debug_map->r_version = 1; debug_map->r_map = (struct link_map *)_dl_objects; debug_map->r_brk = (Elf_Addr)_dl_debug_state; @@ -585,7 +575,7 @@ _dl_boot(const char **argv, char **envp, const long dyn_loff, long *dl_data) (failed == 0) ? "success":"failed")); if (failed != 0) - _dl_exit(1); + _dl_die("relocation failed"); if (_dl_traceld) _dl_exit(0); diff --git a/libexec/ld.so/m88k/archdep.h b/libexec/ld.so/m88k/archdep.h index ed258002dd1..af22305dae2 100644 --- a/libexec/ld.so/m88k/archdep.h +++ b/libexec/ld.so/m88k/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.4 2017/01/20 10:40:30 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.5 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -49,8 +49,6 @@ RELOC_DYN(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v) if (ELF32_R_TYPE(r->r_info) == RELOC_BBASED_32) { *p = v + r->r_addend; } else { - /* _dl_printf("Unexpected bootstrap relocation (%d).\n", - ELF32_R_TYPE(r->r_info)); */ _dl_exit(6); } } diff --git a/libexec/ld.so/m88k/ldasm.S b/libexec/ld.so/m88k/ldasm.S index 8293c8812a8..a5eba334cfd 100644 --- a/libexec/ld.so/m88k/ldasm.S +++ b/libexec/ld.so/m88k/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.23 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.24 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -190,6 +190,7 @@ DL_SYSCALL(pledge) DL_SYSCALL2(getcwd,__getcwd) DL_SYSCALL(sysctl) DL_SYSCALL(getdents) +DL_SYSCALL(thrkill) ENTRY(_dl_cerror) jmp.n %r1 diff --git a/libexec/ld.so/m88k/rtld_machine.c b/libexec/ld.so/m88k/rtld_machine.c index e36f70963b5..d5a24da6b0b 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.17 2016/09/16 02:20:08 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.18 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -87,10 +87,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) if (relas == NULL) return(0); - if (relrela > numrela) { - _dl_printf("relacount > numrel: %d > %d\n", relrela, numrela); - _dl_exit(20); - } + if (relrela > numrela) + _dl_die("relacount > numrel: %d > %d", relrela, numrela); /* * Change protection of all write protected segments in the object @@ -221,13 +219,10 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) case RELOC_DISP26: newval = prev_ooff + addend; newval -= (Elf_Addr)r_addr; - if ((newval >> 28) != 0 && (newval >> 28) != 0x0f) { - _dl_printf("%s: %s: out of range DISP26" + if ((newval >> 28) != 0 && (newval >> 28) != 0x0f) + _dl_die("%s: out of range DISP26" " relocation to '%s' at %x\n", - __progname, object->load_name, symn, - r_addr); - _dl_exit(1); - } + object->load_name, symn, r_addr); *r_addr = (*r_addr & 0xfc000000) | (((int32_t)newval >> 2) & 0x03ffffff); _dl_cacheflush((unsigned long)r_addr, 4); @@ -241,10 +236,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) *r_addr = newval; break; default: - _dl_printf("%s:" - " %s: unsupported relocation '%s' %d at %x\n", - __progname, object->load_name, symn, type, r_addr); - _dl_exit(1); + _dl_die("%s: unsupported relocation '%s' %d at %x\n", + object->load_name, symn, type, r_addr); } } @@ -381,10 +374,8 @@ _dl_bind(elf_object_t *object, int reloff) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL | SYM_WARNNOTFOUND | SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value; diff --git a/libexec/ld.so/m88k/syscall.h b/libexec/ld.so/m88k/syscall.h index 87aa864536a..f9dd8ccf28c 100644 --- a/libexec/ld.so/m88k/syscall.h +++ b/libexec/ld.so/m88k/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.20 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.21 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -57,6 +57,8 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +__dead +void _dl_thrkill(pid_t, int, void *); 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/malloc.c b/libexec/ld.so/malloc.c index 1c2cc6c0b44..c233d3046f6 100644 --- a/libexec/ld.so/malloc.c +++ b/libexec/ld.so/malloc.c @@ -169,25 +169,10 @@ hash(void *p) return sum; } -static void +static __dead void wrterror(char *msg) { - char *q = " error: "; - struct iovec iov[4]; - - iov[0].iov_base = g_pool->func; - iov[0].iov_len = _dl_strlen(g_pool->func); - iov[1].iov_base = q; - iov[1].iov_len = _dl_strlen(q); - iov[2].iov_base = msg; - iov[2].iov_len = _dl_strlen(msg); - iov[3].iov_base = "\n"; - iov[3].iov_len = 1; - _dl_write(STDERR_FILENO, iov[0].iov_base, iov[0].iov_len); - _dl_write(STDERR_FILENO, iov[1].iov_base, iov[1].iov_len); - _dl_write(STDERR_FILENO, iov[2].iov_base, iov[2].iov_len); - _dl_write(STDERR_FILENO, iov[3].iov_base, iov[3].iov_len); - _dl_exit(7); + _dl_die("%s error: %s", g_pool->func, msg); } static void diff --git a/libexec/ld.so/mips64/ldasm.S b/libexec/ld.so/mips64/ldasm.S index d3d275bbc2b..f7208cd0d9d 100644 --- a/libexec/ld.so/mips64/ldasm.S +++ b/libexec/ld.so/mips64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.21 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.22 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -168,3 +168,4 @@ DL_SYSCALL2_NOERR(set_tcb,__set_tcb) DL_SYSCALL(sysctl) DL_SYSCALL(utrace) DL_SYSCALL(write) +DL_SYSCALL(thrkill) diff --git a/libexec/ld.so/mips64/rtld_machine.c b/libexec/ld.so/mips64/rtld_machine.c index f0ff0ebdd2f..722fcec60be 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.23 2017/01/23 10:30:58 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.24 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998-2004 Opsycon AB, Sweden. @@ -141,9 +141,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) break; default: - _dl_printf("%s: unsupported relocation '%d'\n", - __progname, ELF64_R_TYPE(relocs->r_info)); - _dl_exit(1); + _dl_die("unsupported relocation '%d'", + ELF64_R_TYPE(relocs->r_info)); } } DL_DEB(("done %d fails\n", fails)); @@ -284,10 +283,8 @@ _dl_bind(elf_object_t *object, int symidx) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value; diff --git a/libexec/ld.so/mips64/syscall.h b/libexec/ld.so/mips64/syscall.h index f7774657729..898d43a4db7 100644 --- a/libexec/ld.so/mips64/syscall.h +++ b/libexec/ld.so/mips64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.26 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.27 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998-2002 Opsycon AB, Sweden. @@ -57,6 +57,8 @@ int _dl_sysctl(const int *, u_int, void *, size_t *, void *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +__dead +void _dl_thrkill(pid_t, int, void *); 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/archdep.h b/libexec/ld.so/powerpc/archdep.h index 88443873102..a75f5be3e44 100644 --- a/libexec/ld.so/powerpc/archdep.h +++ b/libexec/ld.so/powerpc/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.20 2017/01/20 10:40:30 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.21 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -74,8 +74,6 @@ RELOC_DYN(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v) } else if (ELF32_R_TYPE((r)->r_info) == RELOC_GLOB_DAT) { *p = v + s->st_value + r->r_addend; } else { - /* XXX - printf might not work here, but we give it a shot. */ - _dl_printf("Unknown bootstrap relocation.\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/powerpc/ldasm.S b/libexec/ld.so/powerpc/ldasm.S index 93a03bac12b..91bf9eb02de 100644 --- a/libexec/ld.so/powerpc/ldasm.S +++ b/libexec/ld.so/powerpc/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.30 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.31 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -159,5 +159,6 @@ DL_SYSCALL(read) DL_SYSCALL(readlink) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(sysctl) +DL_SYSCALL(thrkill) DL_SYSCALL(utrace) DL_SYSCALL(write) diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c index 7c4cee2176d..7f9367cae68 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.60 2017/01/23 10:30:58 guenther Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.61 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -111,10 +111,8 @@ _dl_printf("object relocation size %x, numrela %x\n", if (relas == NULL) return(0); - if (relrel > numrela) { - _dl_printf("relcount > numrel: %ld > %d\n", relrel, numrela); - _dl_exit(20); - } + if (relrel > numrela) + _dl_die("relcount > numrel: %ld > %d", relrel, numrela); pltresolve = NULL; pltcall = NULL; @@ -192,18 +190,14 @@ _dl_printf("object relocation size %x, numrela %x\n", #ifdef DEBUG const Elf32_Sym *sym; - if (ELF32_R_TYPE(relas->r_info) != RELOC_RELATIVE) { - _dl_printf("RELCOUNT wrong\n"); - _dl_exit(20); - } + if (ELF32_R_TYPE(relas->r_info) != RELOC_RELATIVE) + _dl_die("RELCOUNT wrong"); sym = object->dyn.symtab; sym += ELF32_R_SYM(relas->r_info); if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL || (ELF32_ST_TYPE(sym->st_info) != STT_SECTION && - ELF32_ST_TYPE(sym->st_info) != STT_NOTYPE)) { - _dl_printf("RELATIVE relocation against symbol\n"); - _dl_exit(20); - } + ELF32_ST_TYPE(sym->st_info) != STT_NOTYPE)) + _dl_die("RELATIVE relocation against symbol"); #endif r_addr = (Elf_Addr *)(relas->r_offset + loff); *r_addr = loff + relas->r_addend; @@ -344,9 +338,11 @@ _dl_printf(" symn [%s] val 0x%x\n", symn, val); { Elf32_Addr val = ooff + prev_value + relas->r_addend - (Elf32_Addr)r_addr; - if (!B24_VALID_RANGE(val)){ + if (!B24_VALID_RANGE(val)) { /* invalid offset */ - _dl_exit(20); + _dl_die("%s: invalid %s offset %x at %p", + object->load_name, "REL24", val, + (char *)r_addr); } val &= ~0xfc000003; val |= (*r_addr & 0xfc000003); @@ -402,7 +398,9 @@ _dl_printf(" symn [%s] val 0x%x\n", symn, val); if (((val & 0xffff8000) != 0) && ((val & 0xffff8000) != 0xffff8000)) { /* invalid offset */ - _dl_exit(20); + _dl_die("%s: invalid %s offset %x at %p", + object->load_name, "REL14", val, + (char *)r_addr); } val &= ~0xffff0003; val |= (*r_addr & 0xffff0003); @@ -458,11 +456,9 @@ _dl_printf(" found other symbol at %x size %d\n", break; default: - _dl_printf("%s:" - " %s: unsupported relocation '%s' %d at %p\n", - __progname, object->load_name, symn, + _dl_die("%s: unsupported relocation '%s' %d at %p\n", + object->load_name, symn, ELF32_R_TYPE(relas->r_info), (char *)r_addr ); - _dl_exit(1); } } @@ -615,10 +611,8 @@ _dl_bind(elf_object_t *object, int reloff) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); value = ooff + this->st_value; diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h index 156d276058b..87175ffaf88 100644 --- a/libexec/ld.so/powerpc/syscall.h +++ b/libexec/ld.so/powerpc/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.43 2016/08/28 06:15:32 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.44 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -58,5 +58,7 @@ int _dl_utrace(const char *, const void *, size_t); ssize_t _dl_write(int, const char *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +__dead +void _dl_thrkill(pid_t, int, void *); #endif /*__DL_SYSCALL_H__*/ diff --git a/libexec/ld.so/reallocarray.c b/libexec/ld.so/reallocarray.c index 09cd7907b2c..867dc0dc349 100644 --- a/libexec/ld.so/reallocarray.c +++ b/libexec/ld.so/reallocarray.c @@ -1,4 +1,4 @@ -/* $OpenBSD: reallocarray.c,v 1.1 2014/06/21 08:00:23 otto Exp $ */ +/* $OpenBSD: reallocarray.c,v 1.2 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> * @@ -31,9 +31,7 @@ void * _dl_reallocarray(void *optr, size_t nmemb, size_t size) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && - nmemb > 0 && SIZE_MAX / nmemb < size) { - _dl_wrstderr("reallocarray overflow\n"); - _dl_exit(7); - } + nmemb > 0 && SIZE_MAX / nmemb < size) + _dl_die("reallocarray overflow"); return _dl_realloc(optr, size * nmemb); } diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c index 07dcd9bfb82..3da418eb721 100644 --- a/libexec/ld.so/resolve.c +++ b/libexec/ld.so/resolve.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolve.c,v 1.80 2017/01/24 02:37:10 guenther Exp $ */ +/* $OpenBSD: resolve.c,v 1.81 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -258,7 +258,7 @@ _dl_finalize_object(const char *objname, Elf_Dyn *dynp, Elf_Phdr *phdrp, #endif object = _dl_calloc(1, sizeof(elf_object_t)); if (object == NULL) - _dl_exit(7); + _dl_oom(); object->prev = object->next = NULL; object->load_dyn = dynp; @@ -361,7 +361,7 @@ _dl_finalize_object(const char *objname, Elf_Dyn *dynp, Elf_Phdr *phdrp, object->obj_base = obase; object->load_name = _dl_strdup(objname); if (object->load_name == NULL) - _dl_exit(7); + _dl_oom(); object->load_object = _dl_loading_object; if (object->load_object == object) DL_DEB(("head %s\n", object->load_name)); diff --git a/libexec/ld.so/sh/archdep.h b/libexec/ld.so/sh/archdep.h index 15c1066ea49..79a7c600895 100644 --- a/libexec/ld.so/sh/archdep.h +++ b/libexec/ld.so/sh/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.9 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.10 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -51,8 +51,6 @@ RELOC_DYN(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v) } else if (ELF_R_TYPE(r->r_info) == R_SH_DIR32) { *p = s->st_value + v + r->r_addend; } else { - /* XXX - printf might not work here, but we give it a shot. */ - _dl_printf("Unknown bootstrap relocation.\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/sh/ldasm.S b/libexec/ld.so/sh/ldasm.S index 74a18eb7ffe..13916795ec9 100644 --- a/libexec/ld.so/sh/ldasm.S +++ b/libexec/ld.so/sh/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.27 2016/08/31 13:18:57 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.28 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2006 Dale Rahn @@ -149,6 +149,7 @@ __CONCAT(_dl_,n): ;\ rts ;\ nop +#define DL_SYSCALL_NOERR(n) DL_SYSCALL2_NOERR(n,n) #define DL_SYSCALL2_NOERR(n,c) \ .global __CONCAT(_dl_,n) ;\ .type __CONCAT(_dl_,n)%function ;\ @@ -171,8 +172,9 @@ _dl_exit: bra 1b nop -DL_SYSCALL(issetugid) -DL_SYSCALL(getthrid) +DL_SYSCALL_NOERR(issetugid) +DL_SYSCALL_NOERR(getthrid) +DL_SYSCALL(thrkill) DL_SYSCALL2(_syscall,__syscall) DL_SYSCALL(munmap) DL_SYSCALL(mprotect) diff --git a/libexec/ld.so/sh/rtld_machine.c b/libexec/ld.so/sh/rtld_machine.c index 9a334f2742b..73e1c318631 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.24 2016/06/21 15:25:38 deraadt Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2004 Dale Rahn @@ -618,10 +618,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) if (rels == NULL) return(0); - if (relrel > numrela) { - _dl_printf("relacount > numrel: %ld > %ld\n", relrel, numrela); - _dl_exit(20); - } + if (relrel > numrela) + _dl_die("relacount > numrel: %ld > %ld", relrel, numrela); /* * unprotect some segments if we need it. @@ -641,10 +639,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) Elf_Addr *where; #ifdef DEBUG - if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELACOUNT wrong\n"); - _dl_exit(20); - } + if (ELF_R_TYPE(rels->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELACOUNT wrong"); #endif where = (Elf_Addr *)(rels->r_offset + loff); *where = rels->r_addend + loff; @@ -657,10 +653,10 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) type = ELF_R_TYPE(rels->r_info); - if (reloc_target_flags[type] & _RF_E) { - _dl_printf(" bad relocation obj %s %d %d\n", object->load_name, i, type); - _dl_exit(1); - } + if (reloc_target_flags[type] & _RF_E) + _dl_die("bad relocation obj %s %ld %d", + object->load_name, i, type); + if (type == R_TYPE(NONE)) continue; @@ -858,10 +854,8 @@ _dl_bind(elf_object_t *object, int reloff) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); buf.newval = ooff + this->st_value; diff --git a/libexec/ld.so/sh/syscall.h b/libexec/ld.so/sh/syscall.h index 72828b99cba..58b5b3d9de1 100644 --- a/libexec/ld.so/sh/syscall.h +++ b/libexec/ld.so/sh/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.23 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.24 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -57,6 +57,8 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +__dead +void _dl_thrkill(pid_t, int, void *); 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/sod.c b/libexec/ld.so/sod.c index 5d1e7d8a22b..df41e143751 100644 --- a/libexec/ld.so/sod.c +++ b/libexec/ld.so/sod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sod.c,v 1.33 2015/10/29 13:07:41 deraadt Exp $ */ +/* $OpenBSD: sod.c,v 1.34 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg @@ -65,7 +65,7 @@ _dl_build_sod(const char *name, struct sod *sodp) /* default is an absolute or relative path */ sodp->sod_name = (long)_dl_strdup(name); /* strtok is destructive */ if (sodp->sod_name == 0) - _dl_exit(7); + _dl_oom(); sodp->sod_library = 0; sodp->sod_major = sodp->sod_minor = 0; @@ -124,7 +124,7 @@ _dl_build_sod(const char *name, struct sod *sodp) cp = (char *)sodp->sod_name; sodp->sod_name = (long)_dl_strdup(realname); if (sodp->sod_name == 0) - _dl_exit(7); + _dl_oom(); _dl_free(cp); sodp->sod_library = 1; sodp->sod_major = major; @@ -135,7 +135,7 @@ backout: _dl_free((char *)sodp->sod_name); sodp->sod_name = (long)_dl_strdup(name); if (sodp->sod_name == 0) - _dl_exit(7); + _dl_oom(); } void @@ -225,16 +225,10 @@ _dl_findhint(char *name, int major, int minor, char *preferred_path) while (1) { /* Sanity check */ - if (bp->hi_namex >= hheader->hh_strtab_sz) { - _dl_printf("Bad name index: %#x\n", bp->hi_namex); - _dl_exit(7); - break; - } - if (bp->hi_pathx >= hheader->hh_strtab_sz) { - _dl_printf("Bad path index: %#x\n", bp->hi_pathx); - _dl_exit(7); - break; - } + if (bp->hi_namex >= hheader->hh_strtab_sz) + _dl_die("bad name index: %#x", bp->hi_namex); + if (bp->hi_pathx >= hheader->hh_strtab_sz) + _dl_die("bad path index: %#x", bp->hi_pathx); if (_dl_strcmp(name, hstrtab + bp->hi_namex) == 0) { /* It's `name', check version numbers */ diff --git a/libexec/ld.so/sparc64/archdep.h b/libexec/ld.so/sparc64/archdep.h index 84217ea7827..15ea156ab65 100644 --- a/libexec/ld.so/sparc64/archdep.h +++ b/libexec/ld.so/sparc64/archdep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: archdep.h,v 1.24 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: archdep.h,v 1.25 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -45,8 +45,6 @@ RELOC_DYN(Elf_RelA *r, const Elf_Sym *s, Elf_Addr *p, unsigned long v) if (ELF_R_TYPE(r->r_info) == RELOC_RELATIVE) { *p = v + r->r_addend; } else { - /* XXX - printf might not work here, but we give it a shot. */ - _dl_printf("Unknown bootstrap relocation.\n"); _dl_exit(6); } } diff --git a/libexec/ld.so/sparc64/ldasm.S b/libexec/ld.so/sparc64/ldasm.S index 31239a93ccd..ab4c77d5669 100644 --- a/libexec/ld.so/sparc64/ldasm.S +++ b/libexec/ld.so/sparc64/ldasm.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ldasm.S,v 1.44 2016/08/28 06:15:33 guenther Exp $ */ +/* $OpenBSD: ldasm.S,v 1.45 2017/01/24 07:48:37 guenther Exp $ */ /* $NetBSD: rtld_start.S,v 1.5 2001/08/14 22:17:48 eeh Exp $ */ /* @@ -341,3 +341,10 @@ _ENTRY(_dl_pledge) t ST_SYSCALL ! off to wonderland retl sub %g0, %o0, %o0 ! error: result = -errno + +_ENTRY(_dl_thrkill) + mov SYS_thrkill | SYSCALL_G2RFLAG, %g1 ! calling sys_thrkill + add %o7, 8, %g2 ! just return on success + t ST_SYSCALL ! off to wonderland + retl + sub %g0, %o0, %o0 ! error: result = -errno diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c index fc1b49c3d3f..dd22ec0fa28 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.58 2016/06/21 15:25:38 deraadt Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.59 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -225,10 +225,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) if (relas == NULL) return(0); - if (relrel > numrela) { - _dl_printf("relacount > numrel: %ld > %ld\n", relrel, numrela); - _dl_exit(20); - } + if (relrel > numrela) + _dl_die("relacount > numrel: %ld > %ld", relrel, numrela); /* * unprotect some segments if we need it. @@ -246,10 +244,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) Elf_Addr *where; #ifdef DEBUG - if (ELF_R_TYPE(relas->r_info) != R_TYPE(RELATIVE)) { - _dl_printf("RELACOUNT wrong\n"); - _dl_exit(20); - } + if (ELF_R_TYPE(relas->r_info) != R_TYPE(RELATIVE)) + _dl_die("RELACOUNT wrong"); #endif where = (Elf_Addr *)(relas->r_offset + loff); *where = relas->r_addend + loff; @@ -639,10 +635,8 @@ _dl_bind(elf_object_t *object, int index) this = NULL; ooff = _dl_find_symbol(symn, &this, SYM_SEARCH_ALL|SYM_WARNNOTFOUND|SYM_PLT, sym, object, &sobj); - if (this == NULL) { - _dl_printf("lazy binding failed!\n"); - *(volatile int *)0 = 0; /* XXX */ - } + if (this == NULL) + _dl_die("lazy binding failed!"); newvalue = ooff + this->st_value; diff --git a/libexec/ld.so/sparc64/syscall.h b/libexec/ld.so/sparc64/syscall.h index f756b6da1d8..1ed7bcd846d 100644 --- a/libexec/ld.so/sparc64/syscall.h +++ b/libexec/ld.so/sparc64/syscall.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.h,v 1.36 2017/01/21 01:15:00 guenther Exp $ */ +/* $OpenBSD: syscall.h,v 1.37 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2001 Niklas Hallqvist @@ -57,6 +57,8 @@ int _dl_getcwd(char *, size_t); int _dl_utrace(const char *, const void *, size_t); int _dl_getentropy(char *, size_t); int _dl_sendsyslog(const char *, size_t, int); +__dead +void _dl_thrkill(pid_t, int, void *); 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/trace.c b/libexec/ld.so/trace.c index 0d6b211b2d0..d3f4276cdb8 100644 --- a/libexec/ld.so/trace.c +++ b/libexec/ld.so/trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trace.c,v 1.3 2015/01/16 16:18:07 deraadt Exp $ */ +/* $OpenBSD: trace.c,v 1.4 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -136,7 +136,7 @@ _dl_trace_parse_spec(const char *var, struct tracespec *spec) if (end != start) { spec->spec = _dl_malloc(1 + end - start); if (spec->spec == NULL) - _dl_exit(8); + _dl_oom(); _dl_bcopy(start, spec->spec, end - start); spec->spec[end - start] = '\0'; diff --git a/libexec/ld.so/util.c b/libexec/ld.so/util.c index 53a5f58eb51..7910b09248f 100644 --- a/libexec/ld.so/util.c +++ b/libexec/ld.so/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.43 2016/08/12 20:39:01 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.44 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -55,7 +55,7 @@ __stack_smash_handler(char func[], int damaged) _dl_strlcat(message, func, sizeof message); _dl_sendsyslog(message, _dl_strlen(message), LOG_CONS); - _dl_exit(127); + _dl_diedie(); } char * @@ -82,7 +82,7 @@ _dl_arc4randombuf(void *v, size_t buflen) while (buflen != 0) { if (reserve == 0) { if (_dl_getentropy(bytes, sizeof(bytes)) != 0) - _dl_exit(8); + _dl_die("no entropy"); reserve = sizeof(bytes); } if (buflen > reserve) diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h index 7fc71dc54c1..9bec531b7a5 100644 --- a/libexec/ld.so/util.h +++ b/libexec/ld.so/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.29 2017/01/23 11:04:19 guenther Exp $ */ +/* $OpenBSD: util.h,v 1.30 2017/01/24 07:48:37 guenther Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -56,6 +56,10 @@ char *_dl_realpath(const char *path, char *resolved); int _dl_uname(struct utsname *name); long _dl_strtol(const char *nptr, char **endptr, int base); + +__dead void _dl_oom(void); +__dead void _dl_die(const char *, ...) __attribute__((format (printf, 1, 2))); +#define _dl_diedie() _dl_thrkill(0, 9, NULL) __END_HIDDEN_DECLS #define _dl_round_page(x) (((x) + (__LDPGSZ - 1)) & ~(__LDPGSZ - 1)) @@ -64,17 +68,6 @@ __END_HIDDEN_DECLS * The following functions are declared inline so they can * be used before bootstrap linking has been finished. */ -static inline void -_dl_wrstderr(const char *s) -{ - const char *p = s; - size_t n = 0; - - while (*p++) - n++; - _dl_write(2, s, n); -} - static inline void * _dl_memset(void *dst, const int c, size_t n) { |