Skip to content

Commit 24acafe

Browse files
ouptonjfvogel
authored andcommitted
KVM: nVMX: Check IO instruction VM-exit conditions
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. Signed-off-by: Oliver Upton <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 35a5713) Orabug: 30847133 CVE: CVE-2020-2732 Signed-off-by: Boris Ostrovsky <[email protected]> Reviewed-by: Darren Kenny <[email protected]>
1 parent 090df0f commit 24acafe

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5171,7 +5171,7 @@ static bool nested_vmx_exit_handled_io(struct kvm_vcpu *vcpu,
51715171
struct vmcs12 *vmcs12)
51725172
{
51735173
unsigned long exit_qualification;
5174-
unsigned int port;
5174+
unsigned short port;
51755175
int size;
51765176

51775177
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))

arch/x86/kvm/vmx/vmx.c

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7177,25 +7177,70 @@ static void vmx_request_immediate_exit(struct kvm_vcpu *vcpu)
71777177
to_vmx(vcpu)->req_immediate_exit = true;
71787178
}
71797179

7180+
static int vmx_check_intercept_io(struct kvm_vcpu *vcpu,
7181+
struct x86_instruction_info *info)
7182+
{
7183+
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
7184+
unsigned short port;
7185+
bool intercept;
7186+
int size;
7187+
7188+
if (info->intercept == x86_intercept_in ||
7189+
info->intercept == x86_intercept_ins) {
7190+
port = info->src_val;
7191+
size = info->dst_bytes;
7192+
} else {
7193+
port = info->dst_val;
7194+
size = info->src_bytes;
7195+
}
7196+
7197+
/*
7198+
* If the 'use IO bitmaps' VM-execution control is 0, IO instruction
7199+
* VM-exits depend on the 'unconditional IO exiting' VM-execution
7200+
* control.
7201+
*
7202+
* Otherwise, IO instruction VM-exits are controlled by the IO bitmaps.
7203+
*/
7204+
if (!nested_cpu_has(vmcs12, CPU_BASED_USE_IO_BITMAPS))
7205+
intercept = nested_cpu_has(vmcs12,
7206+
CPU_BASED_UNCOND_IO_EXITING);
7207+
else
7208+
intercept = nested_vmx_check_io_bitmaps(vcpu, port, size);
7209+
7210+
return intercept ? X86EMUL_UNHANDLEABLE : X86EMUL_CONTINUE;
7211+
}
7212+
71807213
static int vmx_check_intercept(struct kvm_vcpu *vcpu,
71817214
struct x86_instruction_info *info,
71827215
enum x86_intercept_stage stage)
71837216
{
71847217
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
71857218
struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
71867219

7220+
switch (info->intercept) {
71877221
/*
71887222
* RDPID causes #UD if disabled through secondary execution controls.
71897223
* Because it is marked as EmulateOnUD, we need to intercept it here.
71907224
*/
7191-
if (info->intercept == x86_intercept_rdtscp &&
7192-
!nested_cpu_has2(vmcs12, SECONDARY_EXEC_RDTSCP)) {
7193-
ctxt->exception.vector = UD_VECTOR;
7194-
ctxt->exception.error_code_valid = false;
7195-
return X86EMUL_PROPAGATE_FAULT;
7196-
}
7225+
case x86_intercept_rdtscp:
7226+
if (!nested_cpu_has2(vmcs12, SECONDARY_EXEC_RDTSCP)) {
7227+
ctxt->exception.vector = UD_VECTOR;
7228+
ctxt->exception.error_code_valid = false;
7229+
return X86EMUL_PROPAGATE_FAULT;
7230+
}
7231+
break;
7232+
7233+
case x86_intercept_in:
7234+
case x86_intercept_ins:
7235+
case x86_intercept_out:
7236+
case x86_intercept_outs:
7237+
return vmx_check_intercept_io(vcpu, info);
71977238

71987239
/* TODO: check more intercepts... */
7240+
default:
7241+
break;
7242+
}
7243+
71997244
return X86EMUL_UNHANDLEABLE;
72007245
}
72017246

0 commit comments

Comments
 (0)