diff options
author | Brent Cook <bcook@openbsd.org> | 2014-10-27 19:22:03 -0500 |
---|---|---|
committer | Brent Cook <bcook@openbsd.org> | 2014-11-03 01:19:36 -0600 |
commit | 0aeb93b9fc9ecf0f9c2e98444545de485168823d (patch) | |
tree | 605cc1566e5c0ad6698c076b9d5dc2ebeb3f705d | |
parent | 8abf8e1e1577f51deb5c3bc01f076205f1bfb268 (diff) | |
download | portable-0aeb93b9fc9ecf0f9c2e98444545de485168823d.tar.gz portable-0aeb93b9fc9ecf0f9c2e98444545de485168823d.tar.bz2 portable-0aeb93b9fc9ecf0f9c2e98444545de485168823d.zip |
override native arc4random_buf on FreeBSD
The FreeBSD-native arc4random_buf implementation falls back to weak
sources of entropy if the sysctl fails. Remove these dangerous fallbacks
by overriding locally.
Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10)
if a program does not link to -lthr. Callbacks registered with
pthread_atfork() simply fail silently. So, it is not always possible to
detect a PID wraparound. I wish we could do better.
This improves arc4random_buf's safety compared to the native FreeBSD
implementation. Tested on FreeBSD 9 and 10.
ok beck@ deraadt@
-rw-r--r-- | apps/Makefile.am.tpl | 2 | ||||
-rw-r--r-- | configure.ac | 7 | ||||
-rw-r--r-- | crypto/Makefile.am.tpl | 4 | ||||
-rw-r--r-- | crypto/compat/arc4random.h | 7 | ||||
-rw-r--r-- | tests/Makefile.am.tpl | 3 |
5 files changed, 19 insertions, 4 deletions
diff --git a/apps/Makefile.am.tpl b/apps/Makefile.am.tpl index 433fca2..5f1dd21 100644 --- a/apps/Makefile.am.tpl +++ b/apps/Makefile.am.tpl | |||
@@ -3,7 +3,7 @@ include $(top_srcdir)/Makefile.am.common | |||
3 | bin_PROGRAMS = openssl | 3 | bin_PROGRAMS = openssl |
4 | 4 | ||
5 | openssl_CFLAGS = $(USER_CFLAGS) | 5 | openssl_CFLAGS = $(USER_CFLAGS) |
6 | openssl_LDADD = $(PLATFORM_LDADD) | 6 | openssl_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) |
7 | openssl_LDADD += $(top_builddir)/ssl/libssl.la | 7 | openssl_LDADD += $(top_builddir)/ssl/libssl.la |
8 | openssl_LDADD += $(top_builddir)/crypto/libcrypto.la | 8 | openssl_LDADD += $(top_builddir)/crypto/libcrypto.la |
9 | 9 | ||
diff --git a/configure.ac b/configure.ac index 0f75e81..88613d6 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -13,6 +13,10 @@ case $host_os in | |||
13 | HOST_OS=darwin; | 13 | HOST_OS=darwin; |
14 | LDFLAGS="$LDFLAGS -Qunused-arguments" | 14 | LDFLAGS="$LDFLAGS -Qunused-arguments" |
15 | ;; | 15 | ;; |
16 | *freebsd*) | ||
17 | HOST_OS=freebsd; | ||
18 | AC_SUBST([PROG_LDADD], ['-lthr']) | ||
19 | ;; | ||
16 | *linux*) | 20 | *linux*) |
17 | HOST_OS=linux; | 21 | HOST_OS=linux; |
18 | CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE" | 22 | CFLAGS="$CFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE" |
@@ -33,6 +37,7 @@ case $host_os in | |||
33 | esac | 37 | esac |
34 | 38 | ||
35 | AM_CONDITIONAL(HOST_DARWIN, test x$HOST_OS = xdarwin) | 39 | AM_CONDITIONAL(HOST_DARWIN, test x$HOST_OS = xdarwin) |
40 | AM_CONDITIONAL(HOST_FREEBSD, test x$HOST_OS = xfreebsd) | ||
36 | AM_CONDITIONAL(HOST_LINUX, test x$HOST_OS = xlinux) | 41 | AM_CONDITIONAL(HOST_LINUX, test x$HOST_OS = xlinux) |
37 | AM_CONDITIONAL(HOST_SOLARIS, test x$HOST_OS = xsolaris) | 42 | AM_CONDITIONAL(HOST_SOLARIS, test x$HOST_OS = xsolaris) |
38 | AM_CONDITIONAL(HOST_WIN, test x$HOST_OS = xwin) | 43 | AM_CONDITIONAL(HOST_WIN, test x$HOST_OS = xwin) |
@@ -81,7 +86,7 @@ AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" | |||
81 | 86 | ||
82 | # overrides for arc4random_buf implementations with known issues | 87 | # overrides for arc4random_buf implementations with known issues |
83 | AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], | 88 | AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], |
84 | [test "x$HOST_OS" != xdarwin -a "x$NO_ARC4RANDOM_BUF" = xtrue]) | 89 | [test "x$HOST_OS" != xdarwin -a "x$HOST_OS" != xfreebsd -a "x$ac_cv_func_arc4random_buf" = xyes]) |
85 | 90 | ||
86 | AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ | 91 | AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ |
87 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | 92 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
diff --git a/crypto/Makefile.am.tpl b/crypto/Makefile.am.tpl index 0ace78a..d9ca553 100644 --- a/crypto/Makefile.am.tpl +++ b/crypto/Makefile.am.tpl | |||
@@ -61,6 +61,9 @@ if !HAVE_ARC4RANDOM_BUF | |||
61 | libcompat_la_SOURCES += compat/arc4random.c | 61 | libcompat_la_SOURCES += compat/arc4random.c |
62 | 62 | ||
63 | if !HAVE_GETENTROPY | 63 | if !HAVE_GETENTROPY |
64 | if HOST_FREEBSD | ||
65 | libcompat_la_SOURCES += compat/getentropy_freebsd.c | ||
66 | endif | ||
64 | if HOST_LINUX | 67 | if HOST_LINUX |
65 | libcompat_la_SOURCES += compat/getentropy_linux.c | 68 | libcompat_la_SOURCES += compat/getentropy_linux.c |
66 | endif | 69 | endif |
@@ -88,6 +91,7 @@ endif | |||
88 | 91 | ||
89 | noinst_HEADERS = des/ncbc_enc.c | 92 | noinst_HEADERS = des/ncbc_enc.c |
90 | noinst_HEADERS += compat/arc4random.h | 93 | noinst_HEADERS += compat/arc4random.h |
94 | noinst_HEADERS += compat/arc4random_freebsd.h | ||
91 | noinst_HEADERS += compat/arc4random_linux.h | 95 | noinst_HEADERS += compat/arc4random_linux.h |
92 | noinst_HEADERS += compat/arc4random_osx.h | 96 | noinst_HEADERS += compat/arc4random_osx.h |
93 | noinst_HEADERS += compat/arc4random_solaris.h | 97 | noinst_HEADERS += compat/arc4random_solaris.h |
diff --git a/crypto/compat/arc4random.h b/crypto/compat/arc4random.h index 9dae794..7af7fc1 100644 --- a/crypto/compat/arc4random.h +++ b/crypto/compat/arc4random.h | |||
@@ -1,7 +1,12 @@ | |||
1 | #ifndef LIBCRYPTOCOMPAT_ARC4RANDOM_H | 1 | #ifndef LIBCRYPTOCOMPAT_ARC4RANDOM_H |
2 | #define LIBCRYPTOCOMPAT_ARC4RANDOM_H | 2 | #define LIBCRYPTOCOMPAT_ARC4RANDOM_H |
3 | 3 | ||
4 | #if defined(__linux__) | 4 | #include <sys/param.h> |
5 | |||
6 | #if defined(__FreeBSD__) | ||
7 | #include "arc4random_freebsd.h" | ||
8 | |||
9 | #elif defined(__linux__) | ||
5 | #include "arc4random_linux.h" | 10 | #include "arc4random_linux.h" |
6 | 11 | ||
7 | #elif defined(__APPLE__) | 12 | #elif defined(__APPLE__) |
diff --git a/tests/Makefile.am.tpl b/tests/Makefile.am.tpl index 5a760da..ec7301c 100644 --- a/tests/Makefile.am.tpl +++ b/tests/Makefile.am.tpl | |||
@@ -3,7 +3,8 @@ include $(top_srcdir)/Makefile.am.common | |||
3 | AM_CPPFLAGS += -I $(top_srcdir)/crypto/modes | 3 | AM_CPPFLAGS += -I $(top_srcdir)/crypto/modes |
4 | AM_CPPFLAGS += -I $(top_srcdir)/crypto/asn1 | 4 | AM_CPPFLAGS += -I $(top_srcdir)/crypto/asn1 |
5 | 5 | ||
6 | LDADD = $(top_builddir)/ssl/libssl.la | 6 | LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) |
7 | LDADD += $(top_builddir)/ssl/libssl.la | ||
7 | LDADD += $(top_builddir)/crypto/libcrypto.la | 8 | LDADD += $(top_builddir)/crypto/libcrypto.la |
8 | 9 | ||
9 | TESTS = | 10 | TESTS = |