]> git.hungrycats.org Git - linux/commitdiff
KVM: MMU: Segregate shadow pages with different cr0.wp
authorAvi Kivity <avi@redhat.com>
Wed, 12 May 2010 08:48:18 +0000 (11:48 +0300)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 5 Jul 2010 18:16:14 +0000 (11:16 -0700)
When cr0.wp=0, we may shadow a gpte having u/s=1 and r/w=0 with an spte
having u/s=0 and r/w=1.  This allows excessive access if the guest sets
cr0.wp=1 and accesses through this spte.

Fix by making cr0.wp part of the base role; we'll have different sptes for
the two cases and the problem disappears.

Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
(cherry picked from commit 3dbe141595faa48a067add3e47bba3205b79d33c)

arch/x86/include/asm/kvm_host.h
arch/x86/kvm/mmu.c

index ca9e97f51b442bd0c70c056a60309df57868a0ea..e62b4b9696a4880a8e8a87b72496d1dc2daa0fff 100644 (file)
@@ -193,6 +193,7 @@ union kvm_mmu_page_role {
                unsigned invalid:1;
                unsigned cr4_pge:1;
                unsigned nxe:1;
+               unsigned cr0_wp:1;
        };
 };
 
index 28c3d814c092ea80c726a3a42cce3c7b0577098f..db2611b904ba247fe0a1e9e236a971958faaf62a 100644 (file)
@@ -227,7 +227,7 @@ void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
 }
 EXPORT_SYMBOL_GPL(kvm_mmu_set_mask_ptes);
 
-static int is_write_protection(struct kvm_vcpu *vcpu)
+static bool is_write_protection(struct kvm_vcpu *vcpu)
 {
        return vcpu->arch.cr0 & X86_CR0_WP;
 }
@@ -2448,6 +2448,7 @@ static int init_kvm_softmmu(struct kvm_vcpu *vcpu)
                r = paging32_init_context(vcpu);
 
        vcpu->arch.mmu.base_role.glevels = vcpu->arch.mmu.root_level;
+       vcpu->arch.mmu.base_role.cr0_wp = is_write_protection(vcpu);
 
        return r;
 }