From: "Jan Beulich" Subject: [PATCH] x86/HVM: only kill guest when unknown VM exit occurred in guest kernel mode Date: Thu, 30 Oct 2014 14:43:21 +0000 Message-ID: <54525C990200007800043915@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartB98CB299.2__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Xjqwc-0004Xx-Kv for xen-devel@lists.xenproject.org; Thu, 30 Oct 2014 14:43:22 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Kevin Tian , suravee.suthikulpanit@amd.com, Eddie Dong , Aravind Gopalakrishnan , Jun Nakajima , Boris Ostrovsky List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartB98CB299.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline A recent KVM change by Nadav Amit pointed out that unconditional VM exits (like VMX'es ones for the INVEPT, INVVPID, and XSETBV instructions) may result from guest user mode activity (in the example cases, e.g. prior to a privilege level check being done). Consequently convert the unconditional domain_crash() to a conditional one (when guest is in kernel mode) with the alternative of injecting #UD (when in user mode). This is meant to be a precaution against in-guest security issues introduced when any such VM exit becomes possible (on newer hardware) without the hypervisor immediately being aware of it. There are no such unhandled VM exits currently (and hence this is not an active security issue), but old (no longer security maintained) versions exhibit issues in the cases given as examples above. Suggested-by: Tim Deegan Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2680,7 +2680,11 @@ void svm_vmexit_handler(struct cpu_user_ "exitinfo1 =3D %#"PRIx64", exitinfo2 =3D %#"PRIx64"\n", exit_reason,=20 (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2); - domain_crash(v->domain); + if ( vmcb_get_cpl(vmcb) ) + hvm_inject_hw_exception(TRAP_invalid_op, + HVM_DELIVER_NO_ERROR_CODE); + else + domain_crash(v->domain); break; } =20 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -3157,8 +3157,19 @@ void vmx_vmexit_handler(struct cpu_user_ /* fall through */ default: exit_and_crash: - gdprintk(XENLOG_ERR, "Bad vmexit (reason %#lx)\n", exit_reason); - domain_crash(v->domain); + { + struct segment_register ss; + + gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n", + exit_reason); + + vmx_get_segment_register(v, x86_seg_ss, &ss); + if ( ss.attr.fields.dpl ) + hvm_inject_hw_exception(TRAP_invalid_op, + HVM_DELIVER_NO_ERROR_CODE); + else + domain_crash(v->domain); + } break; } =20 --=__PartB98CB299.2__= Content-Type: text/plain; name="x86-HVM-unknown-exits-user-mode.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HVM-unknown-exits-user-mode.patch" x86/HVM: only kill guest when unknown VM exit occurred in guest kernel = mode=0A=0AA recent KVM change by Nadav Amit = pointed out=0Athat unconditional VM exits (like VMX'es ones for the = INVEPT, INVVPID,=0Aand XSETBV instructions) may result from guest user = mode activity (in=0Athe example cases, e.g. prior to a privilege level = check being done).=0AConsequently convert the unconditional domain_crash() = to a conditional=0Aone (when guest is in kernel mode) with the alternative = of injecting=0A#UD (when in user mode).=0A=0AThis is meant to be a = precaution against in-guest security issues=0Aintroduced when any such VM = exit becomes possible (on newer hardware)=0Awithout the hypervisor = immediately being aware of it. There are no such=0Aunhandled VM exits = currently (and hence this is not an active security=0Aissue), but old (no = longer security maintained) versions exhibit issues=0Ain the cases given = as examples above.=0A=0ASuggested-by: Tim Deegan =0ASigned-off= -by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/svm/svm.c= =0A+++ b/xen/arch/x86/hvm/svm/svm.c=0A@@ -2680,7 +2680,11 @@ void = svm_vmexit_handler(struct cpu_user_=0A "exitinfo1 =3D = %#"PRIx64", exitinfo2 =3D %#"PRIx64"\n",=0A exit_reason, = =0A (u64)vmcb->exitinfo1, (u64)vmcb->exitinfo2);=0A- = domain_crash(v->domain);=0A+ if ( vmcb_get_cpl(vmcb) )=0A+ = hvm_inject_hw_exception(TRAP_invalid_op,=0A+ = HVM_DELIVER_NO_ERROR_CODE);=0A+ else=0A+ = domain_crash(v->domain);=0A break;=0A }=0A =0A--- a/xen/arch/x8= 6/hvm/vmx/vmx.c=0A+++ b/xen/arch/x86/hvm/vmx/vmx.c=0A@@ -3157,8 +3157,19 = @@ void vmx_vmexit_handler(struct cpu_user_=0A /* fall through */=0A = default:=0A exit_and_crash:=0A- gdprintk(XENLOG_ERR, "Bad = vmexit (reason %#lx)\n", exit_reason);=0A- domain_crash(v->domain);= =0A+ {=0A+ struct segment_register ss;=0A+=0A+ = gdprintk(XENLOG_WARNING, "Bad vmexit (reason %#lx)\n",=0A+ = exit_reason);=0A+=0A+ vmx_get_segment_register(v, = x86_seg_ss, &ss);=0A+ if ( ss.attr.fields.dpl )=0A+ = hvm_inject_hw_exception(TRAP_invalid_op,=0A+ = HVM_DELIVER_NO_ERROR_CODE);=0A+ else=0A+ = domain_crash(v->domain);=0A+ }=0A break;=0A }=0A =0A --=__PartB98CB299.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartB98CB299.2__=--