From patchwork Thu Sep 21 05:12:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petre Ovidiu PIRCALABU X-Patchwork-Id: 9963251 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 7158C6056A for ; Thu, 21 Sep 2017 05:15:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61C7929342 for ; Thu, 21 Sep 2017 05:15:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 562CD2934B; Thu, 21 Sep 2017 05:15:39 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A898629347 for ; Thu, 21 Sep 2017 05:15:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dutmi-00089K-H5; Thu, 21 Sep 2017 05:12:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dutmh-00088b-5d for xen-devel@lists.xen.org; Thu, 21 Sep 2017 05:12:23 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 4D/CA-03423-63A43C95; Thu, 21 Sep 2017 05:12:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRWlGSWpSXmKPExsUSfTyjVdfU63C kwcV2PYslHxezODB6HN39mymAMYo1My8pvyKBNWPN2i/sBa8FKv6uu8ncwHiCt4uRk4NZwFqi 918zYxcjFweLwCwWifcdk1ggnAksEr3fj7ODVAkJuEnc6WgHqxISWMAosbHlAlTCXeLw7ftQi cWMEq/m32QESbAJGEksWfYWrEhEQFri2ufLYEXMAm+YJN59nwlWJCwQLjHryXZmEJtFQFVi7p 4ZbCA2r4CnxJkDG1hAbAkBOYmb5zrBajgFvCROtc1khdjsKXFuwzzmCYxA9zCsYtQoTi0qSy3 SNTLWSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCrWS87P3cQIDC8GINjB+Gd+4CFGSQ4mJVHe APfDkUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeBk9gXKCRanpqRVpmTnAQIdJS3DwKInwJoCke YsLEnOLM9MhUqcYjTlWTbjyh4mj4+bdP0xCLHn5ealS4ry3PYBKBUBKM0rz4AbBIvASo6yUMC 8j0GlCPAWpRbmZJajyrxjFORiVhHkzQBbyZOaVwO17BXQKE9Ap2RsOgJxSkoiQkmpgNGdZ9uU uj8Uko6vz3X5+lJT5sqSJNypnr+37X5WbTrNpdEtHqJofTWsX051if2H3lLd33mf8CTBRiXTL +Kxo4BpkeXJz6+55Oa3Oa9PTju1R+WO9uY3z0sOIRf8F5z//mN3eXvE8K+nCjy0ZTk8fbNeOW nB73Q4fleJ5ogzng2/HiuucfKC9VImlOCPRUIu5qDgRABJPqeK7AgAA X-Env-Sender: ppircalabu@bitdefender.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1505970741!83761475!1 X-Originating-IP: [91.199.104.133] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45881 invoked from network); 21 Sep 2017 05:12:21 -0000 Received: from mx02.bbu.dsd.mx.bitdefender.com (HELO mx02.buh.bitdefender.com) (91.199.104.133) by server-8.tower-21.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 21 Sep 2017 05:12:21 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=MYH2LS4Vv1Yxvxkekr7snaUPh6bqfLiYk2T2O4dke55l1a0DjYDS2ph4gXWn1Q4GZvJSFxXyOzlOnkPWoSFcaIgXosLZ7l9EVOplCtkajFDZtMZ/sBZG2cHTqYYWbxXD9h8sFdwICc8WM/NiHx8yv5lPY8XdF78hD9Nl9rJLnQuHeBqEAbhLhPTTOriWEzusTnprKx77GSEko/50kC8S1xeIXmligsO0KwQobtl+VAEBqwFqusQtUD+vwj+GD3LjsAy5+goePxmYeLE1GUbqod+4x+hpYLBToXOp8Z1Qv0wqiUU5WV8QlU6Ik0DgLhDegEzJez/X+cLAqFvieCkpng==; h=Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id:in-reply-to:references; s=default; bh=vlgJ9RkI2ysIQh5xDbPTKmiU5F0=; b=N+F6E9r8iAfhAFljjonqEJTVyADS 7/NxJGEc0qavBEchdiKwzUYdxcTTsWoShNW58tupwg+DN+j2YoVMslOk6jwewpGR bRc3nZhWsyOz7SoDSO5SVkisMx5mMzs3G445bG/l2x8KFInTAQa7/XNQI8wPr/g2 d04XFPY29hjkvGsBT+NhSBtBCZel19MZpgeFVAdzuiRN2UHWCER6nqPEFpMYHRvy Mj+UU4j/kNBHhftv9RgFZK01yPnpGIfODtQY+83qQ5a+YdP3ieA25wAVNZSE+OwO FiDNxMtH1nNmPq032SaTzvT4hIBHZNiIFEPnFl8vdqAvmTutWXCNZXyRrA== Received: (qmail 911 invoked from network); 21 Sep 2017 08:12:07 +0300 Received: from mx01robo.bbu.dsd.mx.bitdefender.com (10.17.80.60) by mx02.buh.bitdefender.com with AES128-GCM-SHA256 encrypted SMTP; 21 Sep 2017 08:12:07 +0300 Received: (qmail 9218 invoked from network); 21 Sep 2017 08:12:07 +0300 Received: from unknown (HELO pepi-OptiPlex-9020.bbu.bitdefender.biz) (10.10.194.146) by mx01robo.bbu.dsd.mx.bitdefender.com with SMTP; 21 Sep 2017 08:12:07 +0300 From: Petre Pircalabu To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 08:12:06 +0300 Message-Id: <1505970726-5671-5-git-send-email-ppircalabu@bitdefender.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505970726-5671-1-git-send-email-ppircalabu@bitdefender.com> References: <1505970726-5671-1-git-send-email-ppircalabu@bitdefender.com> Cc: Petre Pircalabu , kevin.tian@intel.com, sstabellini@kernel.org, wei.liu2@citrix.com, jun.nakajima@intel.com, rcojocaru@bitdefender.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, tim@xen.org, paul.durrant@citrix.com, tamas@tklengyel.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v12 4/4] x86emul: Raise #UD when emulating an unrecognized instruction. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Modified the behavior of hvm_emulate_one_insn and vmx_realmode_emulate_one to generate an Invalid Opcode trap when X86EMUL_UNRECOGNIZED is returned by the emulator instead of just crashing the domain. Signed-off-by: Petre Pircalabu Reviewed-by: Kevin Tian --- xen/arch/x86/hvm/io.c | 6 +++++- xen/arch/x86/hvm/vmx/realmode.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c index 7152c28..c7b1c53 100644 --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -96,10 +96,14 @@ bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *descr) switch ( rc ) { case X86EMUL_UNHANDLEABLE: - case X86EMUL_UNIMPLEMENTED: hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc); return false; + case X86EMUL_UNRECOGNIZED: + hvm_dump_emulation_state(XENLOG_G_WARNING, descr, &ctxt, rc); + hvm_inject_hw_exception(TRAP_invalid_op, X86_EVENT_NO_EC); + break; + case X86EMUL_EXCEPTION: hvm_inject_event(&ctxt.ctxt.event); break; diff --git a/xen/arch/x86/hvm/vmx/realmode.c b/xen/arch/x86/hvm/vmx/realmode.c index b93792d..03dea6c 100644 --- a/xen/arch/x86/hvm/vmx/realmode.c +++ b/xen/arch/x86/hvm/vmx/realmode.c @@ -106,12 +106,21 @@ void vmx_realmode_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt) if ( hvm_vcpu_io_need_completion(vio) || vio->mmio_retry ) vio->io_completion = HVMIO_realmode_completion; - if ( rc == X86EMUL_UNHANDLEABLE || rc == X86EMUL_UNIMPLEMENTED ) + if ( rc == X86EMUL_UNHANDLEABLE ) { gdprintk(XENLOG_ERR, "Failed to emulate insn.\n"); goto fail; } + if ( rc == X86EMUL_UNRECOGNIZED ) + { + gdprintk(XENLOG_ERR, "Unrecognized insn.\n"); + if ( curr->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PE ) + goto fail; + + realmode_deliver_exception(TRAP_invalid_op, 0, hvmemul_ctxt); + } + if ( rc == X86EMUL_EXCEPTION ) { if ( unlikely(curr->domain->debugger_attached) &&