mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-09-12 18:15:06 +00:00
virtio-devices: 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
751a302050
commit
eabcd618ba
@ -508,15 +508,20 @@ impl<T: 'static + DiskFile + Send> VirtioDevice for Block<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
let (_, right) = config_slice.split_at_mut(offset as usize);
|
|
||||||
right.copy_from_slice(&data[..]);
|
self.config.writeback = data[0];
|
||||||
self.update_writeback();
|
self.update_writeback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user