diff options
author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2010-06-30 04:02:02 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-08-01 03:47:22 -0400 |
commit | 36a2e6774bfb5f32a0f23bb155f1f960321f291b (patch) | |
tree | c367ac796b1e33694bcb3bd0e95cbd723667791b | |
parent | f5f48ee15c2ee3e44cf429e34b16c6fa9b900246 (diff) |
KVM: MMU: fix writable sync sp mapping
While we sync many unsync sp at one time(in mmu_sync_children()),
we may mapping the spte writable, it's dangerous, if one unsync
sp's mapping gfn is another unsync page's gfn.
For example:
SP1.pte[0] = P
SP2.gfn's pfn = P
[SP1.pte[0] = SP2.gfn's pfn]
First, we write protected SP1 and SP2, but SP1 and SP2 are still the
unsync sp.
Then, sync SP1 first, it will detect SP1.pte[0].gfn only has one unsync-sp,
that is SP2, so it will mapping it writable, but we plan to sync SP2 soon,
at this point, the SP2->unsync is not reliable since later we sync SP2 but
SP2->gfn is already writable.
So the final result is: SP2 is the sync page but SP2.gfn is writable.
This bug will corrupt guest's page table, fixed by mark read-only mapping
if the mapped gfn has shadow pages.
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r-- | arch/x86/kvm/mmu.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 690a7fc58c17..ca07ed083b59 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -1810,11 +1810,14 @@ static int mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn, | |||
1810 | bool need_unsync = false; | 1810 | bool need_unsync = false; |
1811 | 1811 | ||
1812 | for_each_gfn_indirect_valid_sp(vcpu->kvm, s, gfn, node) { | 1812 | for_each_gfn_indirect_valid_sp(vcpu->kvm, s, gfn, node) { |
1813 | if (!can_unsync) | ||
1814 | return 1; | ||
1815 | |||
1813 | if (s->role.level != PT_PAGE_TABLE_LEVEL) | 1816 | if (s->role.level != PT_PAGE_TABLE_LEVEL) |
1814 | return 1; | 1817 | return 1; |
1815 | 1818 | ||
1816 | if (!need_unsync && !s->unsync) { | 1819 | if (!need_unsync && !s->unsync) { |
1817 | if (!can_unsync || !oos_shadow) | 1820 | if (!oos_shadow) |
1818 | return 1; | 1821 | return 1; |
1819 | need_unsync = true; | 1822 | need_unsync = true; |
1820 | } | 1823 | } |