summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbcook <bcook@openbsd.org>2014-07-20 20:51:13 +0000
committerbcook <bcook@openbsd.org>2014-07-20 20:51:13 +0000
commitd976644eacfa6d27cbbf4dafdfa72a873e2f234a (patch)
tree4f7a6bf5f4f3572bc6ac4755329cd876f433f38f
parentFixed typo in error message. (diff)
downloadwireguard-openbsd-d976644eacfa6d27cbbf4dafdfa72a873e2f234a.tar.xz
wireguard-openbsd-d976644eacfa6d27cbbf4dafdfa72a873e2f234a.zip
Move more OS-specific functionality to arc4random.h headers.
Move <sys/mman.h> and raise(SIGKILL) calls to OS-specific headers. On OpenBSD, move thread_private.h as well to arc4random.h. On Windows, use TerminateProcess on getentropy failure. ok deraadt@
-rw-r--r--lib/libc/crypt/arc4random.c7
-rw-r--r--lib/libc/crypt/arc4random.h13
-rw-r--r--lib/libcrypto/arc4random/arc4random_linux.h11
-rw-r--r--lib/libcrypto/arc4random/arc4random_osx.h11
-rw-r--r--lib/libcrypto/arc4random/arc4random_solaris.h11
-rw-r--r--lib/libcrypto/arc4random/arc4random_win.h8
-rw-r--r--lib/libcrypto/crypto/arc4random_linux.h11
-rw-r--r--lib/libcrypto/crypto/arc4random_osx.h11
-rw-r--r--lib/libcrypto/crypto/arc4random_solaris.h11
-rw-r--r--lib/libcrypto/crypto/arc4random_win.h8
10 files changed, 88 insertions, 14 deletions
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c
index 3c80beb3b96..e4b6369bf1e 100644
--- a/lib/libc/crypt/arc4random.c
+++ b/lib/libc/crypt/arc4random.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random.c,v 1.48 2014/07/19 00:08:41 deraadt Exp $ */
+/* $OpenBSD: arc4random.c,v 1.49 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -32,9 +32,6 @@
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
-#include <sys/mman.h>
-
-#include "thread_private.h"
#define KEYSTREAM_ONLY
#include "chacha_private.h"
@@ -90,7 +87,7 @@ _rs_stir(void)
u_char rnd[KEYSZ + IVSZ];
if (getentropy(rnd, sizeof rnd) == -1)
- raise(SIGKILL);
+ _getentropy_fail();
if (!rs)
_rs_init(rnd, sizeof(rnd));
diff --git a/lib/libc/crypt/arc4random.h b/lib/libc/crypt/arc4random.h
index d867687226f..d29873cca4c 100644
--- a/lib/libc/crypt/arc4random.h
+++ b/lib/libc/crypt/arc4random.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random.h,v 1.2 2014/07/19 00:08:41 deraadt Exp $ */
+/* $OpenBSD: arc4random.h,v 1.3 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -21,6 +21,17 @@
/*
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
+#include <signal.h>
+
+#include "thread_private.h"
+
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
diff --git a/lib/libcrypto/arc4random/arc4random_linux.h b/lib/libcrypto/arc4random/arc4random_linux.h
index 0da5a4a433d..7acba3f78e5 100644
--- a/lib/libcrypto/arc4random/arc4random_linux.h
+++ b/lib/libcrypto/arc4random/arc4random_linux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_linux.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -36,6 +39,12 @@ extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
#endif
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
diff --git a/lib/libcrypto/arc4random/arc4random_osx.h b/lib/libcrypto/arc4random/arc4random_osx.h
index aacbef9aaec..c14e044fe26 100644
--- a/lib/libcrypto/arc4random/arc4random_osx.h
+++ b/lib/libcrypto/arc4random/arc4random_osx.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_osx.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_osx.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
diff --git a/lib/libcrypto/arc4random/arc4random_solaris.h b/lib/libcrypto/arc4random/arc4random_solaris.h
index 18b1bd54e05..2082a4728f5 100644
--- a/lib/libcrypto/arc4random/arc4random_solaris.h
+++ b/lib/libcrypto/arc4random/arc4random_solaris.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_solaris.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_solaris.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
diff --git a/lib/libcrypto/arc4random/arc4random_win.h b/lib/libcrypto/arc4random/arc4random_win.h
index 1e044de1097..b7a5a360133 100644
--- a/lib/libcrypto/arc4random/arc4random_win.h
+++ b/lib/libcrypto/arc4random/arc4random_win.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 bcook Exp $ */
+/* $OpenBSD: arc4random_win.h,v 1.4 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -42,6 +42,12 @@ static volatile HANDLE arc4random_mtx = NULL;
#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
+static inline void
+_getentropy_fail(void)
+{
+ TerminateProcess(GetCurrentProcess(), 0);
+}
+
static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
{
diff --git a/lib/libcrypto/crypto/arc4random_linux.h b/lib/libcrypto/crypto/arc4random_linux.h
index 0da5a4a433d..7acba3f78e5 100644
--- a/lib/libcrypto/crypto/arc4random_linux.h
+++ b/lib/libcrypto/crypto/arc4random_linux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_linux.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_linux.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -36,6 +39,12 @@ extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
#endif
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
diff --git a/lib/libcrypto/crypto/arc4random_osx.h b/lib/libcrypto/crypto/arc4random_osx.h
index aacbef9aaec..c14e044fe26 100644
--- a/lib/libcrypto/crypto/arc4random_osx.h
+++ b/lib/libcrypto/crypto/arc4random_osx.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_osx.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_osx.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
diff --git a/lib/libcrypto/crypto/arc4random_solaris.h b/lib/libcrypto/crypto/arc4random_solaris.h
index 18b1bd54e05..2082a4728f5 100644
--- a/lib/libcrypto/crypto/arc4random_solaris.h
+++ b/lib/libcrypto/crypto/arc4random_solaris.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_solaris.h,v 1.6 2014/07/19 15:29:25 bcook Exp $ */
+/* $OpenBSD: arc4random_solaris.h,v 1.7 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -22,7 +22,10 @@
* Stub functions for portability.
*/
+#include <sys/mman.h>
+
#include <pthread.h>
+#include <signal.h>
static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
@@ -30,6 +33,12 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
static volatile sig_atomic_t _rs_forked;
static inline void
diff --git a/lib/libcrypto/crypto/arc4random_win.h b/lib/libcrypto/crypto/arc4random_win.h
index 1e044de1097..b7a5a360133 100644
--- a/lib/libcrypto/crypto/arc4random_win.h
+++ b/lib/libcrypto/crypto/arc4random_win.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4random_win.h,v 1.3 2014/07/20 16:59:31 bcook Exp $ */
+/* $OpenBSD: arc4random_win.h,v 1.4 2014/07/20 20:51:13 bcook Exp $ */
/*
* Copyright (c) 1996, David Mazieres <dm@uun.org>
@@ -42,6 +42,12 @@ static volatile HANDLE arc4random_mtx = NULL;
#define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx)
+static inline void
+_getentropy_fail(void)
+{
+ TerminateProcess(GetCurrentProcess(), 0);
+}
+
static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
{