Skip to content

Commit 5a08ca3

Browse files
authored
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.
2 parents daf8aca + bd8885d commit 5a08ca3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libstd/sys/unix/rand.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ mod imp {
4747
let err = errno() as libc::c_int;
4848
if err == libc::EINTR {
4949
continue;
50-
} else if err == libc::ENOSYS {
50+
} else if err == libc::ENOSYS || err == libc::EPERM {
51+
// Fall back to reading /dev/urandom if `getrandom` is not
52+
// supported on the current kernel.
53+
//
54+
// Also fall back in case it is disabled by something like
55+
// seccomp or inside of virtual machines.
5156
GETRANDOM_UNAVAILABLE.store(true, Ordering::Relaxed);
5257
return false;
5358
} else if err == libc::EAGAIN {

0 commit comments

Comments
 (0)