mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
Catch EPERM error in py_getrandom()
Issue #27955: Fallback on reading /dev/urandom device when the getrandom() syscall fails with EPERM, for example when blocked by SECCOMP.
This commit is contained in:
parent
af59732102
commit
6d8bc46cc0
2 changed files with 11 additions and 7 deletions
|
@ -10,6 +10,9 @@ Release date: TBA
|
||||||
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 #28131: Fix a regression in zipimport's compile_source(). zipimport
|
- Issue #28131: Fix a regression in zipimport's compile_source(). zipimport
|
||||||
should use the same optimization level as the interpreter.
|
should use the same optimization level as the interpreter.
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,8 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal)
|
||||||
|
|
||||||
/* Call getrandom()
|
/* Call getrandom()
|
||||||
- Return 1 on success
|
- Return 1 on success
|
||||||
- Return 0 if getrandom() syscall is not available (failed with ENOSYS)
|
- Return 0 if getrandom() syscall is not available (failed with ENOSYS or
|
||||||
or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system urandom
|
EPERM) or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system 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
|
||||||
|
@ -131,7 +131,7 @@ static int
|
||||||
py_getrandom(void *buffer, Py_ssize_t size, int raise)
|
py_getrandom(void *buffer, Py_ssize_t size, 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()
|
||||||
failed with ENOSYS. Need Linux kernel 3.17 or newer, or Solaris
|
failed with ENOSYS or EPERM. Need Linux kernel 3.17 or newer, or Solaris
|
||||||
11.3 or newer */
|
11.3 or newer */
|
||||||
static int getrandom_works = 1;
|
static int getrandom_works = 1;
|
||||||
|
|
||||||
|
@ -182,8 +182,9 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
|
||||||
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
/* ENOSYS: getrandom() syscall not supported by the kernel (but
|
/* ENOSYS: getrandom() syscall not supported by the kernel (but
|
||||||
* maybe supported by the host which built Python). */
|
* maybe supported by the host which built Python). EPERM:
|
||||||
if (errno == ENOSYS) {
|
* getrandom() syscall blocked by SECCOMP or something else. */
|
||||||
|
if (errno == ENOSYS || errno == EPERM) {
|
||||||
getrandom_works = 0;
|
getrandom_works = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +251,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
|
||||||
if (py_getrandom(buffer, size, 0) == 1) {
|
if (py_getrandom(buffer, size, 0) == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* getrandom() failed with ENOSYS,
|
/* getrandom() failed with ENOSYS or EPERM,
|
||||||
fall back on reading /dev/urandom */
|
fall back on reading /dev/urandom */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -301,7 +302,7 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* getrandom() failed with ENOSYS,
|
/* getrandom() failed with ENOSYS or EPERM,
|
||||||
fall back on reading /dev/urandom */
|
fall back on reading /dev/urandom */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue