[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/3] x86/hvm: implement hvm_get_insn_length()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Mihai DonÈu <mdontu@xxxxxxxxxxxxxxx>
  • Date: Tue, 9 Sep 2014 05:29:52 +0300
  • Cc: Mihai DonÈu <mdontu@xxxxxxxxxxxxxxx>, keir@xxxxxxx, jbeulich@xxxxxxxx
  • Comment: DomainKeys? See http://domainkeys.sourceforge.net/
  • Delivery-date: Tue, 09 Sep 2014 02:30:16 +0000
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=R0Qb461IwAsmyK7GGTV0RlZ0E8n/HVmn/TwKwjRcN9LSJNxRQh5nOKW9OrIZzTcO6pEJS898hpmEGSMe6NCe6m/ib0jJMdaqz0+3wCINyv9Eg1vA5NhBHn3JNVxKxDvpL82fge1bjUMBzpzDwoExlb1v0HzCg47cbFstVhw8M0O/S8QswGN58GiUwExCXLVEW4cbD9ajCFgby2V+CKHpqvIypbmcrGPWLiCJoy4rKQzTnaR7LNCxnZI7/fsqIUVANUJGTI+KQIiBtbbzI1iZqefwme5F8350lJgdhVTNI28LYv7VA4RkptVzdvpOLKN8D1sMMQDM3d4REMA6s40Osw==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:X-BitDefender-Scanner:X-BitDefender-Spam:X-BitDefender-SpamStamp:X-BitDefender-CF-Stamp;
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

Add a helper function that can be used to compute the length of the current
instruction (the one that generated a VMEXIT). This can be called by memory
introspection technologies to jump over instructions that were classified
as malicious.

Signed-off-by: Mihai DonÈu <mdontu@xxxxxxxxxxxxxxx>
---
 xen/arch/x86/hvm/emulate.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 6ab06e0..8f5357d 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -21,6 +21,7 @@
 #include <asm/hvm/hvm.h>
 #include <asm/hvm/trace.h>
 #include <asm/hvm/support.h>
+#include <asm/insn.h>
 
 static void hvmtrace_io_assist(int is_mmio, ioreq_t *p)
 {
@@ -1410,6 +1411,50 @@ void hvm_mem_event_emulate_one(bool_t nowrite, unsigned 
int trapnr,
     hvm_emulate_writeback(&ctx);
 }
 
+int hvm_get_insn_length(
+    struct hvm_emulate_ctxt *hvmemul_ctxt)
+{
+    struct cpu_user_regs *regs = hvmemul_ctxt->ctxt.regs;
+    struct vcpu *curr = current;
+    uint32_t pfec = PFEC_page_present;
+    unsigned long addr;
+    struct insn insn;
+
+    if ( hvm_long_mode_enabled(curr) &&
+         hvmemul_ctxt->seg_reg[x86_seg_cs].attr.fields.l )
+        hvmemul_ctxt->ctxt.addr_size = hvmemul_ctxt->ctxt.sp_size = 64;
+    else
+    {
+        hvmemul_ctxt->ctxt.addr_size =
+            hvmemul_ctxt->seg_reg[x86_seg_cs].attr.fields.db ? 32 : 16;
+        hvmemul_ctxt->ctxt.sp_size =
+            hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.db ? 32 : 16;
+    }
+
+    if ( hvmemul_ctxt->seg_reg[x86_seg_ss].attr.fields.dpl == 3 )
+        pfec |= PFEC_user_mode;
+
+    hvmemul_ctxt->insn_buf_eip = regs->eip;
+    hvmemul_ctxt->insn_buf_bytes =
+        hvm_get_insn_bytes(curr, hvmemul_ctxt->insn_buf)
+        ? :
+        (hvm_virtual_to_linear_addr(
+            x86_seg_cs, &hvmemul_ctxt->seg_reg[x86_seg_cs],
+            regs->eip, sizeof(hvmemul_ctxt->insn_buf),
+            hvm_access_insn_fetch, hvmemul_ctxt->ctxt.addr_size, &addr) &&
+        !hvm_fetch_from_guest_virt_nofault(
+            hvmemul_ctxt->insn_buf, addr,
+            sizeof(hvmemul_ctxt->insn_buf), pfec))
+    ? sizeof(hvmemul_ctxt->insn_buf) : 0;
+
+    hvmemul_ctxt->exn_pending = 0;
+
+    insn_init(&insn, hvmemul_ctxt->insn_buf, hvm_long_mode_enabled(curr));
+    insn_get_length(&insn);
+
+    return insn.length;
+}
+
 void hvm_emulate_prepare(
     struct hvm_emulate_ctxt *hvmemul_ctxt,
     struct cpu_user_regs *regs)
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.