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

[Xen-changelog] [xen stable-4.7] x86/hvm: Fixes to hvmemul_insn_fetch()



commit 3d63ebca46541cd28c5a31dab42086c370c98d89
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Aug 28 13:00:07 2017 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Aug 28 13:00:07 2017 +0200

    x86/hvm: Fixes to hvmemul_insn_fetch()
    
    Force insn_off to a single byte, as offset can wrap around or truncate with
    respect to sh_ctxt->insn_buf_eip under a number of normal circumstances.
    
    Furthermore, don't use an ASSERT() for bounds checking the write into
    hvmemul_ctxt->insn_buf[].
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    
    x86/hvm: Fix boundary check in hvmemul_insn_fetch()
    
    c/s 0943a03037 added some extra protection for overflowing the emulation
    instruction cache, but Coverity points out that boundary condition is off by
    one when memcpy()'ing out of the buffer.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
    
    x86/HVM: fix boundary check in hvmemul_insn_fetch() (again)
    
    Commit 5a992b670b ("x86/hvm: Fix boundary check in
    hvmemul_insn_fetch()") went a little too far in its correction to
    commit 0943a03037 ("x86/hvm: Fixes to hvmemul_insn_fetch()"): Keep the
    start offset check, but restore the original end offset one.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
    master commit: 0943a03037418e6e40cdd420f2472bbf9afae7a2
    master date: 2017-07-19 10:25:18 +0100
    master commit: 5a992b670bff697c40b513c9e037598ba35ca7d4
    master date: 2017-07-27 11:39:57 +0100
    master commit: 58e8986267d976b00c60e0089baa2e5f66f16d3e
    master date: 2017-08-10 12:37:24 +0200
---
 xen/arch/x86/hvm/emulate.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index 791640b..f6d2e7e 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -828,7 +828,8 @@ static int hvmemul_insn_fetch(
 {
     struct hvm_emulate_ctxt *hvmemul_ctxt =
         container_of(ctxt, struct hvm_emulate_ctxt, ctxt);
-    unsigned int insn_off = offset - hvmemul_ctxt->insn_buf_eip;
+    /* Careful, as offset can wrap or truncate WRT insn_buf_eip. */
+    uint8_t insn_off = offset - hvmemul_ctxt->insn_buf_eip;
 
     /*
      * Fall back if requested bytes are not in the prefetch cache.
@@ -842,7 +843,17 @@ static int hvmemul_insn_fetch(
 
         if ( rc == X86EMUL_OKAY && bytes )
         {
-            ASSERT(insn_off + bytes <= sizeof(hvmemul_ctxt->insn_buf));
+            /*
+             * Will we overflow insn_buf[]?  This shouldn't be able to happen,
+             * which means something went wrong with instruction decoding...
+             */
+            if ( insn_off >= sizeof(hvmemul_ctxt->insn_buf) ||
+                 insn_off + bytes > sizeof(hvmemul_ctxt->insn_buf) )
+            {
+                ASSERT_UNREACHABLE();
+                return X86EMUL_UNHANDLEABLE;
+            }
+
             memcpy(&hvmemul_ctxt->insn_buf[insn_off], p_data, bytes);
             hvmemul_ctxt->insn_buf_bytes = insn_off + bytes;
         }
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.7

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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