KVM: x86: fix fixing of hypercalls
PATCH 1/1 KVM: x86: fix fixing of hypercalls
emulator_fix_hypercall() replaces hypercall with vmcall instruction, but it does not handle GP exception properly when writes the new instruction. It can return X86EMUL_PROPAGATE_FAULT without setting exception information. This leads to incorrect emulation and triggers WARN_ON(ctxt->exception.vector > 0x1f) in x86_emulate_insn()
as discovered by syzkaller fuzzer:
WARNING: CPU: 2 PID: 18646 at arch/x86/kvm/emulate.c:5558 Call Trace: warn_slowpath_null+0x2c/0x40 kernel/panic.c:582 x86_emulate_insn+0x16a5/0x4090 arch/x86/kvm/emulate.c:5572 x86_emulate_instruction+0x403/0x1cc0 arch/x86/kvm/x86.c:5618 emulate_instruction arch/x86/include/asm/kvm_host.h:1127 [inline] handle_exception+0x594/0xfd0 arch/x86/kvm/vmx.c:5762 vmx_handle_exit+0x2b7/0x38b0 arch/x86/kvm/vmx.c:8625 vcpu_enter_guest arch/x86/kvm/x86.c:6888 [inline] vcpu_run arch/x86/kvm/x86.c:6947 [inline]
Set exception information when write in emulator_fix_hypercall() fails.
--- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +2 -1
@@ -6171,7 +6171,8 @@ static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt) kvm_x86_ops->patch_hypercall (vcpu, instruction); -return emulator_write_emulated (ctxt, rip, instruction,3 ,NULL ); +return emulator_write_emulated (ctxt, rip, instruction,3 , + &ctxt->exception); }static int dm_request_for_irq_injection (struct kvm_vcpu *vcpu)
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Radim Krčmář
Applied2017-01-17 14:51+0100, Dmitry Vyukov:
Quoted 20 lines
emulator_fix_hypercall()replaces hypercall with vmcall instruction, but it does not handle GP exception properly when writes the new instruction. It can returnX86EMUL_PROPAGATE_FAULTwithout setting exception information. This leads to incorrect emulation and triggersWARN_ON(ctxt->exception.vector > 0x1f)inx86_emulate_insn()
as discovered by syzkaller fuzzer:WARNING: CPU: 2 PID: 18646 at arch/x86/kvm/emulate.c:5558 Call Trace: warn_slowpath_null+0x2c/0x40 kernel/panic.c:582 x86_emulate_insn+0x16a5/0x4090 arch/x86/kvm/emulate.c:5572 x86_emulate_instruction+0x403/0x1cc0 arch/x86/kvm/x86.c:5618 emulate_instruction arch/x86/include/asm/kvm_host.h:1127 [inline] handle_exception+0x594/0xfd0 arch/x86/kvm/vmx.c:5762 vmx_handle_exit+0x2b7/0x38b0 arch/x86/kvm/vmx.c:8625 vcpu_enter_guest arch/x86/kvm/x86.c:6888 [inline] vcpu_run arch/x86/kvm/x86.c:6947 [inline]Set exception information when write in
emulator_fix_hypercall()fails.
Quoted 7 lines
Signed-off-by Dmitry Vyukov <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Cc Wanpeng Li <[email protected]>---
Applied to kvm/master, thanks.