linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/11] KVM: MMU: fix writable sync sp mapping
@ 2010-06-30  8:02 Xiao Guangrong
  2010-06-30  8:02 ` [PATCH v3 2/11] KVM: MMU: fix conflict access permissions in direct sp Xiao Guangrong
                   ` (9 more replies)
  0 siblings, 10 replies; 21+ messages in thread
From: Xiao Guangrong @ 2010-06-30  8:02 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Marcelo Tosatti, LKML, KVM list

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>
---
 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 045a0f9..24290f8 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,
 	bool need_unsync = false;
 
 	for_each_gfn_indirect_valid_sp(vcpu->kvm, s, gfn, node) {
+		if (!can_unsync)
+			return 1;
+
 		if (s->role.level != PT_PAGE_TABLE_LEVEL)
 			return 1;
 
 		if (!need_unsync && !s->unsync) {
-			if (!can_unsync || !oos_shadow)
+			if (!oos_shadow)
 				return 1;
 			need_unsync = true;
 		}
-- 
1.6.1.2


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2010-07-01 12:27 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-30  8:02 [PATCH v3 1/11] KVM: MMU: fix writable sync sp mapping Xiao Guangrong
2010-06-30  8:02 ` [PATCH v3 2/11] KVM: MMU: fix conflict access permissions in direct sp Xiao Guangrong
2010-06-30  8:03 ` [PATCH v3 3/11] KVM: MMU: fix direct sp's access corruptted Xiao Guangrong
2010-06-30 19:39   ` Marcelo Tosatti
2010-07-01  0:50     ` Xiao Guangrong
2010-07-01 12:03       ` Marcelo Tosatti
2010-06-30  8:04 ` [PATCH v3 4/11] KVM: MMU: fix forgot to flush all vcpu's tlb Xiao Guangrong
2010-06-30  8:05 ` [PATCH v3 5/11] KVM: MMU: cleanup FNAME(fetch)() functions Xiao Guangrong
2010-07-01 12:05   ` Marcelo Tosatti
2010-06-30  8:05 ` [PATCH v3 6/11] KVM: MMU: introduce gfn_to_pfn_atomic() function Xiao Guangrong
2010-06-30  8:06 ` [PATCH v3 7/11] KVM: MMU: introduce gfn_to_hva_many() function Xiao Guangrong
2010-06-30  8:07 ` [PATCH v3 8/11] KVM: MMU: introduce pte_prefetch_topup_memory_cache() Xiao Guangrong
2010-06-30  8:08 ` [PATCH v3 9/11] KVM: MMU: prefetch ptes when intercepted guest #PF Xiao Guangrong
2010-06-30 20:43   ` Marcelo Tosatti
2010-07-01  1:11     ` Xiao Guangrong
2010-07-01 12:07       ` Marcelo Tosatti
2010-07-01 12:11       ` Avi Kivity
2010-07-01 12:13         ` Xiao Guangrong
2010-07-01 12:26           ` Marcelo Tosatti
2010-06-30  8:08 ` [PATCH 10/11] KVM: MMU: combine guest pte read between walk and pte prefetch Xiao Guangrong
2010-06-30  8:09 ` [PATCH v3 11/11] KVM: MMU: trace " Xiao Guangrong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).