Skip to contentSkip to conversation

x86/HVM: only kill guest when unknown VM exit occurred in guest kernel mode

PATCH In review Jan Beulich 4 participants 5 messages Oct 30, 2014 – Oct 31, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/HVM: only kill guest when unknown VM exit occurred in guest kernel mode

A recent KVM change by Nadav Amit <[email protected]> pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode).

This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above.

xen/arch/x86/hvm/svm/svm.c +5 -1
@@ -2680,7 +2680,11 @@ void svm_vmexit_handler(struct cpu_user_
                  "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
                  exit_reason, 
                  (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
-        domain_crash(v->domain);
+        if ( vmcb_get_cpl(vmcb) )
+            hvm_inject_hw_exception(TRAP_invalid_op,
+                                    HVM_DELIVER_NO_ERROR_CODE);
+        else
+            domain_crash(v->domain);
         break;
     }
 
xen/arch/x86/hvm/vmx/vmx.c +13 -2
@@ -3157,8 +3157,19 @@ void vmx_vmexit_handler(struct cpu_user_
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_ERR, "Bad vmexit (reason %#lx)\n", exit_reason);
-        domain_crash(v->domain);
+        {
+            struct segment_register ss;
+
+            gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n",
+                     exit_reason);
+
+            vmx_get_segment_register(v, x86_seg_ss, &ss);
+            if ( ss.attr.fields.dpl )
+                hvm_inject_hw_exception(TRAP_invalid_op,
+                                        HVM_DELIVER_NO_ERROR_CODE);
+            else
+                domain_crash(v->domain);
+        }
         break;
     }
 

x86/HVM: only kill guest when unknown VM exit occurred in guest kernel mode

A recent KVM change by Nadav Amit <[email protected]> pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode).

This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above.

xen/arch/x86/hvm/svm/svm.c +5 -1
@@ -2680,7 +2680,11 @@ void svm_vmexit_handler(struct cpu_user_
                  "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
                  exit_reason, 
                  (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
-        domain_crash(v->domain);
+        if ( vmcb_get_cpl(vmcb) )
+            hvm_inject_hw_exception(TRAP_invalid_op,
+                                    HVM_DELIVER_NO_ERROR_CODE);
+        else
+            domain_crash(v->domain);
         break;
     }
 
xen/arch/x86/hvm/vmx/vmx.c +13 -2
@@ -3157,8 +3157,19 @@ void vmx_vmexit_handler(struct cpu_user_
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_ERR, "Bad vmexit (reason %#lx)\n", exit_reason);
-        domain_crash(v->domain);
+        {
+            struct segment_register ss;
+
+            gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n",
+                     exit_reason);
+
+            vmx_get_segment_register(v, x86_seg_ss, &ss);
+            if ( ss.attr.fields.dpl )
+                hvm_inject_hw_exception(TRAP_invalid_op,
+                                        HVM_DELIVER_NO_ERROR_CODE);
+            else
+                domain_crash(v->domain);
+        }
         break;
     }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Jan Beulich

A recent KVM change by Nadav Amit <[email protected]> pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode).

This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above.

Quoted 2 lines

The gdprintk() in vmx.c is not true for some entries via the exit_and_crash label, but it is probably worth deferring fixing it to a separate patch.

Quoted 45 lines
xen/arch/x86/hvm/svm/svm.c +5 -1
@@ -2680,7 +2680,11 @@ void svm_vmexit_handler(struct cpu_user_
                  "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
                  exit_reason, 
                  (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
-        domain_crash(v->domain);
+        if ( vmcb_get_cpl(vmcb) )
+            hvm_inject_hw_exception(TRAP_invalid_op,
+                                    HVM_DELIVER_NO_ERROR_CODE);
+        else
+            domain_crash(v->domain);
         break;
     }
 
xen/arch/x86/hvm/vmx/vmx.c +13 -2
@@ -3157,8 +3157,19 @@ void vmx_vmexit_handler(struct cpu_user_
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_ERR, "Bad vmexit (reason %#lx)\n", exit_reason);
-        domain_crash(v->domain);
+        {
+            struct segment_register ss;
+
+            gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n",
+                     exit_reason);
+
+            vmx_get_segment_register(v, x86_seg_ss, &ss);
+            if ( ss.attr.fields.dpl )
+                hvm_inject_hw_exception(TRAP_invalid_op,
+                                        HVM_DELIVER_NO_ERROR_CODE);
+            else
+                domain_crash(v->domain);
+        }
         break;
     }
 
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 30.10.14 at 15:57, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich

