mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: watchdog: Use checked descriptor iterator
Replace raw desc.addr() usage with checked_iter which validates the descriptor buffer range against guest memory before I/O. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
4192f5101b
commit
33e3f4e29e
@@ -22,6 +22,7 @@ use thiserror::Error;
|
||||
use virtio_queue::{Queue, QueueT};
|
||||
use vm_memory::{Bytes, GuestAddressSpace, GuestMemoryAtomic};
|
||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
||||
use vm_virtio::checked_descriptor::DescriptorChainExt;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
use super::{
|
||||
@@ -81,9 +82,13 @@ impl WatchdogEpollHandler {
|
||||
let queue = &mut self.queue;
|
||||
let mut used_descs = false;
|
||||
while let Some(mut desc_chain) = queue.pop_descriptor_chain(self.mem.memory()) {
|
||||
let desc = desc_chain.next().ok_or(Error::DescriptorChainTooShort)?;
|
||||
let mut descs = desc_chain.checked_iter(None);
|
||||
let desc = descs
|
||||
.next()
|
||||
.ok_or(Error::DescriptorChainTooShort)?
|
||||
.map_err(|_| Error::InvalidDescriptor)?;
|
||||
|
||||
if !(desc.is_write_only() && desc.len() > 0) {
|
||||
if !desc.is_write_only() || desc.is_empty() {
|
||||
return Err(Error::InvalidDescriptor);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user