From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98C65C32792 for ; Thu, 3 Oct 2019 17:29:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 66C1620865 for ; Thu, 3 Oct 2019 17:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570123764; bh=3yddxp/vFdZ4ENu0ylnkR9jwYRR7o/rqNiHIgmu0RGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=C+SIglDU6V7GmPHUkoetXOLfsoLhyb03hqERTqF+UFVrIYfk073NaCYPLhLhX/hvU iy7BBZU/aWSqi097KCjS/3RoFJvUMY7NjeyteV0t4O97ExPaNj6qZ/9EWqTxo+/aju OgNFYFlYvP24drJ5SBtaG3OyTdvudlXeRq2Xl/9M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388084AbfJCQMr (ORCPT ); Thu, 3 Oct 2019 12:12:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:35172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388112AbfJCQMr (ORCPT ); Thu, 3 Oct 2019 12:12:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 037E020865; Thu, 3 Oct 2019 16:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119166; bh=3yddxp/vFdZ4ENu0ylnkR9jwYRR7o/rqNiHIgmu0RGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Qmw+8VGSLQTV4hykhSd+JcRsHuOa8hxnI2mhcJGcYovep/CB7iQ35J4NkkY/ZLDf GoKjuA2ro4BSRewHQngbgZvty4hLLf2o3FzfSq1fggL70P8QEOvypted9PW3s1RMLb 3ak1JdhMVlicbS0ex125QfB5YHIpfF6Rj0JQFH+4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Denis Lunev , Roman Kagan , Denis Plotnikov , Jan Dakinevich , Paolo Bonzini Subject: [PATCH 4.14 150/185] KVM: x86: always stop emulation on page fault Date: Thu, 3 Oct 2019 17:53:48 +0200 Message-Id: <20191003154513.292205405@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154437.541662648@linuxfoundation.org> References: <20191003154437.541662648@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jan Dakinevich commit 8530a79c5a9f4e29e6ffb35ec1a79d81f4968ec8 upstream. inject_emulated_exception() returns true if and only if nested page fault happens. However, page fault can come from guest page tables walk, either nested or not nested. In both cases we should stop an attempt to read under RIP and give guest to step over its own page fault handler. This is also visible when an emulated instruction causes a #GP fault and the VMware backdoor is enabled. To handle the VMware backdoor, KVM intercepts #GP faults; with only the next patch applied, x86_emulate_instruction() injects a #GP but returns EMULATE_FAIL instead of EMULATE_DONE. EMULATE_FAIL causes handle_exception_nmi() (or gp_interception() for SVM) to re-inject the original #GP because it thinks emulation failed due to a non-VMware opcode. This patch prevents the issue as x86_emulate_instruction() will return EMULATE_DONE after injecting the #GP. Fixes: 6ea6e84309ca ("KVM: x86: inject exceptions produced by x86_decode_insn") Cc: stable@vger.kernel.org Cc: Denis Lunev Cc: Roman Kagan Cc: Denis Plotnikov Signed-off-by: Jan Dakinevich Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/x86.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5892,8 +5892,10 @@ int x86_emulate_instruction(struct kvm_v if (reexecute_instruction(vcpu, cr2, write_fault_to_spt, emulation_type)) return EMULATE_DONE; - if (ctxt->have_exception && inject_emulated_exception(vcpu)) + if (ctxt->have_exception) { + inject_emulated_exception(vcpu); return EMULATE_DONE; + } if (emulation_type & EMULTYPE_SKIP) return EMULATE_FAIL; return handle_emulation_failure(vcpu);