All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: David Hildenbrand <david@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org
Cc: Jim Mattson <jmattson@google.com>
Subject: [PATCH v2] kvm: nVMX: Check memory operand to INVVPID
Date: Wed, 28 Jun 2017 09:37:37 -0700	[thread overview]
Message-ID: <20170628163737.111865-1-jmattson@google.com> (raw)
In-Reply-To: <e383bf64-7e84-44a0-2496-722011de77f6@redhat.com>

The memory operand fetched for INVVPID is 128 bits. Bits 63:16 are
reserved and must be zero.  Otherwise, the instruction fails with
VMfail(Invalid operand to INVEPT/INVVPID).  If the INVVPID_TYPE is 0
(individual address invalidation), then bits 127:64 must be in
canonical form, or the instruction fails with VMfail(Invalid operand
to INVEPT/INVVPID).

Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/vmx.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 42db3eb2d13b..3c80a2fec5c6 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -7651,7 +7651,10 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
 	unsigned long type, types;
 	gva_t gva;
 	struct x86_exception e;
-	int vpid;
+	struct {
+		u64 vpid;
+		u64 gla;
+	} operand;
 
 	if (!(vmx->nested.nested_vmx_secondary_ctls_high &
 	      SECONDARY_EXEC_ENABLE_VPID) ||
@@ -7681,17 +7684,28 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
 	if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
 			vmx_instruction_info, false, &gva))
 		return 1;
-	if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &vpid,
-				sizeof(u32), &e)) {
+	if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &operand,
+				sizeof(operand), &e)) {
 		kvm_inject_page_fault(vcpu, &e);
 		return 1;
 	}
+	if (operand.vpid >> 16) {
+		nested_vmx_failValid(vcpu,
+			VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
+		return kvm_skip_emulated_instruction(vcpu);
+	}
 
 	switch (type) {
 	case VMX_VPID_EXTENT_INDIVIDUAL_ADDR:
+		if (is_noncanonical_address(operand.gla)) {
+			nested_vmx_failValid(vcpu,
+				VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
+			return kvm_skip_emulated_instruction(vcpu);
+		}
+		/* fall through */
 	case VMX_VPID_EXTENT_SINGLE_CONTEXT:
 	case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL:
-		if (!vpid) {
+		if (!operand.vpid) {
 			nested_vmx_failValid(vcpu,
 				VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID);
 			return kvm_skip_emulated_instruction(vcpu);
-- 
2.13.2.725.g09c95d1e9-goog

  reply	other threads:[~2017-06-28 16:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 17:59 [PATCH] kvm: nVMX: Check memory operand to INVVPID Jim Mattson
2017-06-28  8:48 ` David Hildenbrand
2017-06-28 12:12 ` Paolo Bonzini
2017-06-28 16:37   ` Jim Mattson [this message]
2017-06-28 16:43     ` [PATCH v2] " Paolo Bonzini
     [not found]       ` <CALMp9eS7QGxZL-G_AFon03bodRB4dz22kG2fj5-fPDradtgESQ@mail.gmail.com>
2017-06-29  8:22         ` Paolo Bonzini
2017-06-29 17:52           ` [kvm-unit-tests PATCH 1/2] Move vmx_{on,off} into vmx.h Jim Mattson
2017-06-29 17:52             ` [kvm-unit-tests PATCH 2/2] Add basic invvpid test Jim Mattson
2017-06-29 18:46             ` [kvm-unit-tests PATCH v2 1/4] Save/restore handler in test_for_exception Jim Mattson
2017-06-29 18:46               ` [kvm-unit-tests PATCH v2 2/4] Specify %cs for exception_handler iret Jim Mattson
2017-06-29 18:46               ` [kvm-unit-tests PATCH v2 3/4] Move vmx_{on,off} into vmx.h Jim Mattson
2017-06-29 18:46               ` [kvm-unit-tests PATCH v2 4/4] Add basic invvpid test Jim Mattson
2017-06-30 10:21               ` [kvm-unit-tests PATCH v2 1/4] Save/restore handler in test_for_exception Paolo Bonzini
2017-06-29 18:14           ` [PATCH v2] kvm: nVMX: Check memory operand to INVVPID David Matlack
2017-06-30 21:55             ` Peter Feiner
2017-06-28 17:00     ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170628163737.111865-1-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.