x86/emul: Correct the return value handling of VMFUNC
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 9 Dec 2016 18:40:11 +0000 (18:40 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 22 Dec 2016 13:32:46 +0000 (13:32 +0000)
The bracketing of x86_emulate() calling the ops->vmfunc() hook is wrong with
respect to the assignment to rc, which can trip the new assertions in
x86_emulate_wrapper().

The hvmemul_vmfunc() hook should only raise #UD if X86EMUL_EXCEPTION is
returned.  This is only a latent bug at the moment.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/emulate.c
xen/arch/x86/x86_emulate/x86_emulate.c

index 24754d3a8e80829a8c74dc6a6e7fd9953e4fd883..aa1b7162dfd93364b2a55d760e0c5ce33957b0a0 100644 (file)
@@ -1653,7 +1653,7 @@ static int hvmemul_vmfunc(
     if ( !hvm_funcs.altp2m_vcpu_emulate_vmfunc )
         return X86EMUL_UNHANDLEABLE;
     rc = hvm_funcs.altp2m_vcpu_emulate_vmfunc(ctxt->regs);
-    if ( rc != X86EMUL_OKAY )
+    if ( rc == X86EMUL_EXCEPTION )
         x86_emul_hw_exception(TRAP_invalid_op, X86_EVENT_NO_EC, ctxt);
 
     return rc;
index b6d73588a00e8b8bd26444784cf159eea37b647f..3076c0c49363ebc4df808dd585b4e9868ca3ff39 100644 (file)
@@ -4463,7 +4463,7 @@ x86_emulate(
             generate_exception_if(lock_prefix | rep_prefix() | (vex.pfx == vex_66),
                                   EXC_UD);
             fail_if(!ops->vmfunc);
-            if ( (rc = ops->vmfunc(ctxt) != X86EMUL_OKAY) )
+            if ( (rc = ops->vmfunc(ctxt)) != X86EMUL_OKAY )
                 goto done;
             goto no_writeback;