x86/HVM: XSETBV intercept needs to check CPL on SVM only
authorJan Beulich <jbeulich@suse.com>
Wed, 2 Dec 2015 14:21:15 +0000 (15:21 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 2 Dec 2015 14:21:15 +0000 (15:21 +0100)
VMX doesn't need a software CPL check on the XSETBV intercept, and
SVM can do that check without resorting to hvm_get_segment_register().

Clean up what is left of hvm_handle_xsetbv(), namely make it return a
proper error code.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/svm/svm.c

index db0aebaa50b4dc3af0affeb9cf6e1f473bc47579..af3d4d77fea0d9118391efab421f7f2ced68a372 100644 (file)
@@ -3153,22 +3153,15 @@ out:
 
 int hvm_handle_xsetbv(u32 index, u64 new_bv)
 {
-    struct segment_register sreg;
-    struct vcpu *curr = current;
-
-    hvm_get_segment_register(curr, x86_seg_ss, &sreg);
-    if ( sreg.attr.fields.dpl != 0 )
-        goto err;
+    int rc;
 
-    hvm_event_crX(XCR0, new_bv, curr->arch.xcr0);
+    hvm_event_crX(XCR0, new_bv, current->arch.xcr0);
 
-    if ( handle_xsetbv(index, new_bv) )
-        goto err;
+    rc = handle_xsetbv(index, new_bv);
+    if ( rc )
+        hvm_inject_hw_exception(TRAP_gp_fault, 0);
 
-    return 0;
-err:
-    hvm_inject_hw_exception(TRAP_gp_fault, 0);
-    return -1;
+    return rc;
 }
 
 int hvm_set_efer(uint64_t value)
index 200a5df9d05b190e60376ebdfc22bbc9575e720e..9415fb139fb3152b86281f1b21f6779edd45b67e 100644 (file)
@@ -2612,10 +2612,11 @@ void svm_vmexit_handler(struct cpu_user_regs *regs)
         break;
 
     case VMEXIT_XSETBV:
-        if ( (inst_len = __get_instruction_length(current, INSTR_XSETBV))==0 )
-            break;
-        if ( hvm_handle_xsetbv(regs->ecx,
-                               (regs->rdx << 32) | regs->_eax) == 0 )
+        if ( vmcb_get_cpl(vmcb) )
+            hvm_inject_hw_exception(TRAP_gp_fault, 0);
+        else if ( (inst_len = __get_instruction_length(v, INSTR_XSETBV)) &&
+                  hvm_handle_xsetbv(regs->ecx,
+                                    (regs->rdx << 32) | regs->_eax) == 0 )
             __update_guest_eip(regs, inst_len);
         break;