All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, Jan Kiszka <jan.kiszka@siemens.com>
Subject: [PATCH kvm-unit-tests 2/2] VMX: Check for validity of vmcs region when calling vmclear/vmptrld
Date: Wed,  4 Jun 2014 17:17:55 -0400	[thread overview]
Message-ID: <1401916675-1568-3-git-send-email-bsd@redhat.com> (raw)
In-Reply-To: <1401916675-1568-1-git-send-email-bsd@redhat.com>

Check if the vmcs pointer is not aligned to page size,
and if bits beyond physical address width are set. Also,
vmclear and vmptrld should fail if the vmxon region is
supplied instead of the vmcs

Signed-off-by: Bandan Das <bsd@redhat.com>
---
 x86/vmx.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 3 deletions(-)

diff --git a/x86/vmx.c b/x86/vmx.c
index 207eb81..64c46aa 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -130,10 +130,43 @@ void print_vmexit_info()
 static void test_vmclear(void)
 {
 	u64 rflags;
+	struct vmcs *tmp_root;
+	int width = cpuid(0x80000008).a & 0xff;
+
+	/*
+	 * Note- The tests below do not necessarily have a
+	 * valid VMCS, but that's ok since the invalid vmcs
+	 * is only used for a specific test and is discarded
+	 * without touching its contents
+	 */
+
+	/* Unaligned page access */
+	tmp_root = (struct vmcs *)((intptr_t)vmcs_root + 1);
+	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
+	write_rflags(rflags);
+	report("test vmclear with unaligned vmcs",
+	       vmcs_clear(tmp_root) == 1);
+
+	/* gpa bits beyond physical address width are set*/
+	tmp_root = (struct vmcs *)((intptr_t)vmcs_root |
+				   ((u64)1 << (width+1)));
+	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
+	write_rflags(rflags);
+	report("test vmclear with vmcs address bits set beyond physical address width",
+	       vmcs_clear(tmp_root) == 1);
 
+	/* Pass VMXON region */
+	tmp_root = (struct vmcs *)vmxon_region;
 	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
 	write_rflags(rflags);
-	report("test vmclear", vmcs_clear(vmcs_root) == 0);
+	report("test vmclear with vmxon region",
+	       vmcs_clear(tmp_root) == 1);
+
+	/* Valid VMCS */
+	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
+	write_rflags(rflags);
+	report("test vmclear with valid vmcs region", vmcs_clear(vmcs_root) == 0);
+
 }
 
 static void test_vmxoff(void)
@@ -651,13 +684,37 @@ out:
 static void test_vmptrld(void)
 {
 	u64 rflags;
-	struct vmcs *vmcs;
+	struct vmcs *vmcs, *tmp_root;
+	int width = cpuid(0x80000008).a & 0xff;
 
 	vmcs = alloc_page();
 	vmcs->revision_id = basic.revision;
+
+	/* Unaligned page access */
+	tmp_root = (struct vmcs *)((intptr_t)vmcs + 1);
+	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
+	write_rflags(rflags);
+	report("test vmptrld with unaligned vmcs",
+	       make_vmcs_current(tmp_root) == 1);
+
+	/* gpa bits beyond physical address width are set*/
+	tmp_root = (struct vmcs *)((intptr_t)vmcs |
+				   ((u64)1 << (width+1)));
+	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
+	write_rflags(rflags);
+	report("test vmptrld with vmcs address bits set beyond physical address width",
+	       make_vmcs_current(tmp_root) == 1);
+
+	/* Pass VMXON region */
+	tmp_root = (struct vmcs *)vmxon_region;
+	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
+	write_rflags(rflags);
+	report("test vmptrld with vmxon region",
+	       make_vmcs_current(tmp_root) == 1);
+
 	rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
 	write_rflags(rflags);
-	report("test vmptrld", make_vmcs_current(vmcs) == 0);
+	report("test vmptrld with valid vmcs", make_vmcs_current(vmcs) == 0);
 }
 
 static void test_vmptrst(void)
-- 
1.8.3.1


      parent reply	other threads:[~2014-06-04 21:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 21:17 [PATCH kvm-unit-tests 0/2] More nvmx unit tests changes Bandan Das
2014-06-04 21:17 ` [PATCH kvm-unit-tests 1/2] VMX: checks for validity of vmxon region Bandan Das
2014-06-05  7:00   ` Jan Kiszka
2014-06-05 10:35     ` Paolo Bonzini
2014-06-04 21:17 ` Bandan Das [this message]

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=1401916675-1568-3-git-send-email-bsd@redhat.com \
    --to=bsd@redhat.com \
    --cc=jan.kiszka@siemens.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.