mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vhost_user_block: set_config tolerates partial sub-range writes
set_config() split the config slice at `offset` and copy_from_slice'd the entire suffix, which asserts src.len() == self.len(). This panics if the guest issues a write shorter than `config_len - offset`. Signed-off-by: Dylan Reid <dgreid@fb.com>
This commit is contained in:
@@ -403,12 +403,14 @@ impl VhostUserBackendMut for VhostUserBlkBackend {
|
|||||||
let config_slice = self.config.as_mut_slice();
|
let config_slice = self.config.as_mut_slice();
|
||||||
let data_len = data.len() as u32;
|
let data_len = data.len() as u32;
|
||||||
let config_len = config_slice.len() as u32;
|
let config_len = config_slice.len() as u32;
|
||||||
if offset + data_len > config_len {
|
let end = offset
|
||||||
error!("Failed to write config space");
|
.checked_add(data_len)
|
||||||
|
.ok_or_else(|| io::Error::from_raw_os_error(libc::EINVAL))?;
|
||||||
|
if end > config_len {
|
||||||
|
error!("Failed to write config space: offset {offset} + len {data_len} > {config_len}");
|
||||||
return Err(io::Error::from_raw_os_error(libc::EINVAL));
|
return Err(io::Error::from_raw_os_error(libc::EINVAL));
|
||||||
}
|
}
|
||||||
let (_, right) = config_slice.split_at_mut(offset as usize);
|
config_slice[offset as usize..end as usize].copy_from_slice(data);
|
||||||
right.copy_from_slice(data);
|
|
||||||
self.update_writeback();
|
self.update_writeback();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user