Skip to contentSkip to conversation

CVE-2020-2732

PATCH In review Paolo Bonzini 4 participants 12 messages Feb 24, 2020 – Mar 1, 2020

Subsystems (4)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

cover 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
author maintainer
#1 lore raw

PATCH 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.

[Made commit, added commit msg - Oliver]
---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
index dcca514ffd42..5801a86f9c24 100644
@@ -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
#2 lore raw

Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode

Quoted 18 lines · Paolo Bonzini

vmx_check_intercept is 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]
---
  arch/x86/kvm/vmx/vmx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +0 -0
index dcca514ffd42..5801a86f9c24 100644

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

#3 lore raw

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() in start_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

#4 lore raw

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() in start_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?

#5 lore raw

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() in start_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

#6 lore raw

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'.

Fixes 07721feee46b ("KVM: nVMX: Don't emulate instructions in guest mode")
Cc Paolo Bonzini <[email protected]>
Cc Jim Mattson <[email protected]>
---
 arch/x86/kvm/vmx/vmx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/kvm/vmx/vmx.c +11 -0
index 63aaf44edd1f..e718b4c9455f 100644
@@ -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
author maintainer Applied
#7 lore raw

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")
Cc Paolo Bonzini <[email protected]>
Cc Jim Mattson <[email protected]>
---
 arch/x86/kvm/vmx/vmx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/kvm/vmx/vmx.c +4 -0
index 63aaf44edd1f..e718b4c9455f 100644
@@ -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

#8 lore raw

Re: [FYI PATCH 1/3] KVM: nVMX: Don't emulate instructions in guest mode

In reply to Jan Kiszka

Since 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() in start_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

#9 lore raw

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() in start_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

author maintainer
#10 lore raw

PATCH 2/3 KVM: nVMX: Refactor IO bitmap checks into helper function

In reply to Paolo Bonzini

From: 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
index 50d8dbb3616d..f979832c394d 100644
@@ -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
index 1db388f2a444..9aeda46f473e 100644
@@ -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
author maintainer
#11 lore raw

PATCH 3/3 KVM: nVMX: Check IO instruction VM-exit conditions

In reply to Paolo Bonzini

From: 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
index f979832c394d..e920d7834d73 100644
@@ -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