mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-05 21:15:45 +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]) {
|
fn write_config(&mut self, offset: u64, data: &[u8]) {
|
||||||
let config_slice = self.config.as_mut_slice();
|
// The "writeback" field is the only mutable field
|
||||||
let data_len = data.len() as u64;
|
let writeback_offset =
|
||||||
let config_len = config_slice.len() as u64;
|
(&self.config.writeback as *const _ as u64) - (&self.config as *const _ as u64);
|
||||||
if offset + data_len > config_len {
|
if offset != writeback_offset || data.len() != std::mem::size_of_val(&self.config.writeback)
|
||||||
error!("Failed to write config space");
|
{
|
||||||
|
error!(
|
||||||
|
"Attempt to write to read-only field: offset {:x} length {}",
|
||||||
|
offset,
|
||||||
|
data.len()
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.config.writeback = data[0];
|
||||||
self.vhost_user_blk
|
self.vhost_user_blk
|
||||||
.set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data)
|
.set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data)
|
||||||
.expect("Failed to set config");
|
.expect("Failed to set config");
|
||||||
let (_, right) = config_slice.split_at_mut(offset as usize);
|
|
||||||
right.copy_from_slice(&data[..]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate(
|
fn activate(
|
||||||
|
Loading…
Reference in New Issue
Block a user