From b49f8b92483fab131f56e96887898e53cafe6da0 Mon Sep 17 00:00:00 2001 From: Markus Napierkowski Date: Thu, 18 Aug 2022 14:03:58 +0200 Subject: [PATCH] virtio-devices: rng: correctly indicate number of bytes written Reads from the random file may only be partial, e.g., if the random file is an ordinary text file. When that happens, the device needs to signal to the driver that only parts of the buffer have been overwritten. Signed-off-by: Markus Napierkowski --- virtio-devices/src/rng.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/virtio-devices/src/rng.rs b/virtio-devices/src/rng.rs index f8b05e20e..5984865f0 100644 --- a/virtio-devices/src/rng.rs +++ b/virtio-devices/src/rng.rs @@ -58,17 +58,13 @@ impl RngEpollHandler { // Drivers can only read from the random device. if desc.is_write_only() { // Fill the read with data from the random device on the host. - if desc_chain - .memory() - .read_from( - desc.addr() - .translate_gva(self.access_platform.as_ref(), desc.len() as usize), - &mut self.random_file, - desc.len() as usize, - ) - .is_ok() - { - len = desc.len(); + if let Ok(number_of_bytes) = desc_chain.memory().read_from( + desc.addr() + .translate_gva(self.access_platform.as_ref(), desc.len() as usize), + &mut self.random_file, + desc.len() as usize, + ) { + len = number_of_bytes as u32; } }