Re: [PATCH] KVM: Fix wallclock version writing race

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/04/2010 03:02 PM, Avi Kivity wrote:
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.

Signed-off-by: Avi Kivity<avi@xxxxxxxxxx>

This was pointed out by Naphtali.

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f6f8dad..c3152d7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -754,14 +754,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));



--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux