@@ -121,8 +121,8 @@ py_getentropy(unsigned char *buffer, Py_ssize_t size, int fatal)
121121
122122/* Call getrandom()
123123 - Return 1 on success
124- - Return 0 if getrandom() syscall is not available (failed with ENOSYS)
125- or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system urandom
124+ - Return 0 if getrandom() syscall is not available (failed with ENOSYS or
125+ EPERM) or if getrandom(GRND_NONBLOCK) failed with EAGAIN (system urandom
126126 not initialized yet) and raise=0.
127127 - Raise an exception (if raise is non-zero) and return -1 on error:
128128 getrandom() failed with EINTR and the Python signal handler raised an
@@ -131,7 +131,7 @@ static int
131131py_getrandom (void * buffer , Py_ssize_t size , int raise )
132132{
133133 /* Is getrandom() supported by the running kernel? Set to 0 if getrandom()
134- failed with ENOSYS. Need Linux kernel 3.17 or newer, or Solaris
134+ failed with ENOSYS or EPERM . Need Linux kernel 3.17 or newer, or Solaris
135135 11.3 or newer */
136136 static int getrandom_works = 1 ;
137137
@@ -182,8 +182,9 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise)
182182
183183 if (n < 0 ) {
184184 /* ENOSYS: getrandom() syscall not supported by the kernel (but
185- * maybe supported by the host which built Python). */
186- if (errno == ENOSYS ) {
185+ * maybe supported by the host which built Python). EPERM:
186+ * getrandom() syscall blocked by SECCOMP or something else. */
187+ if (errno == ENOSYS || errno == EPERM ) {
187188 getrandom_works = 0 ;
188189 return 0 ;
189190 }
@@ -250,7 +251,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
250251 if (py_getrandom (buffer , size , 0 ) == 1 ) {
251252 return ;
252253 }
253- /* getrandom() failed with ENOSYS,
254+ /* getrandom() failed with ENOSYS or EPERM ,
254255 fall back on reading /dev/urandom */
255256#endif
256257
@@ -301,7 +302,7 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
301302 if (res == 1 ) {
302303 return 0 ;
303304 }
304- /* getrandom() failed with ENOSYS,
305+ /* getrandom() failed with ENOSYS or EPERM ,
305306 fall back on reading /dev/urandom */
306307#endif
307308
0 commit comments