diff options
| author | deraadt <> | 2014-07-19 00:08:43 +0000 |
|---|---|---|
| committer | deraadt <> | 2014-07-19 00:08:43 +0000 |
| commit | 7dda705eb34d88c4c8c8ece0a009c6cac7b14c67 (patch) | |
| tree | d1d1ea706aec9066edcbf60e8dd1c10257101a1d | |
| parent | cb6d7664a81745720f33266734161b267e83c5dd (diff) | |
| download | openbsd-7dda705eb34d88c4c8c8ece0a009c6cac7b14c67.tar.gz openbsd-7dda705eb34d88c4c8c8ece0a009c6cac7b14c67.tar.bz2 openbsd-7dda705eb34d88c4c8c8ece0a009c6cac7b14c67.zip | |
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
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/crypt/arc4random.c | 22 | ||||
| -rw-r--r-- | src/lib/libc/crypt/arc4random.h | 31 | ||||
| -rw-r--r-- | src/lib/libcrypto/arc4random/arc4random_linux.h | 29 | ||||
| -rw-r--r-- | src/lib/libcrypto/arc4random/arc4random_osx.h | 29 | ||||
| -rw-r--r-- | src/lib/libcrypto/arc4random/arc4random_solaris.h | 29 | ||||
| -rw-r--r-- | src/lib/libcrypto/arc4random/arc4random_win.h | 23 | ||||
| -rw-r--r-- | src/lib/libcrypto/crypto/arc4random_linux.h | 29 | ||||
| -rw-r--r-- | src/lib/libcrypto/crypto/arc4random_osx.h | 29 | ||||
| -rw-r--r-- | src/lib/libcrypto/crypto/arc4random_solaris.h | 29 | ||||
| -rw-r--r-- | src/lib/libcrypto/crypto/arc4random_win.h | 23 |
10 files changed, 135 insertions, 138 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c index d42022c455..3c80beb3b9 100644 --- a/src/lib/libc/crypt/arc4random.c +++ b/src/lib/libc/crypt/arc4random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random.c,v 1.47 2014/07/18 02:05:55 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random.c,v 1.48 2014/07/19 00:08:41 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -57,17 +57,16 @@ static struct _rs { | |||
| 57 | size_t rs_count; /* bytes till reseed */ | 57 | size_t rs_count; /* bytes till reseed */ |
| 58 | } *rs; | 58 | } *rs; |
| 59 | 59 | ||
| 60 | static inline void *_rs_allocate(size_t len); | 60 | /* Maybe be preserved in fork children, if _rs_allocate() decides. */ |
| 61 | static inline void _rs_forkdetect(void); | 61 | static struct _rsx { |
| 62 | static inline void _rs_forkdetectsetup(struct _rs *buf, size_t len); | ||
| 63 | #include "arc4random.h" | ||
| 64 | |||
| 65 | /* Preserved in fork children. */ | ||
| 66 | static struct { | ||
| 67 | chacha_ctx rs_chacha; /* chacha context for random keystream */ | 62 | chacha_ctx rs_chacha; /* chacha context for random keystream */ |
| 68 | u_char rs_buf[RSBUFSZ]; /* keystream blocks */ | 63 | u_char rs_buf[RSBUFSZ]; /* keystream blocks */ |
| 69 | } *rsx; | 64 | } *rsx; |
| 70 | 65 | ||
| 66 | static inline int _rs_allocate(struct _rs **, struct _rsx **); | ||
| 67 | static inline void _rs_forkdetect(void); | ||
| 68 | #include "arc4random.h" | ||
| 69 | |||
| 71 | static inline void _rs_rekey(u_char *dat, size_t datlen); | 70 | static inline void _rs_rekey(u_char *dat, size_t datlen); |
| 72 | 71 | ||
| 73 | static inline void | 72 | static inline void |
| @@ -77,12 +76,7 @@ _rs_init(u_char *buf, size_t n) | |||
| 77 | return; | 76 | return; |
| 78 | 77 | ||
| 79 | if (rs == NULL) { | 78 | if (rs == NULL) { |
| 80 | if ((rs = _rs_allocate(sizeof(*rs))) == NULL) | 79 | if (_rs_allocate(&rs, &rsx) == -1) |
| 81 | abort(); | ||
| 82 | _rs_forkdetectsetup(rs, sizeof(*rs)); | ||
| 83 | } | ||
| 84 | if (rsx == NULL) { | ||
| 85 | if ((rsx = _rs_allocate(sizeof(*rsx))) == NULL) | ||
| 86 | abort(); | 80 | abort(); |
| 87 | } | 81 | } |
| 88 | 82 | ||
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 @@ | |||
| 1 | /* $OpenBSD: arc4random.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random.h,v 1.2 2014/07/19 00:08:41 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,25 +22,28 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | struct { |
| 29 | struct _rs rs; | ||
| 30 | struct _rsx rsx; | ||
| 31 | } *p; | ||
| 29 | 32 | ||
| 30 | if ((p = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, | 33 | if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE, |
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 34 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 35 | return (-1); |
| 33 | return (p); | 36 | if (minherit(p, sizeof(*p), MAP_INHERIT_ZERO) == -1) { |
| 34 | } | 37 | munmap(p, sizeof(*p)); |
| 38 | return (-1); | ||
| 39 | } | ||
| 35 | 40 | ||
| 36 | static inline void | 41 | *rsp = &p->rs; |
| 37 | _rs_forkdetect(void) | 42 | *rsxp = &p->rsx; |
| 38 | { | 43 | return (0); |
| 39 | } | 44 | } |
| 40 | 45 | ||
| 41 | static inline void | 46 | static inline void |
| 42 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | 47 | _rs_forkdetect(void) |
| 43 | { | 48 | { |
| 44 | if (minherit(rs, len, MAP_INHERIT_ZERO) == -1) | ||
| 45 | abort(); | ||
| 46 | } | 49 | } |
diff --git a/src/lib/libcrypto/arc4random/arc4random_linux.h b/src/lib/libcrypto/arc4random/arc4random_linux.h index f02ae388d5..a713d15e06 100644 --- a/src/lib/libcrypto/arc4random/arc4random_linux.h +++ b/src/lib/libcrypto/arc4random/arc4random_linux.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_linux.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ | 1 | /* $OpenBSD: arc4random_linux.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,15 +22,21 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, |
| 29 | |||
| 30 | if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, | ||
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 29 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 30 | return (-1); |
| 33 | return (p); | 31 | |
| 32 | if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, | ||
| 33 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { | ||
| 34 | munmap(*rsxp, sizeof(**rsxp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | |||
| 38 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 39 | return (0); | ||
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static volatile sig_atomic_t _rs_forked; | 42 | static volatile sig_atomic_t _rs_forked; |
| @@ -54,10 +60,3 @@ _rs_forkdetect(void) | |||
| 54 | memset(rs, 0, sizeof(*rs)); | 60 | memset(rs, 0, sizeof(*rs)); |
| 55 | } | 61 | } |
| 56 | } | 62 | } |
| 57 | |||
| 58 | static inline void | ||
| 59 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 60 | { | ||
| 61 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/lib/libcrypto/arc4random/arc4random_osx.h b/src/lib/libcrypto/arc4random/arc4random_osx.h index 46053a45b9..ea4bd70fcd 100644 --- a/src/lib/libcrypto/arc4random/arc4random_osx.h +++ b/src/lib/libcrypto/arc4random/arc4random_osx.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_osx.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ | 1 | /* $OpenBSD: arc4random_osx.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,15 +22,21 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, |
| 29 | |||
| 30 | if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, | ||
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 29 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 30 | return (-1); |
| 33 | return (p); | 31 | |
| 32 | if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, | ||
| 33 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { | ||
| 34 | munmap(*rsxp, sizeof(**rsxp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | |||
| 38 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 39 | return (0); | ||
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static volatile sig_atomic_t _rs_forked; | 42 | static volatile sig_atomic_t _rs_forked; |
| @@ -54,10 +60,3 @@ _rs_forkdetect(void) | |||
| 54 | memset(rs, 0, sizeof(*rs)); | 60 | memset(rs, 0, sizeof(*rs)); |
| 55 | } | 61 | } |
| 56 | } | 62 | } |
| 57 | |||
| 58 | static inline void | ||
| 59 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 60 | { | ||
| 61 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/lib/libcrypto/arc4random/arc4random_solaris.h b/src/lib/libcrypto/arc4random/arc4random_solaris.h index 2386dbe885..ec9353f1b7 100644 --- a/src/lib/libcrypto/arc4random/arc4random_solaris.h +++ b/src/lib/libcrypto/arc4random/arc4random_solaris.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_solaris.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ | 1 | /* $OpenBSD: arc4random_solaris.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,15 +22,21 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, |
| 29 | |||
| 30 | if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, | ||
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 29 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 30 | return (-1); |
| 33 | return (p); | 31 | |
| 32 | if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, | ||
| 33 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { | ||
| 34 | munmap(*rsxp, sizeof(**rsxp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | |||
| 38 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 39 | return (0); | ||
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static volatile sig_atomic_t _rs_forked; | 42 | static volatile sig_atomic_t _rs_forked; |
| @@ -54,10 +60,3 @@ _rs_forkdetect(void) | |||
| 54 | memset(rs, 0, sizeof(*rs)); | 60 | memset(rs, 0, sizeof(*rs)); |
| 55 | } | 61 | } |
| 56 | } | 62 | } |
| 57 | |||
| 58 | static inline void | ||
| 59 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 60 | { | ||
| 61 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/lib/libcrypto/arc4random/arc4random_win.h b/src/lib/libcrypto/arc4random/arc4random_win.h index 7d01d42be5..1fc228d109 100644 --- a/src/lib/libcrypto/arc4random/arc4random_win.h +++ b/src/lib/libcrypto/arc4random/arc4random_win.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_win.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random_win.h,v 1.2 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,10 +22,19 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | return calloc(1, sizeof(*rs)); | 28 | *rsp = calloc(1, sizeof(**rsp)); |
| 29 | if (*rsp == NULL) | ||
| 30 | return (-1); | ||
| 31 | |||
| 32 | *rsxp = calloc(1, sizeof(**rsxp)); | ||
| 33 | if (*rsxp == NULL) { | ||
| 34 | free(*rsp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | return (0); | ||
| 29 | } | 38 | } |
| 30 | 39 | ||
| 31 | static inline void | 40 | static inline void |
| @@ -37,9 +46,3 @@ static inline void | |||
| 37 | _rs_forkdetect(void) | 46 | _rs_forkdetect(void) |
| 38 | { | 47 | { |
| 39 | } | 48 | } |
| 40 | |||
| 41 | static inline void | ||
| 42 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 43 | { | ||
| 44 | } | ||
| 45 | |||
diff --git a/src/lib/libcrypto/crypto/arc4random_linux.h b/src/lib/libcrypto/crypto/arc4random_linux.h index f02ae388d5..a713d15e06 100644 --- a/src/lib/libcrypto/crypto/arc4random_linux.h +++ b/src/lib/libcrypto/crypto/arc4random_linux.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_linux.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ | 1 | /* $OpenBSD: arc4random_linux.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,15 +22,21 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, |
| 29 | |||
| 30 | if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, | ||
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 29 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 30 | return (-1); |
| 33 | return (p); | 31 | |
| 32 | if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, | ||
| 33 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { | ||
| 34 | munmap(*rsxp, sizeof(**rsxp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | |||
| 38 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 39 | return (0); | ||
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static volatile sig_atomic_t _rs_forked; | 42 | static volatile sig_atomic_t _rs_forked; |
| @@ -54,10 +60,3 @@ _rs_forkdetect(void) | |||
| 54 | memset(rs, 0, sizeof(*rs)); | 60 | memset(rs, 0, sizeof(*rs)); |
| 55 | } | 61 | } |
| 56 | } | 62 | } |
| 57 | |||
| 58 | static inline void | ||
| 59 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 60 | { | ||
| 61 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/lib/libcrypto/crypto/arc4random_osx.h b/src/lib/libcrypto/crypto/arc4random_osx.h index 46053a45b9..ea4bd70fcd 100644 --- a/src/lib/libcrypto/crypto/arc4random_osx.h +++ b/src/lib/libcrypto/crypto/arc4random_osx.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_osx.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ | 1 | /* $OpenBSD: arc4random_osx.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,15 +22,21 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, |
| 29 | |||
| 30 | if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, | ||
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 29 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 30 | return (-1); |
| 33 | return (p); | 31 | |
| 32 | if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, | ||
| 33 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { | ||
| 34 | munmap(*rsxp, sizeof(**rsxp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | |||
| 38 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 39 | return (0); | ||
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static volatile sig_atomic_t _rs_forked; | 42 | static volatile sig_atomic_t _rs_forked; |
| @@ -54,10 +60,3 @@ _rs_forkdetect(void) | |||
| 54 | memset(rs, 0, sizeof(*rs)); | 60 | memset(rs, 0, sizeof(*rs)); |
| 55 | } | 61 | } |
| 56 | } | 62 | } |
| 57 | |||
| 58 | static inline void | ||
| 59 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 60 | { | ||
| 61 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/lib/libcrypto/crypto/arc4random_solaris.h b/src/lib/libcrypto/crypto/arc4random_solaris.h index 2386dbe885..ec9353f1b7 100644 --- a/src/lib/libcrypto/crypto/arc4random_solaris.h +++ b/src/lib/libcrypto/crypto/arc4random_solaris.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_solaris.h,v 1.2 2014/07/18 21:40:54 matthew Exp $ */ | 1 | /* $OpenBSD: arc4random_solaris.h,v 1.3 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,15 +22,21 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | void *p; | 28 | if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, |
| 29 | |||
| 30 | if ((p = mmap(NULL, len, PROT_READ|PROT_WRITE, | ||
| 31 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 29 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 32 | return (NULL); | 30 | return (-1); |
| 33 | return (p); | 31 | |
| 32 | if ((*rsxp = mmap(NULL, sizeof(**rsxp) PROT_READ|PROT_WRITE, | ||
| 33 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { | ||
| 34 | munmap(*rsxp, sizeof(**rsxp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | |||
| 38 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 39 | return (0); | ||
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | static volatile sig_atomic_t _rs_forked; | 42 | static volatile sig_atomic_t _rs_forked; |
| @@ -54,10 +60,3 @@ _rs_forkdetect(void) | |||
| 54 | memset(rs, 0, sizeof(*rs)); | 60 | memset(rs, 0, sizeof(*rs)); |
| 55 | } | 61 | } |
| 56 | } | 62 | } |
| 57 | |||
| 58 | static inline void | ||
| 59 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 60 | { | ||
| 61 | _ARC4_ATFORK(_rs_forkhandler); | ||
| 62 | } | ||
| 63 | |||
diff --git a/src/lib/libcrypto/crypto/arc4random_win.h b/src/lib/libcrypto/crypto/arc4random_win.h index 7d01d42be5..1fc228d109 100644 --- a/src/lib/libcrypto/crypto/arc4random_win.h +++ b/src/lib/libcrypto/crypto/arc4random_win.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random_win.h,v 1.1 2014/07/18 02:05:55 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random_win.h,v 1.2 2014/07/19 00:08:43 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -22,10 +22,19 @@ | |||
| 22 | * Stub functions for portability. | 22 | * Stub functions for portability. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | static inline void * | 25 | static inline int |
| 26 | _rs_allocate(size_t len) | 26 | _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) |
| 27 | { | 27 | { |
| 28 | return calloc(1, sizeof(*rs)); | 28 | *rsp = calloc(1, sizeof(**rsp)); |
| 29 | if (*rsp == NULL) | ||
| 30 | return (-1); | ||
| 31 | |||
| 32 | *rsxp = calloc(1, sizeof(**rsxp)); | ||
| 33 | if (*rsxp == NULL) { | ||
| 34 | free(*rsp); | ||
| 35 | return (-1); | ||
| 36 | } | ||
| 37 | return (0); | ||
| 29 | } | 38 | } |
| 30 | 39 | ||
| 31 | static inline void | 40 | static inline void |
| @@ -37,9 +46,3 @@ static inline void | |||
| 37 | _rs_forkdetect(void) | 46 | _rs_forkdetect(void) |
| 38 | { | 47 | { |
| 39 | } | 48 | } |
| 40 | |||
| 41 | static inline void | ||
| 42 | _rs_forkdetectsetup(struct _rs *rs, size_t len) | ||
| 43 | { | ||
| 44 | } | ||
| 45 | |||
