Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp8153ybp; Thu, 3 Oct 2019 09:26:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0ByqzWjDlw6JAdlMuUwsVgkbZgkqSbLwb1lnnMI85+vdhdOo/SPvs3MlHj4ZNlnFbiqhS X-Received: by 2002:aa7:dd8e:: with SMTP id g14mr10396783edv.233.1570119965101; Thu, 03 Oct 2019 09:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570119965; cv=none; d=google.com; s=arc-20160816; b=mS8q+VY0z3We/URoBXdeXkxlY8OsxLmTjbQ8IeyagOOnXxTP9zXBtyCgKxEGHr0FcZ uVLEHPdEbQc9/CQzu47a4kfonsCDaIOsDYo3E8gY6DCmFoLEE+5FOBW1f/JmMS1qJtN5 JJHS8Ky4jyHVNbXXjKvhm7gXgh/+Vf4FND5jXvqJQtxaEKpc4UWuEMjruDUwBL7RGbHJ bFO6yNBARnozY1KE89n4A0BXNyRHN+BX8e94B4ECF9eVde8MuaprgsZrRi1OZbVLqIb9 MHxOeCaJeH26D65Eqitq7LQqkRAe7GeeiBzy3h5wGeaWMamfhXUxx/K/UM9zwQZR2ZQI oKXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iAJPznvj/VuIHmA2pVLLGnt00Edy4u816F3nFZStzO8=; b=ZmC66vfj+IfEVgftq7+lHU2RxoKGnBiVbEQYPryOH+RdBWz+bz7aEHFuNbLsQFIFHI OyTBHpstECkrGxj/LSsgGfNLBRlfmfSGggZKQY19aUQWZrP4KWAJwmo1McyYGtR2Ri34 MgyxFYpSzC1F6lYAAfP92It/Ld6MPZ6E0MbpGVoIsLK1DOnFWlYAT17Jggy7w9vBImAS WpEzAF3JBaFzLAmxfg/vo3Dvv7ouOPyx63zhtRIvP1UydGbZYMRAeoewy27HoBzhi6/t j0NhG5LjtpCJyg4KZkJ2vT2zgWyI0TH51I5YHnXljx3RVeDmQDKyMuSp0JDa1vXfv6TQ LyJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l8BbQFky; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f57si1747230edb.165.2019.10.03.09.25.39; Thu, 03 Oct 2019 09:26:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l8BbQFky; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390210AbfJCQVw (ORCPT + 99 others); Thu, 3 Oct 2019 12:21:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:50266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388873AbfJCQVt (ORCPT ); Thu, 3 Oct 2019 12:21:49 -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 88F5B21A4C; Thu, 3 Oct 2019 16:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119709; bh=DGlwU+v3u6z+2mLU2WrgF0LQts6QqlPRvvRSOnHMvFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l8BbQFkycujaHUzsRWrvi5t2xBC+Wf2I6qcsis3gOevLNLo3wSLAIWjGrO/ybjilx JuL0kYkMb60OhLIvK6pjBqZ4V9M8FktruoWK2832UAioAq9dY3RivgXhgQlbT0Fl+i tbB1nrHhUsszPXdkP0f2e5Wc4n8fLFviMie5y0lE= 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.19 165/211] KVM: x86: always stop emulation on page fault Date: Thu, 3 Oct 2019 17:53:51 +0200 Message-Id: <20191003154525.515888626@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -6244,8 +6244,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, emulation_type);