Don't set /dev/hwrng to O_NONBLOCK

Reads on `tokio::fs::File` are expected to block, and are performed
inside a `spawn_blocking` call so that they don't block the reactor.

Bug: 268075535
Test: read from /dev/socket/prng_seeder 256 times
Change-Id: I009d1fb11b540412e705cc2be0ebc7e2f09d2c0c
This commit is contained in:
Paul Crowley 2023-03-09 17:51:58 +00:00
parent 308b2c22f9
commit 17885691e7
2 changed files with 2 additions and 5 deletions

View file

@ -1,2 +1,2 @@
paulcrowley@google.com
prb@google.com
prb@google.com

View file

@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{fs::File, io::Read, os::unix::io::AsRawFd};
use std::{fs::File, io::Read};
use anyhow::{ensure, Context, Result};
use log::debug;
use nix::fcntl::{fcntl, FcntlArg::F_SETFL, OFlag};
use tokio::io::AsyncReadExt;
use crate::drbg;
@ -34,8 +33,6 @@ impl ConditionerBuilder {
let mut et: drbg::Entropy = [0; drbg::ENTROPY_LEN];
hwrng.read_exact(&mut et).context("hwrng.read_exact in new")?;
let rg = drbg::Drbg::new(&et)?;
fcntl(hwrng.as_raw_fd(), F_SETFL(OFlag::O_NONBLOCK))
.context("setting O_NONBLOCK on hwrng")?;
Ok(ConditionerBuilder { hwrng, rg })
}