Skip to contentSkip to conversation

Xen Security Advisory 278 v2 (CVE-2018-18883) - x86: Nested VT-x usable even when disabled

PATCH Xen.org security team 1 participant 1 message Nov 1, 2018

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Xen Security Advisory CVE-2018-18883 / XSA-278
version 2

x86: Nested VT-x usable even when disabled

UPDATES IN VERSION 2
====================

CVE assigned.

ISSUE DESCRIPTION
=================

When running HVM guests, virtual extensions are enabled in hardware because Xen is using them. As a result, a guest can blindly execute the virtualisation instructions, and will exit to Xen for processing.

In the case that the guest hasn't followed the correct (virtual) configuration procedure, it shouldn't be able to use the instructions, and Xen should respond with #UD exception. When nested virtualisation is disabled for the guest, it is not permitted to complete the configuration procedure.

Unfortunately, when nested virtualisation is intended to be disabled for the guest, an incorrect default value leads Xen to believe that the configuration procedure has already been completed.

IMPACT
======

Guest software which blindly plays with the VT-x instructions can cause Xen to operate on uninitialised data. As the backing memory is zeroed, this causes Xen to suffer a NULL pointer dereference, causing a host Denial of Service.

Other behaviours such as memory corruption or privilege escalation have not been ruled out.

VULNERABLE SYSTEMS
==================

Systems running Xen 4.9 or later are vulnerable. Systems running Xen 4.8 or earlier are not vulnerable.

Only Intel x86 systems are vulnerable. Systems from other x86 vendors, and other hardware vendors are not vulnerable.

Only x86 HVM and PVH guests can leverage this vulnerability. x86 PV guests cannot leverage this vulnerability.

MITIGATION
==========

Running only x86 PV guests will avoid the issue.

For x86 HVM guests, while enabling nested virtualisation for affected guests does work around this particular DoS, it is not a security supported configuration and has other know DoS and suspected privilege escalation vulnerabilities. Therefore, it is not a mitigation.

CREDITS
=======

This issue was discovered by Sergey Dyasli of Citrix.

RESOLUTION
==========

Applying the appropriate attached patch resolves this issue.

xsa278.patch xen-unstable
xsa278-4.11.patch Xen 4.11, 4.10, 4.9

$ sha256sum xsa278*
d94c59ee170f96af14f0cf696221ba8b9447b86820fe99fba1815ab93cc89cd7  xsa278.patch
22686a9bbfbd38bb74292a28a452012d263875c9064815d4afd3fd6c62df0c3a  xsa278-4.11.patch
$

NOTE CONCERNING LACK OF EMBARGO
===============================

This issue was first reported in private and was in the usual XSA process.

It was later independently reported in public with enough detail for the issue to be considered fully public.
-----BEGIN PGP SIGNATURE-----

iQFABAEBCAAqFiEEI+MiLBRfRHX6gGCng/4UyVfoK9kFAlva3xQMHHBncEB4ZW4u b3JnAAoJEIP+FMlX6CvZ2DUIAKIKRyJ9tb1+t8FVECYVR6L5JjhVjyiC1HKnmmGO o+Fl1glQZqK1b5oKkV58jNf32wUOjhlHut1iXJmuE7VGrBsSzj4ew3wIwFcAeTyL nykIFtS8YBlodQfcd7XRyh030bQ5f5JtJYTyJTpAwor8JQrVJH+lYdv+zddPfVbp sUMXFrSxAmnzhrYKuUHNZ438O6+PwunPROTng6VRmreutqnxjnvxtmLqJLk23gvI jfg8THSawEREg9R6cjpO8ZmfouukTJp7t5mmte1g8kJm/UJ4iRWAS67tYF6m4V+K 1H7Sc0E4yV8I/PL46V+53r43NcCtPFP+GM/AaIzggov2Hn0=
=el52
-----END PGP SIGNATURE-----

From: Andrew Cooper <[email protected]>
Subject: x86/vvmx: Disallow the use of VT-x instructions when nested virt is disabled

c/s ac6a4500b "vvmx: set vmxon_region_pa of vcpu out of VMX operation to an invalid address" was a real bugfix as described, but has a very subtle bug which results in all VT-x instructions being usable by a guest.

