intel_iommu: Only set dirty bit when PTE exposes write permission
PATCH 1/2 intel_iommu: Only set dirty bit when PTE exposes write permission
Setting the dirty bit without the write bit in vIOMMU creates a spoofed shadow stack PTE that misleads the guest OS. This results in infinite PRI requests from the device, as no actual write permission is ever granted - the guest OS treats the PTE as a legitimate shadow stack entry and considers the permissions already correct.
Fixes 65c4f0999991 ("intel_iommu: Set accessed and dirty bits during stage-1 translation")
Signed-off-by Clement Mathieu--Drif <[email protected]>
Reviewed-by Yi Liu <[email protected]>
--- hw/i386/intel_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
@@ -2066,7 +2066,7 @@ static int vtd_iova_to_fspte(IntelIOMMUState *s, VTDContextEntry *ce,return -VTD_FR_FS_PAGING_ENTRY_RSVD ; } -if (vtd_is_last_pte (fspte, *fspte_level) && is_write) { +if (vtd_is_last_pte (fspte, *fspte_level) && *writes && is_write) { flag_ad |=VTD_FS_D ; }
Signature · 1 line
2.53.0
PATCH 2/2 intel_iommu: Always write all the flags passed to vtd_set_flag_in_pte
This function was initially designed to write a single flag in a pte. The current implementation expects it to set several flags.
Fixes 65c4f0999991 ("intel_iommu: Set accessed and dirty bits during stage-1 translation")
Signed-off-by Clement Mathieu--Drif <[email protected]>
Reviewed-by Yi Liu <[email protected]>
Reviewed-by Zhenzhong Duan <[email protected]>
--- hw/i386/intel_iommu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/i386/intel_iommu.c +5 -5
@@ -1991,13 +1991,13 @@ static bool vtd_iova_fs_check_canonical(IntelIOMMUState *s, uint64_t iova, } } -static MemTxResult vtd_set_flag_in_pte (dma_addr_t base_addr,uint32_t index, -uint64_t pte,uint64_t flag) +static MemTxResult vtd_set_flags_in_pte (dma_addr_t base_addr,uint32_t index, +uint64_t pte,uint64_t flags) { -if (pte & flag) { +if ((pte & flags) == flags) {return MEMTX_OK ; } - pte |= flag; + pte |= flags; pte =cpu_to_le64 (pte); return dma_memory_write(&address_space_memory, base_addr + index * sizeof(pte),
@@ -2070,7 +2070,7 @@ static int vtd_iova_to_fspte(IntelIOMMUState *s, VTDContextEntry *ce, flag_ad |=VTD_FS_D ; } -if (vtd_set_flag_in_pte (addr, offset, fspte, flag_ad) !=MEMTX_OK ) { +if (vtd_set_flags_in_pte (addr, offset, fspte, flag_ad) !=MEMTX_OK ) {return -VTD_FR_FS_BIT_UPDATE_FAILED ; }
Signature · 1 line
2.53.0