From 63559a378edd18f00978f68eeb77fbd0f088a804 Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Sat, 19 Jul 2014 00:08:43 +0000 Subject: Change _rs_allocate so it can combine the two regions (rs and rsx) into one if a system has an awesome getentropy(). In that case it is valid to totally throw away the rsx state in the child. If the getentropy() is not very good and has a lazy reseed operation, this combining is a bad idea, and the reseed should probably continue to use the "something old, something new" mix. _rs_allocate() can accomodate either method, but not on the fly. ok matthew --- src/lib/libc/crypt/arc4random.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/lib/libc/crypt/arc4random.h') diff --git a/src/lib/libc/crypt/arc4random.h b/src/lib/libc/crypt/arc4random.h index e0309a3184..d867687226 100644 --- a/src/lib/libc/crypt/arc4random.h +++ b/src/lib/libc/crypt/arc4random.h @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */ +/* $OpenBSD: arc4random.h,v 1.2 2014/07/19 00:08:41 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres @@ -22,25 +22,28 @@ * Stub functions for portability. */ -static inline void * -_rs_allocate(size_t len) +static inline int +_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { - void *p; + struct { + struct _rs rs; + struct _rsx rsx; + } *p; - if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, + if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) - return (NULL); - return (p); -} + return (-1); + if (minherit(p, sizeof(*p), MAP_INHERIT_ZERO) == -1) { + munmap(p, sizeof(*p)); + return (-1); + } -static inline void -_rs_forkdetect(void) -{ + *rsp = &p->rs; + *rsxp = &p->rsx; + return (0); } static inline void -_rs_forkdetectsetup(struct _rs *rs, size_t len) +_rs_forkdetect(void) { - if (minherit(rs, len, MAP_INHERIT_ZERO) == -1) - abort(); } -- cgit v1.2.3-55-g6feb