The toolstack constructs a guest by issuing:

XEN_DOMCTL_createdomain
XEN_DOMCTL_max_vcpus

and optionally later, HVMOP_set_param to enable nested virt.

As a result, the call to nvmx_vcpu_initialise() in hvm_vcpu_initialise() (which is what makes the above patch look correct during review) is actually dead code. In practice, nvmx_vcpu_initialise() first gets called when nested virt is enabled, which is typically never.

As a result, the zeroed memory of struct vcpu causes nvmx_vcpu_in_vmx() to return true before nested virt is enabled for the guest.

Fixing the order of initialisation is a work in progress for other reasons, but not viable for security backports.

A compounding factor is that the vmexit handlers for all instructions, other than VMXON, pass 0 into vmx_inst_check_privilege()'s vmxop_check parameter, which skips the CR4.VMXE check. (This is one of many reasons why nested virt isn't a supported feature yet.)

However, the overall result is that when nested virt is not enabled by the toolstack (i.e. the default configuration for all production guests), the VT-x instructions (other than VMXON) are actually usable, and Xen very quickly falls over the fact that the nvmx structure is uninitialised.

In order to fail safe in the supported case, re-implement all the VT-x instruction handling using a single function with a common prologue, covering all the checks which should cause #UD or #GP faults. This deliberately doesn't use any state from the nvmx structure, in case there are other lurking issues.

This is XSA-278

xen/arch/x86/hvm/vmx/vmx.c +1 -41
index d16129f..7a49075 100644
@@ -4003,57 +4003,17 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
         break;
 
     case EXIT_REASON_VMXOFF:
