[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] x86emul: avoid speculative out of bounds accesses
commit 1f2ccbd40c85e383799d59f9dfc1cffa5e18c920 Author: Jan Beulich <jbeulich@xxxxxxxx> AuthorDate: Thu Jul 4 16:05:18 2019 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Thu Jul 4 16:05:18 2019 +0200 x86emul: avoid speculative out of bounds accesses There are a few array accesses here the indexes of which are (at least indirectly) driven by the guest. Use array_access_nospec() to bound such accesses. In the {,_}decode_gpr() cases replace existing guarding constructs. To deal with an otherwise occurring #include cycle, drop the inclusion of asm/x86_emulate.h from asm/processor.h. This include had been introduced for obtaining the struct cpuid_leaf declaration, which has since moved into the x86 helper library. This is part of the speculative hardening effort. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- xen/arch/x86/x86_emulate.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 4 ++-- xen/arch/x86/x86_emulate/x86_emulate.h | 8 +++++++- xen/include/asm-x86/processor.h | 1 - 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/x86_emulate.c b/xen/arch/x86/x86_emulate.c index d0d52c93c1..e763278012 100644 --- a/xen/arch/x86/x86_emulate.c +++ b/xen/arch/x86/x86_emulate.c @@ -102,7 +102,7 @@ int x86emul_read_dr(unsigned int reg, unsigned long *val, switch ( reg ) { case 0 ... 3: - *val = curr->arch.dr[reg]; + *val = array_access_nospec(curr->arch.dr, reg); break; case 4: diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index 64fe416124..40eb467cb4 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -2235,7 +2235,7 @@ static void *_decode_gpr( ASSERT(modrm_reg < ARRAY_SIZE(byte_reg_offsets)); - /* For safety in release builds. Debug builds will hit the ASSERT() */ + /* Note that this also acts as array_access_nospec() stand-in. */ modrm_reg &= ARRAY_SIZE(byte_reg_offsets) - 1; return (void *)regs + byte_reg_offsets[modrm_reg]; @@ -2985,7 +2985,7 @@ x86_decode( b = insn_fetch_type(uint8_t); opcode |= MASK_INSR(0x8f08 + ext - ext_8f08, X86EMUL_OPC_EXT_MASK); - d = xop_table[ext - ext_8f08]; + d = array_access_nospec(xop_table, ext - ext_8f08); } else { diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h b/xen/arch/x86/x86_emulate/x86_emulate.h index 08645762cc..91f77417b1 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -642,6 +642,12 @@ int x86_emulate_wrapper( #define x86_emulate x86_emulate_wrapper #endif +#ifdef __XEN__ +# include <xen/nospec.h> +#else +# define array_access_nospec(arr, idx) arr[idx] +#endif + /* Map GPRs by ModRM encoding to their offset within struct cpu_user_regs. */ extern const uint8_t cpu_user_regs_gpr_offsets[X86_NR_GPRS]; @@ -658,7 +664,7 @@ static inline unsigned long *decode_gpr(struct cpu_user_regs *regs, ASSERT(modrm < ARRAY_SIZE(cpu_user_regs_gpr_offsets)); - /* For safety in release builds. Debug builds will hit the ASSERT() */ + /* Note that this also acts as array_access_nospec() stand-in. */ modrm &= ARRAY_SIZE(cpu_user_regs_gpr_offsets) - 1; return (void *)regs + cpu_user_regs_gpr_offsets[modrm]; diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h index 6051b92fdb..2862321eee 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -13,7 +13,6 @@ #include <asm/types.h> #include <asm/cpufeature.h> #include <asm/desc.h> -#include <asm/x86_emulate.h> #endif #include <asm/x86-defns.h> -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |