1 This patch resolves a compatibility issue when compiled against glibc
3 and run runder kernels < 3.17:
5 https://bugzilla.redhat.com/show_bug.cgi?id=1410175
9 https://bugs.python.org/issue29157
10 https://bugs.python.org/issue29188
12 Patch adapted from upstream source repository:
14 https://github.com/python/cpython/commit/01bdbad3e951014c58581635b94b22868537901c
16 From 01bdbad3e951014c58581635b94b22868537901c Mon Sep 17 00:00:00 2001
17 From: Victor Stinner <victor.stinner@gmail.com>
18 Date: Mon, 9 Jan 2017 11:10:41 +0100
19 Subject: [PATCH] Don't use getentropy() on Linux
21 Issue #29188: Support glibc 2.24 on Linux: don't use getentropy() function but
22 read from /dev/urandom to get random bytes, for example in os.urandom(). On
23 Linux, getentropy() is implemented which getrandom() is blocking mode, whereas
24 os.urandom() should not block.
27 Python/random.c | 11 +++++++++--
28 2 files changed, 14 insertions(+), 2 deletions(-)
30 diff --git a/Python/random.c b/Python/random.c
31 index 57c41ffcd6..000cb36938 100644
34 @@ -97,8 +97,15 @@ win32_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
37 /* Issue #25003: Don't use getentropy() on Solaris (available since
38 - * Solaris 11.3), it is blocking whereas os.urandom() should not block. */
39 -#elif defined(HAVE_GETENTROPY) && !defined(sun)
40 + Solaris 11.3), it is blocking whereas os.urandom() should not block.
42 + Issue #29188: Don't use getentropy() on Linux since the glibc 2.24
43 + implements it with the getrandom() syscall which can fail with ENOSYS,
44 + and this error is not supported in py_getentropy() and getrandom() is called
45 + with flags=0 which blocks until system urandom is initialized, which is not
46 + the desired behaviour to seed the Python hash secret nor for os.urandom():
47 + see the PEP 524 which was only implemented in Python 3.6. */
48 +#elif defined(HAVE_GETENTROPY) && !defined(sun) && !defined(linux)
49 #define PY_GETENTROPY 1
51 /* Fill buffer with size pseudo-random bytes generated by getentropy().