diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-05-20 23:02:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-20 23:02:55 +0200 |
| commit | 5a08ca38deb7c363aa5078681b4ea90a6276c931 (patch) | |
| tree | fc317e13bf959d7c0ebd979193c77d15e7d983a3 /src/libstd/sys | |
| parent | daf8aca0e3b9566bdd96479b6efae2e93de97bd1 (diff) | |
| parent | bd8885d340beb20ac1728d0bd7e64321da641b91 (diff) | |
| download | rust-5a08ca38deb7c363aa5078681b4ea90a6276c931.tar.gz rust-5a08ca38deb7c363aa5078681b4ea90a6276c931.zip | |
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.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/rand.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 77f1439e17b..71c62461ee9 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -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 { |
