CVE-2020-2732
Subsystems (4)
Paolo Bonzini
maintainercover CVE-2020-2732
vmx_check_intercept is not yet fully implemented by KVM on Intel processors, causing e.g. the I/O or MSR interception bitmaps not to be checked. In general we can just disallow instruction emulation on behalf of L1, but this series also implements I/O port checks.
Paolo
Oliver Upton (2):
KVM: nVMX: Refactor IO bitmap checks into helper function
KVM: nVMX: Check IO instruction VM-exit conditions
Paolo Bonzini (1):
KVM: nVMX: Don't emulate instructions in guest mode
arch/x86/kvm/vmx/nested.c | 39 ++++++++++++++++++++----------- arch/x86/kvm/vmx/nested.h | 2 ++ arch/x86/kvm/vmx/vmx.c | 59 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 79 insertions(+), 21 deletions(-)
Signature · 1 line
1.8.3.1
Paolo Bonzini
maintainerPATCH 1/3 KVM: nVMX: Don't emulate instructions in guest mode
vmx_check_intercept is not yet fully implemented. To avoid emulating instructions disallowed by the L1 hypervisor, refuse to emulate instructions by default.
--- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -7164,7 +7164,7 @@ static int vmx_check_intercept(struct kvm_vcpu *vcpu, }/* TODO: check more intercepts... */ -return X86EMUL_CONTINUE ; +return X86EMUL_UNHANDLEABLE ; }#ifdef CONFIG_X86_64
Signature · 1 line
1.8.3.1
Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode
Quoted 18 lines · Paolo Bonzini
vmx_check_interceptis not yet fully implemented. To avoid emulating instructions disallowed by the L1 hypervisor, refuse to emulate instructions by default.[Made commit, added commit msg - Oliver]Signed-off-by Oliver Upton <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static int vmx_check_intercept(struct kvm_vcpu *vcpu, · line 7170
Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +1
-1@@ -7164,7 +7164,7 @@ static int vmx_check_intercept(struct kvm_vcpu *vcpu, }/* TODO: check more intercepts... */ -return X86EMUL_CONTINUE ; +return X86EMUL_UNHANDLEABLE ; }#ifdef CONFIG_X86_64
Is this expected to cause regressions on less common workloads? Jailhouse as L1 now fails when Linux as L2 tries to boot a CPU: L2-Linux gets a triple fault on load_current_idt() in start_secondary(). Only bisected so far, didn't debug further.
Jan
Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode
Hi Jan,
Quoted 4 lines · Jan Kiszka
Is this expected to cause regressions on less common workloads? Jailhouse as L1 now fails when Linux as L2 tries to boot a CPU: L2-Linux gets a triple fault on
load_current_idt()instart_secondary(). Only bisected so far, didn't debug further.
I'm guessing that Jailhouse doesn't use 'descriptor table exiting', so when KVM gets the corresponding exit from L2 the emulation burden is on L0. We now refuse the emulation, which kicks a #UD back to L2. I can get a patch out quickly to address this case (like the PIO exiting one that came in this series) but the eventual solution is to map emulator intercept checks into VM-exits + call into the nested_vmx_exit_reflected() plumbing.
--
Thanks,
Oliver
Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode
Quoted 9 lines · Oliver Upton
Hi Jan,
Quoted 4 lines · Jan Kiszka
Is this expected to cause regressions on less common workloads? Jailhouse as L1 now fails when Linux as L2 tries to boot a CPU: L2-Linux gets a triple fault on
load_current_idt()instart_secondary(). Only bisected so far, didn't debug further.
Quoted 7 lines
I'm guessing that Jailhouse doesn't use 'descriptor table exiting', so when KVM gets the corresponding exit from L2 the emulation burden is on L0. We now refuse the emulation, which kicks a #UD back to L2. I can get a patch out quickly to address this case (like the PIO exiting one that came in this series) but the eventual solution is to map emulator intercept checks into VM-exits + call into the
nested_vmx_exit_reflected()plumbing.
If Jailhouse doesn't use descriptor table exiting, why is L0 intercepting descriptor table instructions? Is this just so that L0 can partially emulate UMIP on hardware that doesn't support it?
Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode
Quoted 18 lines · Jim Mattson
Quoted 9 lines · Oliver Upton
Hi Jan,
Quoted 4 lines · Jan Kiszka
Is this expected to cause regressions on less common workloads? Jailhouse as L1 now fails when Linux as L2 tries to boot a CPU: L2-Linux gets a triple fault on
load_current_idt()instart_secondary(). Only bisected so far, didn't debug further.Quoted 7 lines
I'm guessing that Jailhouse doesn't use 'descriptor table exiting', so when KVM gets the corresponding exit from L2 the emulation burden is on L0. We now refuse the emulation, which kicks a #UD back to L2. I can get a patch out quickly to address this case (like the PIO exiting one that came in this series) but the eventual solution is to map emulator intercept checks into VM-exits + call into the
nested_vmx_exit_reflected()plumbing.
Quoted 4 lines
If Jailhouse doesn't use descriptor table exiting, why is L0 intercepting descriptor table instructions? Is this just so that L0 can partially emulate UMIP on hardware that doesn't support it?
That seems to be the case: My host lacks umip, L1 has it. So, KVM is intercepting descriptor table load instructions to emulate umip. Jailhouse never activates that interception.
Jan
PATCH 1/1 KVM: VMX: check descriptor table exits on instruction emulation
KVM emulates UMIP on hardware that doesn't support it by setting the 'descriptor table exiting' VM-execution control and performing instruction emulation. When running nested, this emulation is broken as KVM refuses to emulate L2 instructions by default.
Correct this regression by allowing the emulation of descriptor table instructions if L1 hasn't requested 'descriptor table exiting'.
--- arch/x86/kvm/vmx/vmx.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/x86/kvm/vmx/vmx.c +11 -0
@@ -7204,6 +7204,17 @@ static int vmx_check_intercept(struct kvm_vcpu *vcpu,case x86_intercept_outs:return vmx_check_intercept_io (vcpu, info); +case x86_intercept_lgdt: +case x86_intercept_lidt: +case x86_intercept_lldt: +case x86_intercept_ltr: +case x86_intercept_sgdt: +case x86_intercept_sidt: +case x86_intercept_sldt: +case x86_intercept_str: +if (!nested_cpu_has2 (vmcs12,SECONDARY_EXEC_DESC )) +return X86EMUL_CONTINUE ; +/* TODO: check more intercepts... */ default :break ;
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Re: [PATCH] KVM: VMX: check descriptor table exits on instruction emulation
Quoted 31 lines · Oliver Upton
KVM emulates UMIP on hardware that doesn't support it by setting the 'descriptor table exiting' VM-execution control and performing instruction emulation. When running nested, this emulation is broken as KVM refuses to emulate L2 instructions by default.
Correct this regression by allowing the emulation of descriptor table instructions if L1 hasn't requested 'descriptor table exiting'.
Fixes 07721feee46b ("KVM: nVMX: Don't emulate instructions in guest mode")Reported-by Jan Kiszka <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Jim Mattson <[email protected]>Signed-off-by Oliver Upton <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/x86/kvm/vmx/vmx.c +4
-0@@ -7204,6 +7204,17 @@ static int vmx_check_intercept(struct kvm_vcpu *vcpu,case x86_intercept_outs:return vmx_check_intercept_io (vcpu, info); +case x86_intercept_lgdt: +case x86_intercept_lidt: +case x86_intercept_lldt: +case x86_intercept_ltr:
arch/x86/kvm/vmx/vmx.c static int vmx_check_intercept(struct kvm_vcpu *vcpu, · line 7220
Quoted 10 lines
arch/x86/kvm/vmx/vmx.c +7
-0+case x86_intercept_sgdt: +case x86_intercept_sidt: +case x86_intercept_sldt: +case x86_intercept_str: +if (!nested_cpu_has2 (vmcs12,SECONDARY_EXEC_DESC )) +return X86EMUL_CONTINUE ; +/* TODO: check more intercepts... */ default :break ;
Queued, thanks.
Paolo
Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode
In reply to Jan KiszkaSince UMIP emulation is broken, I'm not sure why anyone would use it. (Sorry, Paolo.)
Quoted 30 lines · Jan Kiszka
Quoted 18 lines · Jim Mattson
Quoted 9 lines · Oliver Upton
Hi Jan,
Quoted 4 lines · Jan Kiszka
Is this expected to cause regressions on less common workloads? Jailhouse as L1 now fails when Linux as L2 tries to boot a CPU: L2-Linux gets a triple fault on
load_current_idt()instart_secondary(). Only bisected so far, didn't debug further.Quoted 7 lines
I'm guessing that Jailhouse doesn't use 'descriptor table exiting', so when KVM gets the corresponding exit from L2 the emulation burden is on L0. We now refuse the emulation, which kicks a #UD back to L2. I can get a patch out quickly to address this case (like the PIO exiting one that came in this series) but the eventual solution is to map emulator intercept checks into VM-exits + call into the
nested_vmx_exit_reflected()plumbing.Quoted 4 lines
If Jailhouse doesn't use descriptor table exiting, why is L0 intercepting descriptor table instructions? Is this just so that L0 can partially emulate UMIP on hardware that doesn't support it?
That seems to be the case: My host lacks umip, L1 has it. So, KVM is intercepting descriptor table load instructions to emulate umip. Jailhouse never activates that interception.
Jan
Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode
Quoted 2 lines · Jim Mattson
Since UMIP emulation is broken, I'm not sure why anyone would use it. (Sorry, Paolo.)
FWIW, adding "-umip" to the "-cpu host" in my qemu setup works around the bug.
Jan
Quoted 32 lines · Jan Kiszka
Quoted 30 lines · Jim Mattson
Quoted 18 lines · Oliver Upton
Quoted 9 lines
Hi Jan,
Quoted 4 lines · Jan Kiszka
Is this expected to cause regressions on less common workloads? Jailhouse as L1 now fails when Linux as L2 tries to boot a CPU: L2-Linux gets a triple fault on
load_current_idt()instart_secondary(). Only bisected so far, didn't debug further.Quoted 7 lines
I'm guessing that Jailhouse doesn't use 'descriptor table exiting', so when KVM gets the corresponding exit from L2 the emulation burden is on L0. We now refuse the emulation, which kicks a #UD back to L2. I can get a patch out quickly to address this case (like the PIO exiting one that came in this series) but the eventual solution is to map emulator intercept checks into VM-exits + call into the
nested_vmx_exit_reflected()plumbing.Quoted 4 lines
If Jailhouse doesn't use descriptor table exiting, why is L0 intercepting descriptor table instructions? Is this just so that L0 can partially emulate UMIP on hardware that doesn't support it?
That seems to be the case: My host lacks umip, L1 has it. So, KVM is intercepting descriptor table load instructions to emulate umip. Jailhouse never activates that interception.
Jan
Paolo Bonzini
maintainerPATCH 2/3 KVM: nVMX: Refactor IO bitmap checks into helper function
In reply to Paolo BonziniFrom: Oliver Upton <[email protected]>
Checks against the IO bitmap are useful for both instruction emulation and VM-exit reflection. Refactor the IO bitmap checks into a helper function.
--- arch/x86/kvm/vmx/nested.c | 39 +++++++++++++++++++++++++-------------- arch/x86/kvm/vmx/nested.h | 2 ++ 2 files changed, 27 insertions(+), 14 deletions(-)
arch/x86/kvm/vmx/nested.c +25 -14
@@ -5312,24 +5312,17 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu)return 1 ; } - -static bool nested_vmx_exit_handled_io (struct kvm_vcpu *vcpu, -struct vmcs12 *vmcs12) +/* +* Return true if an IO instruction with the specified port and size should cause +* a VM-exit into L1. +*/ +bool nested_vmx_check_io_bitmaps (struct kvm_vcpu *vcpu,unsigned int port, +int size) { -unsigned long exit_qualification; +struct vmcs12 *vmcs12 =get_vmcs12 (vcpu);gpa_t bitmap, last_bitmap; -unsigned int port; -int size;u8 b; -if (!nested_cpu_has (vmcs12,CPU_BASED_USE_IO_BITMAPS )) -return nested_cpu_has (vmcs12,CPU_BASED_UNCOND_IO_EXITING ); - - exit_qualification =vmcs_readl (EXIT_QUALIFICATION ); - - port = exit_qualification >>16 ; - size = (exit_qualification &7 ) +1 ; - last_bitmap = (gpa_t)-1 ; b =-1 ;
@@ -5356,6 +5349,24 @@ static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,return false; } +static bool nested_vmx_exit_handled_io (struct kvm_vcpu *vcpu, +struct vmcs12 *vmcs12) +{ +unsigned long exit_qualification; +unsigned int port; +int size; + +if (!nested_cpu_has (vmcs12,CPU_BASED_USE_IO_BITMAPS )) +return nested_cpu_has (vmcs12,CPU_BASED_UNCOND_IO_EXITING ); + + exit_qualification =vmcs_readl (EXIT_QUALIFICATION ); + + port = exit_qualification >>16 ; + size = (exit_qualification &7 ) +1 ; + +return nested_vmx_check_io_bitmaps (vcpu, port, size); +} +/* * Return 1 if we should exit from L2 to L1 to handle an MSR access, * rather than handle it ourselves in L0. I.e., check whether L1 expressed
arch/x86/kvm/vmx/nested.h +2 -0
@@ -33,6 +33,8 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,int get_vmx_mem_address (struct kvm_vcpu *vcpu,unsigned long exit_qualification,u32 vmx_instruction_info,bool wr,int len,gva_t *ret);void nested_vmx_pmu_entry_exit_ctls_update (struct kvm_vcpu *vcpu); +bool nested_vmx_check_io_bitmaps (struct kvm_vcpu *vcpu,unsigned int port, +int size);static inline struct vmcs12 *get_vmcs12 (struct kvm_vcpu *vcpu) {
Signature · 1 line
1.8.3.1
Paolo Bonzini
maintainerPATCH 3/3 KVM: nVMX: Check IO instruction VM-exit conditions
In reply to Paolo BonziniFrom: Oliver Upton <[email protected]>
Consult the 'unconditional IO exiting' and 'use IO bitmaps' VM-execution controls when checking instruction interception. If the 'use IO bitmaps' VM-execution control is 1, check the instruction access against the IO bitmaps to determine if the instruction causes a VM-exit.
--- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 57 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 7 deletions(-)
arch/x86/kvm/vmx/nested.c +1 -1
@@ -5353,7 +5353,7 @@ static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) {unsigned long exit_qualification; -unsigned int port; +unsigned short port;int size;if (!nested_cpu_has (vmcs12,CPU_BASED_USE_IO_BITMAPS ))
arch/x86/kvm/vmx/vmx.c +51 -6
75 lines not on this page · raw message
Signature · 1 line
1.8.3.1