Merge 3.6

This commit is contained in:
Victor Stinner 2016-09-20 22:50:11 +02:00
commit 6b405d2f2b
2 changed files with 14 additions and 8 deletions

View File

@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #27955: Fallback on reading /dev/urandom device when the getrandom()
syscall fails with EPERM, for example when blocked by SECCOMP.
- Issue #28192: Don't import readline in isolated mode. - Issue #28192: Don't import readline in isolated mode.
- Issue #27441: Remove some redundant assignments to ob_size in longobject.c. - Issue #27441: Remove some redundant assignments to ob_size in longobject.c.

View File

@ -121,9 +121,9 @@ py_getentropy(char *buffer, Py_ssize_t size, int raise)
/* Call getrandom() /* Call getrandom()
- Return 1 on success - Return 1 on success
- Return 0 if getrandom() syscall is not available (fails with ENOSYS) - Return 0 if getrandom() syscall is not available (failed with ENOSYS or
or if getrandom(GRND_NONBLOCK) fails with EAGAIN (blocking=0 and system EPERM) or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system urandom
urandom not initialized yet) and raise=0. not initialized yet) and raise=0.
- Raise an exception (if raise is non-zero) and return -1 on error: - Raise an exception (if raise is non-zero) and return -1 on error:
getrandom() failed with EINTR and the Python signal handler raised an getrandom() failed with EINTR and the Python signal handler raised an
exception, or getrandom() failed with a different error. */ exception, or getrandom() failed with a different error. */
@ -131,8 +131,8 @@ static int
py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise) py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
{ {
/* Is getrandom() supported by the running kernel? Set to 0 if getrandom() /* Is getrandom() supported by the running kernel? Set to 0 if getrandom()
fails with ENOSYS. Need Linux kernel 3.17 or newer, or Solaris 11.3 failed with ENOSYS or EPERM. Need Linux kernel 3.17 or newer, or Solaris
or newer */ 11.3 or newer */
static int getrandom_works = 1; static int getrandom_works = 1;
int flags; int flags;
char *dest; char *dest;
@ -178,7 +178,10 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
#endif #endif
if (n < 0) { if (n < 0) {
if (errno == ENOSYS) { /* ENOSYS: getrandom() syscall not supported by the kernel (but
* maybe supported by the host which built Python). EPERM:
* getrandom() syscall blocked by SECCOMP or something else. */
if (errno == ENOSYS || errno == EPERM) {
getrandom_works = 0; getrandom_works = 0;
return 0; return 0;
} }
@ -246,8 +249,8 @@ dev_urandom(char *buffer, Py_ssize_t size, int blocking, int raise)
if (res == 1) { if (res == 1) {
return 0; return 0;
} }
/* getrandom() is not supported by the running kernel, fall back /* getrandom() failed with ENOSYS or EPERM,
on reading /dev/urandom */ fall back on reading /dev/urandom */
#endif #endif