mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
x86/emul: Correct the decoding of mov to/from cr/dr
The mov to/from cr/dr behave as if they were encoded with Mod = 3. When
encoded with Mod != 3, no displacement or SIB bytes are fetched.
Add a test with a deliberately malformed ModRM byte. (Also add the
automatically-generated simd.h to .gitignore.)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: c2e316b2f2
master date: 2017-03-07 17:29:16 +0000
This commit is contained in:
1 parent
e26a2a0016
commit
049b13dce8
2 files changed
+46
-1
No files matched your search
@@ -163,6 +163,18 @@ static inline uint64_t xgetbv(uint32_t xcr)
|
||||
(ebx & (1U << 5)) != 0; \
|
||||
})
|
||||
|
||||
static int read_segment(
|
||||
enum x86_segment seg,
|
||||
struct segment_register *reg,
|
||||
struct x86_emulate_ctxt *ctxt)
|
||||
{
|
||||
if ( !is_x86_user_segment(seg) )
|
||||
return X86EMUL_UNHANDLEABLE;
|
||||
memset(reg, 0, sizeof(*reg));
|
||||
reg->attr.fields.p = 1;
|
||||
return X86EMUL_OKAY;
|
||||
}
|
||||
|
||||
static int read_cr(
|
||||
unsigned int reg,
|
||||
unsigned long *val,
|
||||
@@ -215,6 +227,7 @@ static struct x86_emulate_ops emulops = {
|
||||
.write = write,
|
||||
.cmpxchg = cmpxchg,
|
||||
.cpuid = cpuid,
|
||||
.read_segment = read_segment,
|
||||
.read_cr = read_cr,
|
||||
.get_fpu = get_fpu,
|
||||
};
|
||||
@@ -732,6 +745,27 @@ int main(int argc, char **argv)
|
||||
goto fail;
|
||||
printf("okay\n");
|
||||
|
||||
printf("%-40s", "Testing mov %%cr4,%%esi (bad ModRM)...");
|
||||
/*
|
||||
* Mod = 1, Reg = 4, R/M = 6 would normally encode a memory reference of
|
||||
* disp8(%esi), but mov to/from cr/dr are special and behave as if they
|
||||
* were encoded with Mod == 3.
|
||||
*/
|
||||
instr[0] = 0x0f; instr[1] = 0x20, instr[2] = 0x66;
|
||||
instr[3] = 0; /* Supposed disp8. */
|
||||
regs.esi = 0;
|
||||
regs.eip = (unsigned long)&instr[0];
|
||||
rc = x86_emulate(&ctxt, &emulops);
|
||||
/*
|
||||
* We don't care precicely what gets read from %cr4 into %esi, just so
|
||||
* long as ModRM is treated as a register operand and 0(%esi) isn't
|
||||
* followed as a memory reference.
|
||||
*/
|
||||
if ( (rc != X86EMUL_OKAY) ||
|
||||
(regs.eip != (unsigned long)&instr[3]) )
|
||||
goto fail;
|
||||
printf("okay\n");
|
||||
|
||||
#define decl_insn(which) extern const unsigned char which[], which##_len[]
|
||||
#define put_insn(which, insn) ".pushsection .test, \"ax\", @progbits\n" \
|
||||
#which ": " insn "\n" \
|
||||
|
||||
@@ -2211,6 +2211,17 @@ x86_decode(
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0x20: /* mov cr,reg */
|
||||
case 0x21: /* mov dr,reg */
|
||||
case 0x22: /* mov reg,cr */
|
||||
case 0x23: /* mov reg,dr */
|
||||
/*
|
||||
* Mov to/from cr/dr ignore the encoding of Mod, and behave as
|
||||
* if they were encoded as reg/reg instructions. No futher
|
||||
* disp/SIB bytes are fetched.
|
||||
*/
|
||||
modrm_mod = 3;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -4759,7 +4770,7 @@ x86_emulate(
|
||||
case X86EMUL_OPC(0x0f, 0x21): /* mov dr,reg */
|
||||
case X86EMUL_OPC(0x0f, 0x22): /* mov reg,cr */
|
||||
case X86EMUL_OPC(0x0f, 0x23): /* mov reg,dr */
|
||||
generate_exception_if(ea.type != OP_REG, EXC_UD, -1);
|
||||
ASSERT(ea.type == OP_REG); /* Early operand adjustment ensures this. */
|
||||
generate_exception_if(!mode_ring0(), EXC_GP, 0);
|
||||
modrm_reg |= lock_prefix << 3;
|
||||
if ( b & 2 )
|
||||
|
||||