KVM: x86: Don't update RIP or do single-step on faulting emulation
Don't advance RIP or inject a single-step #DB if emulation signals a fault. This logic applies to all state updates that are conditional on clean retirement of the emulation instruction, e.g. updating RFLAGS was previously handled by commit38827dbd3f
("KVM: x86: Do not update EFLAGS on faulting emulation"). Not advancing RIP is likely a nop, i.e. ctxt->eip isn't updated with ctxt->_eip until emulation "retires" anyways. Skipping #DB injection fixes a bug reported by Andy Lutomirski where a #UD on SYSCALL due to invalid state with EFLAGS.TF=1 would loop indefinitely due to emulation overwriting the #UD with #DB and thus restarting the bad SYSCALL over and over. Cc: Nadav Amit <nadav.amit@gmail.com> Cc: stable@vger.kernel.org Reported-by: Andy Lutomirski <luto@kernel.org> Fixes:663f4c61b8
("KVM: x86: handle singlestep during emulation") Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
This commit is contained in:

committed by
Radim Krčmář

parent
ea1529873a
commit
75ee23b30d
@@ -6594,12 +6594,13 @@ restart:
|
|||||||
unsigned long rflags = kvm_x86_ops->get_rflags(vcpu);
|
unsigned long rflags = kvm_x86_ops->get_rflags(vcpu);
|
||||||
toggle_interruptibility(vcpu, ctxt->interruptibility);
|
toggle_interruptibility(vcpu, ctxt->interruptibility);
|
||||||
vcpu->arch.emulate_regs_need_sync_to_vcpu = false;
|
vcpu->arch.emulate_regs_need_sync_to_vcpu = false;
|
||||||
|
if (!ctxt->have_exception ||
|
||||||
|
exception_type(ctxt->exception.vector) == EXCPT_TRAP) {
|
||||||
kvm_rip_write(vcpu, ctxt->eip);
|
kvm_rip_write(vcpu, ctxt->eip);
|
||||||
if (r == EMULATE_DONE && ctxt->tf)
|
if (r == EMULATE_DONE && ctxt->tf)
|
||||||
kvm_vcpu_do_singlestep(vcpu, &r);
|
kvm_vcpu_do_singlestep(vcpu, &r);
|
||||||
if (!ctxt->have_exception ||
|
|
||||||
exception_type(ctxt->exception.vector) == EXCPT_TRAP)
|
|
||||||
__kvm_set_rflags(vcpu, ctxt->eflags);
|
__kvm_set_rflags(vcpu, ctxt->eflags);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For STI, interrupts are shadowed; so KVM_REQ_EVENT will
|
* For STI, interrupts are shadowed; so KVM_REQ_EVENT will
|
||||||
|
Reference in New Issue
Block a user