-        if ( nvmx_handle_vmxoff(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_VMXON:
-        if ( nvmx_handle_vmxon(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_VMCLEAR:
-        if ( nvmx_handle_vmclear(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
- 
     case EXIT_REASON_VMPTRLD:
-        if ( nvmx_handle_vmptrld(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_VMPTRST:
-        if ( nvmx_handle_vmptrst(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_VMREAD:
-        if ( nvmx_handle_vmread(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
- 
     case EXIT_REASON_VMWRITE:
-        if ( nvmx_handle_vmwrite(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_VMLAUNCH:
-        if ( nvmx_handle_vmlaunch(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_VMRESUME:
-        if ( nvmx_handle_vmresume(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_INVEPT:
-        if ( nvmx_handle_invept(regs) == X86EMUL_OKAY )
-            update_guest_eip();
-        break;
-
     case EXIT_REASON_INVVPID:
-        if ( nvmx_handle_invvpid(regs) == X86EMUL_OKAY )
+        if ( nvmx_handle_vmx_insn(regs, exit_reason) == X86EMUL_OKAY )
             update_guest_eip();
         break;
 
xen/arch/x86/hvm/vmx/vvmx.c +86 -11

169 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +1 -12
index a20bd9e..6b9c4ae 100644
@@ -94,9 +94,6 @@ void nvmx_domain_relinquish_resources(struct domain *d);
 
 bool_t nvmx_ept_enabled(struct vcpu *v);
 
-int nvmx_handle_vmxon(struct cpu_user_regs *regs);
-int nvmx_handle_vmxoff(struct cpu_user_regs *regs);
-
 #define EPT_TRANSLATE_SUCCEED       0
 #define EPT_TRANSLATE_VIOLATION     1
 #define EPT_TRANSLATE_MISCONFIG     2
@@ -189,15 +186,7 @@ enum vmx_insn_errno set_vvmcs_real_safe(const struct vcpu *, u32 encoding,
    set_vvmcs_virtual_safe(vcpu_nestedhvm(vcpu).nv_vvmcx, encoding, val))
 
 void nvmx_destroy_vmcs(struct vcpu *v);
-int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
-int nvmx_handle_vmptrst(struct cpu_user_regs *regs);
-int nvmx_handle_vmclear(struct cpu_user_regs *regs);
-int nvmx_handle_vmread(struct cpu_user_regs *regs);
-int nvmx_handle_vmwrite(struct cpu_user_regs *regs);
-int nvmx_handle_vmresume(struct cpu_user_regs *regs);
-int nvmx_handle_vmlaunch(struct cpu_user_regs *regs);
-int nvmx_handle_invept(struct cpu_user_regs *regs);
-int nvmx_handle_invvpid(struct cpu_user_regs *regs);
+int nvmx_handle_vmx_insn(struct cpu_user_regs *regs, unsigned int exit_reason);
 int nvmx_msr_read_intercept(unsigned int msr,
                                 u64 *msr_content);
 

From: Andrew Cooper <[email protected]>
Subject: x86/vvmx: Disallow the use of VT-x instructions when nested virt is disabled

c/s ac6a4500b "vvmx: set vmxon_region_pa of vcpu out of VMX operation to an invalid address" was a real bugfix as described, but has a very subtle bug which results in all VT-x instructions being usable by a guest.

The toolstack constructs a guest by issuing:

XEN_DOMCTL_createdomain
XEN_DOMCTL_max_vcpus

and optionally later, HVMOP_set_param to enable nested virt.

As a result, the call to nvmx_vcpu_initialise() in hvm_vcpu_initialise() (which is what makes the above patch look correct during review) is actually dead code. In practice, nvmx_vcpu_initialise() first gets called when nested virt is enabled, which is typically never.

As a result, the zeroed memory of struct vcpu causes nvmx_vcpu_in_vmx() to return true before nested virt is enabled for the guest.

Fixing the order of initialisation is a work in progress for other reasons, but not viable for security backports.

A compounding factor is that the vmexit handlers for all instructions, other than VMXON, pass 0 into vmx_inst_check_privilege()'s vmxop_check parameter, which skips the CR4.VMXE check. (This is one of many reasons why nested virt isn't a supported feature yet.)

However, the overall result is that when nested virt is not enabled by the toolstack (i.e. the default configuration for all production guests), the VT-x instructions (other than VMXON) are actually usable, and Xen very quickly falls over the fact that the nvmx structure is uninitialised.

In order to fail safe in the supported case, re-implement all the VT-x instruction handling using a single function with a common prologue, covering all the checks which should cause #UD or #GP faults. This deliberately doesn't use any state from the nvmx structure, in case there are other lurking issues.

This is XSA-278

xen/arch/x86/hvm/vmx/vmx.c +1 -41

58 lines not on this page · raw message

xen/arch/x86/hvm/vmx/vvmx.c +86 -11

169 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +1 -12
index 9ea35eb..fc4a8d1 100644
@@ -94,9 +94,6 @@ void nvmx_domain_relinquish_resources(struct domain *d);
 
 bool_t nvmx_ept_enabled(struct vcpu *v);
 
-int nvmx_handle_vmxon(struct cpu_user_regs *regs);
-int nvmx_handle_vmxoff(struct cpu_user_regs *regs);
-
 #define EPT_TRANSLATE_SUCCEED       0
 #define EPT_TRANSLATE_VIOLATION     1
 #define EPT_TRANSLATE_MISCONFIG     2
@@ -191,15 +188,7 @@ enum vmx_insn_errno set_vvmcs_real_safe(const struct vcpu *, u32 encoding,
 uint64_t get_shadow_eptp(struct vcpu *v);
 
 void nvmx_destroy_vmcs(struct vcpu *v);
-int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
-int nvmx_handle_vmptrst(struct cpu_user_regs *regs);
-int nvmx_handle_vmclear(struct cpu_user_regs *regs);
-int nvmx_handle_vmread(struct cpu_user_regs *regs);
-int nvmx_handle_vmwrite(struct cpu_user_regs *regs);
-int nvmx_handle_vmresume(struct cpu_user_regs *regs);
-int nvmx_handle_vmlaunch(struct cpu_user_regs *regs);
-int nvmx_handle_invept(struct cpu_user_regs *regs);
-int nvmx_handle_invvpid(struct cpu_user_regs *regs);
+int nvmx_handle_vmx_insn(struct cpu_user_regs *regs, unsigned int exit_reason);
 int nvmx_msr_read_intercept(unsigned int msr,
                                 u64 *msr_content);
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel