Use getrandom for random_get, disable default rand features (#625)
* use getrandom, disable default rand features
This commit is contained in:
committed by
Dan Gohman
parent
64f9cee842
commit
752ed901d6
@@ -44,7 +44,7 @@ errno = "0.2.4"
|
|||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
target-lexicon = { version = "0.9.0", default-features = false }
|
target-lexicon = { version = "0.9.0", default-features = false }
|
||||||
pretty_env_logger = "0.3.0"
|
pretty_env_logger = "0.3.0"
|
||||||
rand = { version = "0.7.0", features = ["small_rng"] }
|
rand = { version = "0.7.0", default-features = false, features = ["small_rng"] }
|
||||||
cranelift-codegen = { version = "0.50.0", features = ["enable-serde", "all-arch"] }
|
cranelift-codegen = { version = "0.50.0", features = ["enable-serde", "all-arch"] }
|
||||||
filetime = "0.2.7"
|
filetime = "0.2.7"
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ wasi-common-cbindgen = { path = "wasi-common-cbindgen" }
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
rand = "0.7"
|
getrandom = "0.1"
|
||||||
cfg-if = "0.1.9"
|
cfg-if = "0.1.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
filetime = "0.2.7"
|
filetime = "0.2.7"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::fdentry::Descriptor;
|
|||||||
use crate::memory::*;
|
use crate::memory::*;
|
||||||
use crate::sys::hostcalls_impl;
|
use crate::sys::hostcalls_impl;
|
||||||
use crate::{wasi, wasi32, Error, Result};
|
use crate::{wasi, wasi32, Error, Result};
|
||||||
use log::trace;
|
use log::{error, trace};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
pub(crate) fn args_get(
|
pub(crate) fn args_get(
|
||||||
@@ -132,15 +132,14 @@ pub(crate) fn random_get(
|
|||||||
buf_ptr: wasi32::uintptr_t,
|
buf_ptr: wasi32::uintptr_t,
|
||||||
buf_len: wasi32::size_t,
|
buf_len: wasi32::size_t,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use rand::{thread_rng, RngCore};
|
|
||||||
|
|
||||||
trace!("random_get(buf_ptr={:#x?}, buf_len={:?})", buf_ptr, buf_len);
|
trace!("random_get(buf_ptr={:#x?}, buf_len={:?})", buf_ptr, buf_len);
|
||||||
|
|
||||||
let buf = dec_slice_of_mut_u8(memory, buf_ptr, buf_len)?;
|
let buf = dec_slice_of_mut_u8(memory, buf_ptr, buf_len)?;
|
||||||
|
|
||||||
thread_rng().fill_bytes(buf);
|
getrandom::getrandom(buf).map_err(|err| {
|
||||||
|
error!("getrandom failure: {:?}", err);
|
||||||
Ok(())
|
Error::EIO
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clock_res_get(
|
pub(crate) fn clock_res_get(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::old::snapshot_0::fdentry::Descriptor;
|
|||||||
use crate::old::snapshot_0::memory::*;
|
use crate::old::snapshot_0::memory::*;
|
||||||
use crate::old::snapshot_0::sys::hostcalls_impl;
|
use crate::old::snapshot_0::sys::hostcalls_impl;
|
||||||
use crate::old::snapshot_0::{wasi, wasi32, Error, Result};
|
use crate::old::snapshot_0::{wasi, wasi32, Error, Result};
|
||||||
use log::trace;
|
use log::{error, trace};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
pub(crate) fn args_get(
|
pub(crate) fn args_get(
|
||||||
@@ -132,15 +132,14 @@ pub(crate) fn random_get(
|
|||||||
buf_ptr: wasi32::uintptr_t,
|
buf_ptr: wasi32::uintptr_t,
|
||||||
buf_len: wasi32::size_t,
|
buf_len: wasi32::size_t,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use rand::{thread_rng, RngCore};
|
|
||||||
|
|
||||||
trace!("random_get(buf_ptr={:#x?}, buf_len={:?})", buf_ptr, buf_len);
|
trace!("random_get(buf_ptr={:#x?}, buf_len={:?})", buf_ptr, buf_len);
|
||||||
|
|
||||||
let buf = dec_slice_of_mut_u8(memory, buf_ptr, buf_len)?;
|
let buf = dec_slice_of_mut_u8(memory, buf_ptr, buf_len)?;
|
||||||
|
|
||||||
thread_rng().fill_bytes(buf);
|
getrandom::getrandom(buf).map_err(|err| {
|
||||||
|
error!("getrandom failure: {:?}", err);
|
||||||
Ok(())
|
Error::EIO
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clock_res_get(
|
pub(crate) fn clock_res_get(
|
||||||
|
|||||||
Reference in New Issue
Block a user