Skip to content

Commit c2b8cdf

Browse files
dwmw2bonzini
authored andcommitted
KVM: x86/xen: Only do in-kernel acceleration of hypercalls for guest CPL0
There are almost no hypercalls which are valid from CPL > 0, and definitely none which are handled by the kernel. Fixes: 2fd6df2 ("KVM: x86/xen: intercept EVTCHNOP_send from guests") Reported-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Sean Christopherson <seanjc@google.com> Cc: stable@kernel.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 4ea9439 commit c2b8cdf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

arch/x86/kvm/xen.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
12271227
bool longmode;
12281228
u64 input, params[6], r = -ENOSYS;
12291229
bool handled = false;
1230+
u8 cpl;
12301231

12311232
input = (u64)kvm_register_read(vcpu, VCPU_REGS_RAX);
12321233

@@ -1254,9 +1255,17 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
12541255
params[5] = (u64)kvm_r9_read(vcpu);
12551256
}
12561257
#endif
1258+
cpl = static_call(kvm_x86_get_cpl)(vcpu);
12571259
trace_kvm_xen_hypercall(input, params[0], params[1], params[2],
12581260
params[3], params[4], params[5]);
12591261

1262+
/*
1263+
* Only allow hypercall acceleration for CPL0. The rare hypercalls that
1264+
* are permitted in guest userspace can be handled by the VMM.
1265+
*/
1266+
if (unlikely(cpl > 0))
1267+
goto handle_in_userspace;
1268+
12601269
switch (input) {
12611270
case __HYPERVISOR_xen_version:
12621271
if (params[0] == XENVER_version && vcpu->kvm->arch.xen.xen_version) {
@@ -1291,10 +1300,11 @@ int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
12911300
if (handled)
12921301
return kvm_xen_hypercall_set_result(vcpu, r);
12931302

1303+
handle_in_userspace:
12941304
vcpu->run->exit_reason = KVM_EXIT_XEN;
12951305
vcpu->run->xen.type = KVM_EXIT_XEN_HCALL;
12961306
vcpu->run->xen.u.hcall.longmode = longmode;
1297-
vcpu->run->xen.u.hcall.cpl = static_call(kvm_x86_get_cpl)(vcpu);
1307+
vcpu->run->xen.u.hcall.cpl = cpl;
12981308
vcpu->run->xen.u.hcall.input = input;
12991309
vcpu->run->xen.u.hcall.params[0] = params[0];
13001310
vcpu->run->xen.u.hcall.params[1] = params[1];

0 commit comments

Comments
 (0)