aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-05-25 20:02:36 +0200
committerDuncaen <mail@duncano.de>2017-05-25 20:07:08 +0200
commit4f82162df84f734db1215baf3a0a52e7d91f6a1c (patch)
tree7dff40ed0dd5c8eee1099a60a54ae2ff74be4085
parent2afdb8469758ce0d4bb60298575215a769254189 (diff)
downloadlobase-4f82162df84f734db1215baf3a0a52e7d91f6a1c.tar.gz
lib/libopenbsd: update getentropy_linux.c
-rw-r--r--lib/libopenbsd/Makefile1
-rw-r--r--lib/libopenbsd/getentropy_linux.c15
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/libopenbsd/Makefile b/lib/libopenbsd/Makefile
index cdd1d8d..1655418 100644
--- a/lib/libopenbsd/Makefile
+++ b/lib/libopenbsd/Makefile
@@ -23,7 +23,6 @@ endif
ifneq ($(HAVE_GETENTROPY),1)
# XXX: fix fstatfs
SRCS+= getentropy_linux.c
-getentropy_linux.o : CPPFLAGS += -D_GNU_SOURCE
endif
include ${.TOPDIR}/mk/bsd.lib.mk
diff --git a/lib/libopenbsd/getentropy_linux.c b/lib/libopenbsd/getentropy_linux.c
index 7e74798..a845239 100644
--- a/lib/libopenbsd/getentropy_linux.c
+++ b/lib/libopenbsd/getentropy_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getentropy_linux.c,v 1.42 2016/04/19 20:20:24 tj Exp $ */
+/* $OpenBSD: getentropy_linux.c,v 1.44 2017/04/29 18:43:31 beck Exp $ */
/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
@@ -96,13 +96,16 @@ getentropy(void *buf, size_t len)
#ifdef SYS_getrandom
/*
- * Try descriptor-less getrandom()
+ * Try descriptor-less getrandom(), in non-blocking mode.
+ *
+ * The design of Linux getrandom is broken. It has an
+ * uninitialized phase coupled with blocking behaviour, which
+ * is unacceptable from within a library at boot time without
+ * possible recovery. See http://bugs.python.org/issue26839#msg267745
*/
ret = getentropy_getrandom(buf, len);
if (ret != -1)
return (ret);
- if (errno != ENOSYS)
- return (-1);
#endif
/*
@@ -156,7 +159,7 @@ getentropy(void *buf, size_t len)
* - Do the best under the circumstances....
*
* This code path exists to bring light to the issue that Linux
- * does not provide a failsafe API for entropy collection.
+ * still does not provide a failsafe API for entropy collection.
*
* We hope this demonstrates that Linux should either retain their
* sysctl ABI, or consider providing a new failsafe API which
@@ -199,7 +202,7 @@ getentropy_getrandom(void *buf, size_t len)
if (len > 256)
return (-1);
do {
- ret = syscall(SYS_getrandom, buf, len, 0);
+ ret = syscall(SYS_getrandom, buf, len, GRND_NONBLOCK);
} while (ret == -1 && errno == EINTR);
if (ret != len)