kvm: nVMX: Don't allow L2 to access the hardware CR8
PATCH 1/1 kvm: nVMX: Don't allow L2 to access the hardware CR8
If L1 does not specify the "use TPR shadow" VM-execution control in vmcs12, then L0 must specify the "CR8-load exiting" and "CR8-store exiting" VM-execution controls in vmcs02. Failure to do so will give the L2 VM unrestricted read/write access to the hardware CR8.
This fixes CVE-2017-12154.
--- arch/x86/kvm/vmx.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kvm/vmx.c +5 -0
@@ -10525,6 +10525,11 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,if (exec_control &CPU_BASED_TPR_SHADOW ) {vmcs_write64 (VIRTUAL_APIC_PAGE_ADDR ,-1ull );vmcs_write32 (TPR_THRESHOLD , vmcs12->tpr_threshold); + }else { +#ifdef CONFIG_X86_64 + exec_control |=CPU_BASED_CR8_LOAD_EXITING | +CPU_BASED_CR8_STORE_EXITING ; +#endif }/*
Signature · 1 line
2.14.1.581.gf28d330327-goog
Quoted 19 lines · Jim Mattson
If L1 does not specify the "use TPR shadow" VM-execution control in vmcs12, then L0 must specify the "CR8-load exiting" and "CR8-store exiting" VM-execution controls in vmcs02. Failure to do so will give the L2 VM unrestricted read/write access to the hardware CR8.
This fixes CVE-2017-12154.
Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++++ 1 file changed, 5 insertions(+)arch/x86/kvm/vmx.c +0
-0@@ -10525,6 +10525,11 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,if (exec_control &CPU_BASED_TPR_SHADOW ) {
arch/x86/kvm/vmx.c static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, · line 10535
Quoted 10 lines
arch/x86/kvm/vmx.c +5
-0vmcs_write64 (VIRTUAL_APIC_PAGE_ADDR ,-1ull );vmcs_write32 (TPR_THRESHOLD , vmcs12->tpr_threshold); + }else { +#ifdef CONFIG_X86_64 + exec_control |=CPU_BASED_CR8_LOAD_EXITING | +CPU_BASED_CR8_STORE_EXITING ; +#endif }/*
Don't you have to make sure that setting these bits to 1 is supported? (yes, there could be strange configurations - nested nested ...)
Signature · 3 lines
Thanks, David
Good point. I think the best solution is to require 'use TPR shadow' for vmcs12 if the hardware doesn't support CR8-{load,store} exiting.
If the hardware supports neither 'use TPR shadow' nor CR8-{load,store} exiting, then we have to somehow restrict L1 and L2 VMs to legacy mode (or just give up on VT-x altogether).
Quoted 39 lines · David Hildenbrand
Quoted 19 lines · Jim Mattson
If L1 does not specify the "use TPR shadow" VM-execution control in vmcs12, then L0 must specify the "CR8-load exiting" and "CR8-store exiting" VM-execution controls in vmcs02. Failure to do so will give the L2 VM unrestricted read/write access to the hardware CR8.
This fixes CVE-2017-12154.
Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++++ 1 file changed, 5 insertions(+)arch/x86/kvm/vmx.c +0
-0@@ -10525,6 +10525,11 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,if (exec_control &CPU_BASED_TPR_SHADOW ) {arch/x86/kvm/vmx.c static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, · line 10535
Quoted 10 lines
arch/x86/kvm/vmx.c +5
-0vmcs_write64 (VIRTUAL_APIC_PAGE_ADDR ,-1ull );vmcs_write32 (TPR_THRESHOLD , vmcs12->tpr_threshold); + }else { +#ifdef CONFIG_X86_64 + exec_control |=CPU_BASED_CR8_LOAD_EXITING | +CPU_BASED_CR8_STORE_EXITING ; +#endif }/* Don't you have to make sure that setting these bits to 1 is supported? (yes, there could be strange configurations - nested nested ...)
--
Thanks,
David
I take it back. Your proposed V-x configuration isn't supported by kvm at all. CPU_BASED_CR8_LOAD_EXITING and CPU_BASED_CR8_STORE_EXITING are in the minimum required primary processor-based VM-execution controls enforced by setup_vmcs_config(). So...someone else has already made sure that setting these bits to 1 is supported. :-)
Quoted 47 lines · Jim Mattson
Good point. I think the best solution is to require 'use TPR shadow' for vmcs12 if the hardware doesn't support CR8-{load,store} exiting.
If the hardware supports neither 'use TPR shadow' nor CR8-{load,store} exiting, then we have to somehow restrict L1 and L2 VMs to legacy mode (or just give up on VT-x altogether).
Quoted 39 lines · David Hildenbrand
Quoted 19 lines · Jim Mattson
If L1 does not specify the "use TPR shadow" VM-execution control in vmcs12, then L0 must specify the "CR8-load exiting" and "CR8-store exiting" VM-execution controls in vmcs02. Failure to do so will give the L2 VM unrestricted read/write access to the hardware CR8.
This fixes CVE-2017-12154.
Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++++ 1 file changed, 5 insertions(+)arch/x86/kvm/vmx.c +0
-0@@ -10525,6 +10525,11 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,if (exec_control &CPU_BASED_TPR_SHADOW ) {arch/x86/kvm/vmx.c static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, · line 10535
Quoted 10 lines
arch/x86/kvm/vmx.c +5
-0vmcs_write64 (VIRTUAL_APIC_PAGE_ADDR ,-1ull );vmcs_write32 (TPR_THRESHOLD , vmcs12->tpr_threshold); + }else { +#ifdef CONFIG_X86_64 + exec_control |=CPU_BASED_CR8_LOAD_EXITING | +CPU_BASED_CR8_STORE_EXITING ; +#endif }/* Don't you have to make sure that setting these bits to 1 is supported? (yes, there could be strange configurations - nested nested ...)
--
Thanks,
David
Paolo Bonzini
maintainerQuoted 5 lines · Jim Mattson
I take it back. Your proposed V-x configuration isn't supported by kvm at all.
CPU_BASED_CR8_LOAD_EXITINGandCPU_BASED_CR8_STORE_EXITINGare in the minimum required primary processor-based VM-execution controls enforced bysetup_vmcs_config(). So...someone else has already made sure that setting these bits to 1 is supported. :-)
Right, that's because VMs with userspace LAPIC cannot use TPR shadowing and must use CR8-load/store exiting instead. (OTOH even with kernel LAPIC a hypothetical configuration _without_ TPR shadowing could still fall back to CR8-load/store exits).
Thanks,
Paolo
David Hildenbrand
Reviewed-byQuoted 6 lines · Jim Mattson
I take it back. Your proposed V-x configuration isn't supported by kvm at all.
CPU_BASED_CR8_LOAD_EXITINGandCPU_BASED_CR8_STORE_EXITINGare in the minimum required primary processor-based VM-execution controls enforced bysetup_vmcs_config(). So...someone else has already made sure that setting these bits to 1 is supported. :-)
That implies
:)
Thanks,
David