A recent KVM change by Nadav Amit <[email protected]> pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode).

This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above.

Quoted 8 lines
Quoted 2 lines

The gdprintk() in vmx.c is not true for some entries via the exit_and_crash label, but it is probably worth deferring fixing it to a separate patch.

Right - several would better bypass the logging. The same applies to svm.c afaict. And yes, logically a separate change, so better also a separate patch.

Jan

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jan Beulich
Quoted 15 lines · Jan Beulich

A recent KVM change by Nadav Amit <[email protected]> pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode).

This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above.

Quoted 2 lines
Quoted 43 lines
xen/arch/x86/hvm/svm/svm.c +5 -1
@@ -2680,7 +2680,11 @@ void svm_vmexit_handler(struct cpu_user_
                   "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
                   exit_reason,
                   (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
-        domain_crash(v->domain);
+        if ( vmcb_get_cpl(vmcb) )
+            hvm_inject_hw_exception(TRAP_invalid_op,
+                                    HVM_DELIVER_NO_ERROR_CODE);
+        else
+            domain_crash(v->domain);
          break;
      }
 
xen/arch/x86/hvm/vmx/vmx.c +13 -2
@@ -3157,8 +3157,19 @@ void vmx_vmexit_handler(struct cpu_user_
      /* fall through */
      default:
      exit_and_crash:
-        gdprintk(XENLOG_ERR, "Bad vmexit (reason %#lx)\n", exit_reason);
-        domain_crash(v->domain);
+        {
+            struct segment_register ss;
+
+            gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n",
+                     exit_reason);
+
+            vmx_get_segment_register(v, x86_seg_ss, &ss);
+            if ( ss.attr.fields.dpl )
+                hvm_inject_hw_exception(TRAP_invalid_op,
+                                        HVM_DELIVER_NO_ERROR_CODE);
+            else
+                domain_crash(v->domain);
+        }
          break;
      }
 
Acked-by on v1 1/1
#4 lore raw
In reply to Jan Beulich
Quoted 18 lines

From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, October 30, 2014 10:43 PM

A recent KVM change by Nadav Amit <[email protected]> pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode).

This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above.

Quoted 2 lines
Quoted 44 lines
xen/arch/x86/hvm/svm/svm.c +5 -1
@@ -2680,7 +2680,11 @@ void svm_vmexit_handler(struct cpu_user_
                  "exitinfo1 = %#"PRIx64", exitinfo2 = %#"PRIx64"\n",
                  exit_reason,
                  (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);
-        domain_crash(v->domain);
+        if ( vmcb_get_cpl(vmcb) )
+            hvm_inject_hw_exception(TRAP_invalid_op,
+
 HVM_DELIVER_NO_ERROR_CODE);
+        else
+            domain_crash(v->domain);
         break;
     }
xen/arch/x86/hvm/vmx/vmx.c +13 -2
@@ -3157,8 +3157,19 @@ void vmx_vmexit_handler(struct cpu_user_
     /* fall through */
     default:
     exit_and_crash:
-        gdprintk(XENLOG_ERR, "Bad vmexit (reason %#lx)\n", exit_reason);
-        domain_crash(v->domain);
+        {
+            struct segment_register ss;
+
+            gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n",
+                     exit_reason);
+
+            vmx_get_segment_register(v, x86_seg_ss, &ss);
+            if ( ss.attr.fields.dpl )
+                hvm_inject_hw_exception(TRAP_invalid_op,
+
 HVM_DELIVER_NO_ERROR_CODE);
+            else
+                domain_crash(v->domain);
+        }
         break;
     }