From: Avi Kivity Date: Tue, 4 May 2010 12:00:37 +0000 (+0300) Subject: KVM: Fix wallclock version writing race X-Git-Tag: v2.6.34.1~7 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=0119618803088bf8be6f287fc0e160e4a08fbfa6;p=karo-tx-linux.git KVM: Fix wallclock version writing race Wallclock writing uses an unprotected global variable to hold the version; this can cause one guest to interfere with another if both write their wallclock at the same time. Acked-by: Glauber Costa Signed-off-by: Avi Kivity Signed-off-by: Greg Kroah-Hartman (Cherry-picked from commit 9ed3c444ab8987c7b219173a2f7807e3f71e234e) --- diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b5c4393385a7..ead3ea4070bf 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -695,14 +695,22 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data) static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) { - static int version; + int version; + int r; struct pvclock_wall_clock wc; struct timespec boot; if (!wall_clock) return; - version++; + r = kvm_read_guest(kvm, wall_clock, &version, sizeof(version)); + if (r) + return; + + if (version & 1) + ++version; /* first time write, random junk */ + + ++version; kvm_write_guest(kvm, wall_clock, &version, sizeof(version));