Skip to content

Commit 5f0b819

Browse files
committed
KVM: MMU: fix reserved bit check for ept=0/CR0.WP=0/CR4.SMEP=1/EFER.NX=0
KVM has special logic to handle pages with pte.u=1 and pte.w=0 when CR0.WP=1. These pages' SPTEs flip continuously between two states: U=1/W=0 (user and supervisor reads allowed, supervisor writes not allowed) and U=0/W=1 (supervisor reads and writes allowed, user writes not allowed). When SMEP is in effect, however, U=0 will enable kernel execution of this page. To avoid this, KVM also sets NX=1 in the shadow PTE together with U=0, making the two states U=1/W=0/NX=gpte.NX and U=0/W=1/NX=1. When guest EFER has the NX bit cleared, the reserved bit check thinks that the latter state is invalid; teach it that the smep_andnot_wp case will also use the NX bit of SPTEs. Cc: [email protected] Reviewed-by: Xiao Guangrong <[email protected]> Fixes: c258b62 Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 844a5fe commit 5f0b819

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

arch/x86/kvm/mmu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3721,13 +3721,15 @@ static void reset_rsvds_bits_mask_ept(struct kvm_vcpu *vcpu,
37213721
void
37223722
reset_shadow_zero_bits_mask(struct kvm_vcpu *vcpu, struct kvm_mmu *context)
37233723
{
3724+
bool uses_nx = context->nx || context->base_role.smep_andnot_wp;
3725+
37243726
/*
37253727
* Passing "true" to the last argument is okay; it adds a check
37263728
* on bit 8 of the SPTEs which KVM doesn't use anyway.
37273729
*/
37283730
__reset_rsvds_bits_mask(vcpu, &context->shadow_zero_check,
37293731
boot_cpu_data.x86_phys_bits,
3730-
context->shadow_root_level, context->nx,
3732+
context->shadow_root_level, uses_nx,
37313733
guest_cpuid_has_gbpages(vcpu), is_pse(vcpu),
37323734
true);
37333735
}

0 commit comments

Comments
 (0)