Skip to content

Commit

Permalink
KVM: lapic: Check for in-kernel LAPIC before deferencing apic pointer
Browse files Browse the repository at this point in the history
...to avoid dereferencing a null pointer when querying the per-vCPU
timer advance.

Fixes: 39497d7 ("KVM: lapic: Track lapic timer advance per vCPU")
Reported-by: syzbot+f7e65445a40d3e0e4ebf@syzkaller.appspotmail.com
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Apr 30, 2019
1 parent 76d58e0 commit b904cb8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 0 additions & 3 deletions arch/x86/kvm/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,9 +1507,6 @@ void wait_lapic_expire(struct kvm_vcpu *vcpu)
u32 timer_advance_ns = apic->lapic_timer.timer_advance_ns;
u64 guest_tsc, tsc_deadline, ns;

if (!lapic_in_kernel(vcpu))
return;

if (apic->lapic_timer.expired_tscdeadline == 0)
return;

Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -7894,7 +7894,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
}

trace_kvm_entry(vcpu->vcpu_id);
if (vcpu->arch.apic->lapic_timer.timer_advance_ns)
if (lapic_in_kernel(vcpu) &&
vcpu->arch.apic->lapic_timer.timer_advance_ns)
wait_lapic_expire(vcpu);
guest_enter_irqoff();

Expand Down

0 comments on commit b904cb8

Please sign in to comment.