From: Andrew Cooper Date: Thu, 25 Sep 2014 10:06:24 +0000 (+0200) Subject: x86/hvm: Forced Emulation Prefix for debug builds of Xen X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~4330 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1efde771adb6685dcf6fa7e3c4889dee863c950f;p=xen.git x86/hvm: Forced Emulation Prefix for debug builds of Xen Analysis of XSAs 105 and 106 show that is possible to force a race condition which causes any arbitrary instruction to be emulated. To aid testing, explicitly introduce the Forced Emulation Prefix for debug builds alone. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown index af93e17ba6..389701a347 100644 --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -682,6 +682,17 @@ Bit 11 - MSR operation logging Recognized in debug builds of the hypervisor only. +### hvm\_fep +> `= ` + +> Default: `false` + +Allow use of the Forced Emulation Prefix in HVM guests, to allow emulation of +arbitrary instructions. + +This option is intended for development purposes, and is only available in +debug builds of the hypervisor. + ### hvm\_port80 > `= ` diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 5c7e0a46d0..34f28d0fcd 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -86,6 +86,11 @@ unsigned long __attribute__ ((__section__ (".bss.page_aligned"))) static bool_t __initdata opt_hap_enabled = 1; boolean_param("hap", opt_hap_enabled); +#ifndef opt_hvm_fep +bool_t opt_hvm_fep; +boolean_param("hvm_fep", opt_hvm_fep); +#endif + static int cpu_callback( struct notifier_block *nfb, unsigned long action, void *hcpu) { diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 5d404cea6e..30af10d8e2 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2069,6 +2069,19 @@ static void svm_vmexit_ud_intercept(struct cpu_user_regs *regs) struct hvm_emulate_ctxt ctxt; int rc; + if ( opt_hvm_fep ) + { + char sig[5]; /* ud2; .ascii "xen" */ + + if ( (hvm_fetch_from_guest_virt_nofault( + sig, regs->eip, sizeof(sig), 0) == HVMCOPY_okay) && + (memcmp(sig, "\xf\xbxen", sizeof(sig)) == 0) ) + { + regs->eip += sizeof(sig); + regs->eflags &= ~X86_EFLAGS_RF; + } + } + hvm_emulate_prepare(&ctxt, regs); rc = hvm_emulate_one(&ctxt); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 84119edce9..923f0082ec 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2499,6 +2499,19 @@ static void vmx_vmexit_ud_intercept(struct cpu_user_regs *regs) struct hvm_emulate_ctxt ctxt; int rc; + if ( opt_hvm_fep ) + { + char sig[5]; /* ud2; .ascii "xen" */ + + if ( (hvm_fetch_from_guest_virt_nofault( + sig, regs->eip, sizeof(sig), 0) == HVMCOPY_okay) && + (memcmp(sig, "\xf\xbxen", sizeof(sig)) == 0) ) + { + regs->eip += sizeof(sig); + regs->eflags &= ~X86_EFLAGS_RF; + } + } + hvm_emulate_prepare(&ctxt, regs); rc = hvm_emulate_one(&ctxt); diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 3e66276bbe..c0fbc8bd16 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -517,6 +517,13 @@ bool_t nhvm_vmcx_hap_enabled(struct vcpu *v); /* interrupt */ enum hvm_intblk nhvm_interrupt_blocked(struct vcpu *v); +#ifndef NDEBUG +/* Permit use of the Forced Emulation Prefix in HVM guests */ +extern bool_t opt_hvm_fep; +#else +#define opt_hvm_fep 0 +#endif + #endif /* __ASM_X86_HVM_HVM_H__ */ /*