mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: iommu: Pass size to translate_gva/translate_gpa
The DmaRemapping translate_gva and translate_gpa entry points discarded the size argument that AccessPlatform's signature already carries and only checked the base address. A buffer beginning inside a mapping but extending past it was treated as fully translated, allowing reads or writes outside the IOMMU-authorized window. Add `size` to the trait, validate the full span fits in a single mapping, and propagate it through AccessPlatformMapping. Signed-off-by: Rob Bradford <rbradford@meta.com> Assisted-by: Claude:claude-opus-4-7
This commit is contained in:
@@ -202,10 +202,23 @@ pub trait VirtioDevice: Send {
|
||||
/// On the other side, the implementation itself should be provided by the code
|
||||
/// emulating the IOMMU for the guest.
|
||||
pub trait DmaRemapping {
|
||||
/// Provide a way to translate GVA address ranges into GPAs.
|
||||
fn translate_gva(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
/// Provide a way to translate GPA address ranges into GVAs.
|
||||
fn translate_gpa(&self, id: u32, addr: u64) -> std::result::Result<u64, std::io::Error>;
|
||||
/// Provide a way to translate GVA address ranges into GPAs. The
|
||||
/// implementation must reject translations whose [addr, addr+size)
|
||||
/// span isn't entirely covered by a single mapping.
|
||||
fn translate_gva(
|
||||
&self,
|
||||
id: u32,
|
||||
addr: u64,
|
||||
size: u64,
|
||||
) -> std::result::Result<u64, std::io::Error>;
|
||||
/// Provide a way to translate GPA address ranges into GVAs. Same
|
||||
/// span requirement as `translate_gva`.
|
||||
fn translate_gpa(
|
||||
&self,
|
||||
id: u32,
|
||||
addr: u64,
|
||||
size: u64,
|
||||
) -> std::result::Result<u64, std::io::Error>;
|
||||
}
|
||||
|
||||
/// Structure to handle device state common to all devices
|
||||
|
||||
Reference in New Issue
Block a user