mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: iommu: Validate descriptor ranges
Add check_range calls on request and status descriptor addresses to reject buffers that extend past guest memory. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
795e606183
commit
a5962db441
@@ -18,7 +18,7 @@ use thiserror::Error;
|
|||||||
use virtio_queue::{DescriptorChain, Queue, QueueT};
|
use virtio_queue::{DescriptorChain, Queue, QueueT};
|
||||||
use vm_device::dma_mapping::ExternalDmaMapping;
|
use vm_device::dma_mapping::ExternalDmaMapping;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
|
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
|
||||||
GuestMemoryError, GuestMemoryLoadGuard,
|
GuestMemoryError, GuestMemoryLoadGuard,
|
||||||
};
|
};
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
||||||
@@ -371,6 +371,15 @@ impl Request {
|
|||||||
return Err(Error::InvalidRequest);
|
return Err(Error::InvalidRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !desc_chain
|
||||||
|
.memory()
|
||||||
|
.check_range(desc.addr(), desc.len() as usize)
|
||||||
|
{
|
||||||
|
return Err(Error::GuestMemory(GuestMemoryError::InvalidGuestAddress(
|
||||||
|
desc.addr(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
let req_head: VirtioIommuReqHead = desc_chain
|
let req_head: VirtioIommuReqHead = desc_chain
|
||||||
.memory()
|
.memory()
|
||||||
.read_obj(desc.addr())
|
.read_obj(desc.addr())
|
||||||
@@ -785,6 +794,15 @@ impl Request {
|
|||||||
return Err(Error::BufferLengthTooSmall);
|
return Err(Error::BufferLengthTooSmall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !desc_chain
|
||||||
|
.memory()
|
||||||
|
.check_range(status_desc.addr(), status_desc.len() as usize)
|
||||||
|
{
|
||||||
|
return Err(Error::GuestMemory(GuestMemoryError::InvalidGuestAddress(
|
||||||
|
status_desc.addr(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
let tail = VirtioIommuReqTail {
|
let tail = VirtioIommuReqTail {
|
||||||
status,
|
status,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|||||||
Reference in New Issue
Block a user