Skip to content

Commit 3e90c27

Browse files
committed
KVM: x86/mmu: Guard against collision with KVM-defined PFERR_IMPLICIT_ACCESS
Add an assertion in kvm_mmu_page_fault() to ensure the error code provided by hardware doesn't conflict with KVM's software-defined IMPLICIT_ACCESS flag. In the unlikely scenario that future hardware starts using bit 48 for a hardware-defined flag, preserving the bit could result in KVM incorrectly interpreting the unknown flag as KVM's IMPLICIT_ACCESS flag. WARN so that any such conflict can be surfaced to KVM developers and resolved, but otherwise ignore the bit as KVM can't possibly rely on a flag it knows nothing about. Fixes: 4f4aa80 ("KVM: X86: Handle implicit supervisor access with SMAP") Acked-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Link: https://lore.kernel.org/r/20230721223711.2334426-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e193149 commit 3e90c27

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5742,6 +5742,17 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err
57425742
int r, emulation_type = EMULTYPE_PF;
57435743
bool direct = vcpu->arch.mmu->root_role.direct;
57445744

5745+
/*
5746+
* IMPLICIT_ACCESS is a KVM-defined flag used to correctly perform SMAP
5747+
* checks when emulating instructions that triggers implicit access.
5748+
* WARN if hardware generates a fault with an error code that collides
5749+
* with the KVM-defined value. Clear the flag and continue on, i.e.
5750+
* don't terminate the VM, as KVM can't possibly be relying on a flag
5751+
* that KVM doesn't know about.
5752+
*/
5753+
if (WARN_ON_ONCE(error_code & PFERR_IMPLICIT_ACCESS))
5754+
error_code &= ~PFERR_IMPLICIT_ACCESS;
5755+
57455756
if (WARN_ON(!VALID_PAGE(vcpu->arch.mmu->root.hpa)))
57465757
return RET_PF_RETRY;
57475758

0 commit comments

Comments
 (0)