From patchwork Tue Jan 17 13:51:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Vyukov X-Patchwork-Id: 9521019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 065D6601C3 for ; Tue, 17 Jan 2017 13:51:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAE1728563 for ; Tue, 17 Jan 2017 13:51:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDE1D28565; Tue, 17 Jan 2017 13:51:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36ADC28563 for ; Tue, 17 Jan 2017 13:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751151AbdAQNvN (ORCPT ); Tue, 17 Jan 2017 08:51:13 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38024 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750939AbdAQNvM (ORCPT ); Tue, 17 Jan 2017 08:51:12 -0500 Received: by mail-wm0-f47.google.com with SMTP id r144so223314822wme.1 for ; Tue, 17 Jan 2017 05:51:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=naCWJZa1L36ptodgQk6AD6sZXFVrfjxOk4Xf4JCxSJs=; b=aQgHq3iG0wC/SuBBDe/46asAvUvWy/ZxHfsVj4HlrdPYGdf9aosCWDrxOZcMlDdHIe 8iaOwO7fWDKMI/HJZqbXOKWdBKLSiRovpXCmD2tXjdnAwuxWwho4rQ/isC48sSmvdpM9 d3P7pIMbXPhg1pUKcpwxFh1MXAWGtFPFTGEWHaRfW2rF/tRbFKDhNHu9v3chJf1bHcbI UZBf9UhkBBDl8dAoyUpC3NFv0lDgl/vxd1z7Q10DBtfe0pmmw5/RbCVAF4Gu929HSwgy MJiVtBo4jD20BGipV494a9pmqJGfyi2RtCcew8vQwhQuz4hLL21OA2LxaqjDgzAAk1bY NYjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=naCWJZa1L36ptodgQk6AD6sZXFVrfjxOk4Xf4JCxSJs=; b=cZm3n/5OwMjWhtspRWE2qhe0f8CTSdLVaRCkuvkLhDQMC7uN6Qnng3waZTg8UeY5Lb jMHdALHrtFRj3hOj0iXAK2mtNpmJvYzI2gemMU4bVyw++sWD4H0svYteotOCspL37jeg Io+kgsRlZUtdQ+yv3J4Urf7Cilj4jaFZCdrehhvPaeeE3yxXCA+kVwL/2QZUJ8xIHDs4 rpP2RYfA8Y8Sf579ZZ89XqIt4PfcD2BRzYKvSGdQTF2H/LJW4ct4Ij9q2AyqLjl9A+S7 VEL82FHUmprWox1Zj6kT0yQd3G1+PAmrvwzUdTXH8kjsNbqixxPAxOZEnkBrCxmdPQTw 7kyA== X-Gm-Message-State: AIkVDXKoqNUm/mHIZrc0wVCVgXBbPe/DkkbthH60qoHy4BpBN9Xy8CkHIUoH/uGWrshtjT7j X-Received: by 10.223.134.173 with SMTP id 42mr31131513wrx.95.1484661070464; Tue, 17 Jan 2017 05:51:10 -0800 (PST) Received: from dvyukov-z840.muc.corp.google.com ([100.105.28.62]) by smtp.gmail.com with ESMTPSA id k11sm37136325wmb.18.2017.01.17.05.51.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 05:51:09 -0800 (PST) Received: by dvyukov-z840.muc.corp.google.com (Postfix, from userid 129372) id 7E638E1244; Tue, 17 Jan 2017 14:51:06 +0100 (CET) From: Dmitry Vyukov To: pbonzini@redhat.com, rkrcmar@redhat.com Cc: Dmitry Vyukov , Wanpeng Li , kvm@vger.kernel.org, syzkaller@googlegroups.com Subject: [PATCH] KVM: x86: fix fixing of hypercalls Date: Tue, 17 Jan 2017 14:51:04 +0100 Message-Id: <20170117135104.145739-1-dvyukov@google.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Dmitry Vyukov Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Wanpeng Li Cc: kvm@vger.kernel.org Cc: syzkaller@googlegroups.com --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 57d8a856cdc5..d153be8929a6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -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)