x86/nSVM: Ignore bits 11:0 of L1's MSRPM base address
PATCH 1/1 x86/nSVM: Ignore bits 11:0 of L1's MSRPM base address
VMRUN ignores bits 11:0 of MSRPM_BASE_PA (APM volume 2, 24593 Rev. 3.44, section 15.11), but nsvm_vmrun_permissionmap() copies L1's MSR permission map from the address exactly as L1 wrote it. With any of those bits set, the copy starts at the wrong offset, so both the merged map and the intercept check on #VMEXIT use the wrong bits: L1 can miss intercepts it set or see ones it didn't, and the copy may run into the following page, giving a spurious VMEXIT_INVALID if that isn't RAM.
Mask the address before copying.
---
Notes:
To reproduce, in L1: set MSR_PROT, set only FS_BASE's read bit in a page-aligned MSRPM, point MSRPM_BASE_PA at the map + 0x800, and run L2 doing RDMSR of FS_BASE. L1 should get VMEXIT_MSR; without this patch the RDMSR completes in L2 instead.
The IOPM base, handled in the same function, doesn't need the same fix:
all of its users convert it to a frame number first.
xen/arch/x86/hvm/svm/nestedsvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/svm/nestedsvm.c +3 -1
@@ -309,8 +309,10 @@ static int nsvm_vmrun_permissionmap(struct vcpu *v) ns_msrpm_ptr = (unsigned long *)svm->ns_cached_msrpm; +/* VMRUN ignores bits 11:0 of MSRPM_BASE_PA. */ ret =hvm_copy_from_guest_phys (svm->ns_cached_msrpm, - ns_vmcb->_msrpm_base_pa,MSRPM_SIZE ); + ns_vmcb->_msrpm_base_pa &PAGE_MASK , +MSRPM_SIZE );if ( ret != HVMTRANS_okay ) {gdprintk (XENLOG_ERR ,"hvm_copy_from_guest_phys msrpm %u\n" , ret);
base-commit: 4e3c0eeac5761c505f8229e82d265eb29957ca5c
Signature · 1 line
2.49.0
Quoted 44 lines · Stephen Cheng
VMRUN ignores bits 11:0 of
MSRPM_BASE_PA(APM volume 2, 24593 Rev. 3.44, section 15.11), butnsvm_vmrun_permissionmap()copies L1's MSR permission map from the address exactly as L1 wrote it. With any of those bits set, the copy starts at the wrong offset, so both the merged map and the intercept check on #VMEXIT use the wrong bits: L1 can miss intercepts it set or see ones it didn't, and the copy may run into the following page, giving a spuriousVMEXIT_INVALIDif that isn't RAM.Mask the address before copying.
Fixes 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")Assisted-by Claude:claude-opus-5-5Signed-off-by Stephen Cheng <[email protected]>---
Notes:
To reproduce, in L1: setMSR_PROT, set only FS_BASE's read bit in a page-aligned MSRPM, pointMSRPM_BASE_PAat the map +0x800, and run L2 doing RDMSR ofFS_BASE. L1 should getVMEXIT_MSR; without this patch the RDMSR completes in L2 instead.The IOPM base, handled in the same function, doesn't need the same fix:
all of its users convert it to a frame number first.xen/arch/x86/hvm/svm/nestedsvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/nestedsvm.c +3
-1@@ -309,8 +309,10 @@ static int nsvm_vmrun_permissionmap(struct vcpu *v) ns_msrpm_ptr = (unsigned long *)svm->ns_cached_msrpm; +/* VMRUN ignores bits 11:0 of MSRPM_BASE_PA. */ ret =hvm_copy_from_guest_phys (svm->ns_cached_msrpm, - ns_vmcb->_msrpm_base_pa,MSRPM_SIZE ); + ns_vmcb->_msrpm_base_pa &PAGE_MASK , +MSRPM_SIZE );if ( ret != HVMTRANS_okay ) {gdprintk (XENLOG_ERR ,"hvm_copy_from_guest_phys msrpm %u\n" , ret);
Quoted 1 line
base-commit:
4e3c0eeac5761c505f8229e82d265eb29957ca5c
The commit title and message could perhaps be more precise - writing L1's MSR permission map, etc. is vague and could refer to either L0-L1 or L1-L2 (or sometimes even L0-L2) depending on the context.
With that tweaked,
Quoted 2 lines · Stephen Cheng
VMRUN ignores bits 11:0 of
MSRPM_BASE_PA(APM volume 2, 24593 Rev. 3.44, section 15.11),
As before - section titles please alongside (or in place or) section numbers. I'm looking at 3.45, and it is mere luck that section numbers didn't change there. Then, on top of Ross'es R-b:
Jan