Skip to content

Commit 75ee23b

Browse files
Sean Christophersonrkrcmar
authored andcommitted
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 commit 38827db ("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 <[email protected]> Cc: [email protected] Reported-by: Andy Lutomirski <[email protected]> Fixes: 663f4c6 ("KVM: x86: handle singlestep during emulation") Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent ea15298 commit 75ee23b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arch/x86/kvm/x86.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6594,12 +6594,13 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
65946594
unsigned long rflags = kvm_x86_ops->get_rflags(vcpu);
65956595
toggle_interruptibility(vcpu, ctxt->interruptibility);
65966596
vcpu->arch.emulate_regs_need_sync_to_vcpu = false;
6597-
kvm_rip_write(vcpu, ctxt->eip);
6598-
if (r == EMULATE_DONE && ctxt->tf)
6599-
kvm_vcpu_do_singlestep(vcpu, &r);
66006597
if (!ctxt->have_exception ||
6601-
exception_type(ctxt->exception.vector) == EXCPT_TRAP)
6598+
exception_type(ctxt->exception.vector) == EXCPT_TRAP) {
6599+
kvm_rip_write(vcpu, ctxt->eip);
6600+
if (r == EMULATE_DONE && ctxt->tf)
6601+
kvm_vcpu_do_singlestep(vcpu, &r);
66026602
__kvm_set_rflags(vcpu, ctxt->eflags);
6603+
}
66036604

66046605
/*
66056606
* For STI, interrupts are shadowed; so KVM_REQ_EVENT will

0 commit comments

Comments
 (0)