Rollup merge of #60453 - tbu-:pr_getrandom_enoperm, r=sfackler

Fall back to `/dev/urandom` on `EPERM` for `getrandom`

This can happen because of seccomp or some VMs.

Fixes #52609.
This commit is contained in:
Mazdak Farrokhzad 2019-05-20 23:02:55 +02:00 committed by GitHub
commit 5a08ca38de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -47,7 +47,12 @@ mod imp {
let err = errno() as libc::c_int;
if err == libc::EINTR {
continue;
} else if err == libc::ENOSYS {
} else if err == libc::ENOSYS || err == libc::EPERM {
// Fall back to reading /dev/urandom if `getrandom` is not
// supported on the current kernel.
//
// Also fall back in case it is disabled by something like
// seccomp or inside of virtual machines.
GETRANDOM_UNAVAILABLE.store(true, Ordering::Relaxed);
return false;
} else if err == libc::EAGAIN {