diff options
author | Avi Kivity <avi@redhat.com> | 2010-05-04 15:00:37 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-07-05 11:11:19 -0700 |
commit | 0890bb8d955da47bd51bc823f5080ec0c2664b3f (patch) | |
tree | 17751d8a5e1418ef8e560168b321617eb0354e1b | |
parent | 4a277f9cb862ad44d3a83bfcc0cf42727de99ac3 (diff) | |
download | lwn-0890bb8d955da47bd51bc823f5080ec0c2664b3f.tar.gz lwn-0890bb8d955da47bd51bc823f5080ec0c2664b3f.zip |
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 <glommer@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
(cherry picked from commit 9ed3c444ab8987c7b219173a2f7807e3f71e234e)
-rw-r--r-- | arch/x86/kvm/x86.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3f83a30d1802..802c7bd2cef2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -554,14 +554,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)); |