[Python-checkins] cpython (2.7): Don't use getentropy() on Linux
victor.stinner
python-checkins at python.org
Mon Jan 9 05:22:20 EST 2017
https://hg.python.org/cpython/rev/13a39142c047
changeset: 106060:13a39142c047
branch: 2.7
parent: 106053:cb4f73be9486
user: Victor Stinner <victor.stinner at gmail.com>
date: Mon Jan 09 11:10:41 2017 +0100
summary:
Don't use getentropy() on Linux
Issue #29188: Support glibc 2.24 on Linux: don't use getentropy() function but
read from /dev/urandom to get random bytes, for example in os.urandom(). On
Linux, getentropy() is implemented which getrandom() is blocking mode, whereas
os.urandom() should not block.
files:
Misc/NEWS | 5 +++++
Python/random.c | 11 +++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,11 @@
Library
-------
+- Issue #29188: Support glibc 2.24 on Linux: don't use getentropy() function
+ but read from /dev/urandom to get random bytes, for example in os.urandom().
+ On Linux, getentropy() is implemented which getrandom() is blocking mode,
+ whereas os.urandom() should not block.
+
- Issue #29142: In urllib, suffixes in no_proxy environment variable with
leading dots could match related hostnames again (e.g. .b.c matches a.b.c).
Patch by Milan Oberkirch.
diff --git a/Python/random.c b/Python/random.c
--- a/Python/random.c
+++ b/Python/random.c
@@ -97,8 +97,15 @@
}
/* Issue #25003: Don't use getentropy() on Solaris (available since
- * Solaris 11.3), it is blocking whereas os.urandom() should not block. */
-#elif defined(HAVE_GETENTROPY) && !defined(sun)
+ Solaris 11.3), it is blocking whereas os.urandom() should not block.
+
+ Issue #29188: Don't use getentropy() on Linux since the glibc 2.24
+ implements it with the getrandom() syscall which can fail with ENOSYS,
+ and this error is not supported in py_getentropy() and getrandom() is called
+ with flags=0 which blocks until system urandom is initialized, which is not
+ the desired behaviour to seed the Python hash secret nor for os.urandom():
+ see the PEP 524 which was only implemented in Python 3.6. */
+#elif defined(HAVE_GETENTROPY) && !defined(sun) && !defined(linux)
#define PY_GETENTROPY 1
/* Fill buffer with size pseudo-random bytes generated by getentropy().
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list