mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
virtio-devices: vhost_user: block: Only change mutable field in write_config()
The only driver writable field in the virtio-block specification is the writeback one. Check that the offset being written to is for that field and update it. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
eabcd618ba
commit
dfd6f3471d
@ -191,18 +191,23 @@ impl VirtioDevice for Blk {
|
||||
}
|
||||
|
||||
fn write_config(&mut self, offset: u64, data: &[u8]) {
|
||||
let config_slice = self.config.as_mut_slice();
|
||||
let data_len = data.len() as u64;
|
||||
let config_len = config_slice.len() as u64;
|
||||
if offset + data_len > config_len {
|
||||
error!("Failed to write config space");
|
||||
// The "writeback" field is the only mutable field
|
||||
let writeback_offset =
|
||||
(&self.config.writeback as *const _ as u64) - (&self.config as *const _ as u64);
|
||||
if offset != writeback_offset || data.len() != std::mem::size_of_val(&self.config.writeback)
|
||||
{
|
||||
error!(
|
||||
"Attempt to write to read-only field: offset {:x} length {}",
|
||||
offset,
|
||||
data.len()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
self.config.writeback = data[0];
|
||||
self.vhost_user_blk
|
||||
.set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data)
|
||||
.expect("Failed to set config");
|
||||
let (_, right) = config_slice.split_at_mut(offset as usize);
|
||||
right.copy_from_slice(&data[..]);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
|
Loading…
Reference in New Issue
Block a user