From: deraadt Date: Fri, 12 Aug 2016 20:39:01 +0000 (+0000) Subject: the slimmed down random functions inside ld.so are strict clones of the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=acb148b129063116239fc8bb9358da184f245f5a;p=openbsd the slimmed down random functions inside ld.so are strict clones of the libc arc4random API, so call them _dl_{arc4random,arcrandombuf} ok tedu guenther --- diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c index 7adf2bc81cf..ac63b964dd6 100644 --- a/libexec/ld.so/library.c +++ b/libexec/ld.so/library.c @@ -1,4 +1,4 @@ -/* $OpenBSD: library.c,v 1.78 2016/08/08 21:59:20 guenther Exp $ */ +/* $OpenBSD: library.c,v 1.79 2016/08/12 20:39:01 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -278,7 +278,7 @@ _dl_tryload_shlib(const char *libname, int type, int flags) } case PT_OPENBSD_RANDOMIZE: - _dl_randombuf((char *)(phdp->p_vaddr + loff), + _dl_arc4randombuf((char *)(phdp->p_vaddr + loff), phdp->p_memsz); break; diff --git a/libexec/ld.so/library_mquery.c b/libexec/ld.so/library_mquery.c index 2192d6f691d..becf2735e16 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.55 2016/08/08 21:59:20 guenther Exp $ */ +/* $OpenBSD: library_mquery.c,v 1.56 2016/08/12 20:39:01 deraadt Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -300,7 +300,7 @@ retry: phdp = (Elf_Phdr *)(hbuf + ehdr->e_phoff); for (i = 0; i < ehdr->e_phnum; i++, phdp++) { if (phdp->p_type == PT_OPENBSD_RANDOMIZE) - _dl_randombuf((char *)(phdp->p_vaddr + LOFF), + _dl_arc4randombuf((char *)(phdp->p_vaddr + LOFF), phdp->p_memsz); else if (phdp->p_type == PT_GNU_RELRO) { relro_addr = phdp->p_vaddr + LOFF; diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c index bd7c82e95ab..06dc2cbab91 100644 --- a/libexec/ld.so/loader.c +++ b/libexec/ld.so/loader.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loader.c,v 1.163 2016/08/08 21:59:20 guenther Exp $ */ +/* $OpenBSD: loader.c,v 1.164 2016/08/12 20:39:01 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -308,7 +308,7 @@ _dl_load_dep_libs(elf_object_t *object, int flags, int booting) for (loop = 1; loop < libcount; loop++) { unsigned int rnd; int cur; - rnd = _dl_random(); + rnd = _dl_arc4random(); rnd = rnd % (loop+1); cur = randomlist[rnd]; randomlist[rnd] = randomlist[loop]; diff --git a/libexec/ld.so/malloc.c b/libexec/ld.so/malloc.c index b1e89f2d623..a234065ee71 100644 --- a/libexec/ld.so/malloc.c +++ b/libexec/ld.so/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.8 2016/05/19 18:50:01 guenther Exp $ */ +/* $OpenBSD: malloc.c,v 1.9 2016/08/12 20:39:01 deraadt Exp $ */ /* * Copyright (c) 2008, 2010, 2011 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky @@ -196,7 +196,7 @@ wrterror(char *msg) static void rbytes_init(struct dir_info *d) { - _dl_randombuf(d->rbytes, sizeof(d->rbytes)); + _dl_arc4randombuf(d->rbytes, sizeof(d->rbytes)); d->rbytesused = 0; } @@ -358,7 +358,7 @@ omalloc_init(struct dir_info **dp) mopts.malloc_guard = MALLOC_PAGESIZE; do { - _dl_randombuf(&mopts.malloc_canary, + _dl_arc4randombuf(&mopts.malloc_canary, sizeof(mopts.malloc_canary)); } while (mopts.malloc_canary == 0); @@ -376,7 +376,7 @@ omalloc_init(struct dir_info **dp) MALLOC_PAGESIZE, PROT_NONE); d_avail = (DIR_INFO_RSZ - sizeof(*d)) >> MALLOC_MINSHIFT; - _dl_randombuf(&tmp, sizeof(tmp)); + _dl_arc4randombuf(&tmp, sizeof(tmp)); d = (struct dir_info *)(p + MALLOC_PAGESIZE + ((tmp % d_avail) << MALLOC_MINSHIFT)); /* not uniform */ diff --git a/libexec/ld.so/util.c b/libexec/ld.so/util.c index c81cb5350e2..53a5f58eb51 100644 --- a/libexec/ld.so/util.c +++ b/libexec/ld.so/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.42 2016/08/05 15:42:05 tedu Exp $ */ +/* $OpenBSD: util.c,v 1.43 2016/08/12 20:39:01 deraadt Exp $ */ /* * Copyright (c) 1998 Per Fogelstrom, Opsycon AB @@ -72,7 +72,7 @@ _dl_strdup(const char *orig) } void -_dl_randombuf(void *v, size_t buflen) +_dl_arc4randombuf(void *v, size_t buflen) { static char bytes[256]; static u_int reserve; @@ -110,9 +110,9 @@ _dl_randombuf(void *v, size_t buflen) } u_int32_t -_dl_random(void) +_dl_arc4random(void) { u_int32_t rnd; - _dl_randombuf(&rnd, sizeof(rnd)); + _dl_arc4randombuf(&rnd, sizeof(rnd)); return (rnd); } diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h index 584617a793c..323a2246f42 100644 --- a/libexec/ld.so/util.h +++ b/libexec/ld.so/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.26 2014/06/21 08:00:23 otto Exp $ */ +/* $OpenBSD: util.h,v 1.27 2016/08/12 20:39:01 deraadt Exp $ */ /* * Copyright (c) 1998 Todd C. Miller @@ -46,8 +46,8 @@ void _dl_printf(const char *fmt, ...); void _dl_vprintf(const char *fmt, va_list ap); void _dl_fdprintf(int, const char *fmt, ...); void _dl_show_objects(void); -void _dl_randombuf(void *, size_t); -u_int32_t _dl_random(void); +void _dl_arc4randombuf(void *, size_t); +u_int32_t _dl_arc4random(void); ssize_t _dl_write(int fd, const char* buf, size_t len); char * _dl_dirname(const char *path); char *_dl_realpath(const char *path, char *resolved);