|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] x86/nSVM: Validate the L1 IOPM physical address range
commit 8c36d5a500da81c15d088f7349286307537ca8b1
Author: Abdelkareem Abdelsaamad <abdelkareem.abdelsaamad@xxxxxxxxxx>
AuthorDate: Wed Aug 19 11:57:26 2026 +0200
Commit: Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Aug 19 11:57:26 2026 +0200
x86/nSVM: Validate the L1 IOPM physical address range
The Xen nested virtualization code does not validate that the physical
address
range assigned by the L1 guest, for IOPM, resides within the valid guest
physical memory. Add a sanity check to properly validate the IOPM is in the
valid L1 guest address range. This check also makes the behaviour compliant
with the hardware handling of the assigned address. The hardware is
expected to
trigger VMEXIT_INVALID if the address of the last byte in the IOPM is
greater
than or equal to the maximum supported physical address, see the APM
volume #2 (40332â??Rev. 4.40â??July 2026).
While at it, clean up the code. Remove the unused bool viopm and the
svm_vcpu::ns_oiomap_pa. Change nsvm_vmrun_permissionmap return error from
literal 1 to NSVM_ERROR_VVMCB.
Signed-off-by: Abdelkareem Abdelsaamad <abdelkareem.abdelsaamad@xxxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
xen/arch/x86/hvm/svm/nestedsvm.c | 18 ++++++++++++++----
xen/arch/x86/include/asm/hvm/svm-types.h | 2 +-
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 0845e9f778..3d0e77f5eb 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -283,7 +283,7 @@ static int nsvm_vcpu_hostrestore(struct vcpu *v, struct
cpu_user_regs *regs)
return 0;
}
-static int nsvm_vmrun_permissionmap(struct vcpu *v, bool viopm)
+static int nsvm_vmrun_permissionmap(struct vcpu *v)
{
struct svm_vcpu *arch_svm = &v->arch.hvm.svm;
struct nestedsvm *svm = &vcpu_nestedsvm(v);
@@ -295,6 +295,17 @@ static int nsvm_vmrun_permissionmap(struct vcpu *v, bool
viopm)
enum hvm_translation_result ret;
unsigned long *ns_viomap;
bool ioport_80 = true, ioport_ed = true;
+ /* IOPM is structured as a linear array of 64K+3 bits. */
+ gfn_t ns_iopm_end =
+ gfn_add(gaddr_to_gfn(ns_vmcb->_iopm_base_pa),
+ PFN_DOWN((0x10000 + 3) / 8));
+
+ if ( !gfn_valid(v->domain, ns_iopm_end) )
+ {
+ gdprintk(XENLOG_ERR, "%s invalid _iopm_base_pa address (%#"PRIx64")\n",
+ __func__, ns_vmcb->_iopm_base_pa);
+ return NSVM_ERROR_VVMCB;
+ }
ns_msrpm_ptr = (unsigned long *)svm->ns_cached_msrpm;
@@ -303,13 +314,12 @@ static int nsvm_vmrun_permissionmap(struct vcpu *v, bool
viopm)
if ( ret != HVMTRANS_okay )
{
gdprintk(XENLOG_ERR, "hvm_copy_from_guest_phys msrpm %u\n", ret);
- return 1;
+ return NSVM_ERROR_VVMCB;
}
/* Check l1 guest io permission map and get a shadow one based on
* if l1 guest intercepts io ports 0x80 and/or 0xED.
*/
- svm->ns_oiomap_pa = svm->ns_iomap_pa;
svm->ns_iomap_pa = ns_vmcb->_iopm_base_pa;
ns_viomap = hvm_map_guest_frame_ro(svm->ns_iomap_pa >> PAGE_SHIFT, 0);
@@ -419,7 +429,7 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct
cpu_user_regs *regs)
n2vmcb->_tsc_offset = n1vmcb->_tsc_offset + ns_vmcb->_tsc_offset;
/* Nested IO permission bitmaps */
- rc = nsvm_vmrun_permissionmap(v, clean.iopm);
+ rc = nsvm_vmrun_permissionmap(v);
if ( rc )
return rc;
diff --git a/xen/arch/x86/include/asm/hvm/svm-types.h
b/xen/arch/x86/include/asm/hvm/svm-types.h
index 8acadb9dcc..beab9a3af2 100644
--- a/xen/arch/x86/include/asm/hvm/svm-types.h
+++ b/xen/arch/x86/include/asm/hvm/svm-types.h
@@ -51,7 +51,7 @@ struct nestedsvm {
unsigned long *ns_merged_msrpm;
/* guest physical address of virtual io permission map */
- paddr_t ns_iomap_pa, ns_oiomap_pa;
+ paddr_t ns_iomap_pa;
/* Shadow io permission map */
unsigned long *ns_iomap;
--
generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |