mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 03:12:27 +00:00
devices: acpi: Increase robustness of bus devices
Check the size of data buffer for reading on the ApciPmTimer device to avoid a potential panic if the guest uses non-DWORD access. Simplify the zeroring of the buffer for AcpiShutdownDevice. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
1d78812b63
commit
a77160dca4
@ -34,9 +34,7 @@ impl AcpiShutdownDevice {
|
|||||||
impl BusDevice for AcpiShutdownDevice {
|
impl BusDevice for AcpiShutdownDevice {
|
||||||
// Spec has all fields as zero
|
// Spec has all fields as zero
|
||||||
fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {
|
fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {
|
||||||
for i in data.iter_mut() {
|
data.fill(0)
|
||||||
*i = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, _base: u64, _offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
|
fn write(&mut self, _base: u64, _offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
|
||||||
@ -191,6 +189,10 @@ impl Default for AcpiPmTimerDevice {
|
|||||||
|
|
||||||
impl BusDevice for AcpiPmTimerDevice {
|
impl BusDevice for AcpiPmTimerDevice {
|
||||||
fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {
|
fn read(&mut self, _base: u64, _offset: u64, data: &mut [u8]) {
|
||||||
|
if data.len() != std::mem::size_of::<u32>() {
|
||||||
|
warn!("Invalid sized read of PM timer: {}", data.len());
|
||||||
|
return;
|
||||||
|
}
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let since = now.duration_since(self.start);
|
let since = now.duration_since(self.start);
|
||||||
let nanos = since.as_nanos();
|
let nanos = since.as_nanos();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user