KVM: x86: Improve thread safety in pit
authorAndy Honig <ahonig@google.com>
Wed, 27 Aug 2014 21:42:54 +0000 (14:42 -0700)
committerZefan Li <lizefan@huawei.com>
Mon, 2 Feb 2015 09:04:57 +0000 (17:04 +0800)
commit 2febc839133280d5a5e8e1179c94ea674489dae2 upstream.

There's a race condition in the PIT emulation code in KVM.  In
__kvm_migrate_pit_timer the pit_timer object is accessed without
synchronization.  If the race condition occurs at the wrong time this
can crash the host kernel.

This fixes CVE-2014-3611.

Signed-off-by: Andrew Honig <ahonig@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[lizf: Backported to 3.4: adjust context]
Signed-off-by: Zefan Li <lizefan@huawei.com>
arch/x86/kvm/i8254.c

index d68f99df690c72ba81b53f8436c77c2d420d56a5..db336f9f2c8c55f44730f14a5a7500adbe12754d 100644 (file)
@@ -263,8 +263,10 @@ void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
                return;
 
        timer = &pit->pit_state.pit_timer.timer;
+       mutex_lock(&pit->pit_state.lock);
        if (hrtimer_cancel(timer))
                hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
+       mutex_unlock(&pit->pit_state.lock);
 }
 
 static void destroy_pit_timer(struct kvm_pit *pit)