Skip to content

Commit

Permalink
Rollup merge of rust-lang#60453 - tbu-:pr_getrandom_enoperm, r=sfackler
Browse files Browse the repository at this point in the history
Fall back to `/dev/urandom` on `EPERM` for `getrandom`

This can happen because of seccomp or some VMs.

Fixes rust-lang#52609.
  • Loading branch information
Centril authored May 20, 2019
2 parents daf8aca + bd8885d commit 5a08ca3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libstd/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5a08ca3

Please sign in to comment.