From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Razvan Cojocaru <rcojocaru@bitdefender.com>, xen-devel@lists.xen.org
Cc: ian.jackson@eu.citrix.com, ian.campbell@citrix.com,
JBeulich@suse.com, stefano.stabellini@eu.citrix.com
Subject: Re: [PATCH] tools/tests: Add EIP check to test_x86_emulator.c
Date: Thu, 07 Aug 2014 09:18:38 +0100 [thread overview]
Message-ID: <53E3365E.5030507@citrix.com> (raw)
In-Reply-To: <1407399362-4106-1-git-send-email-rcojocaru@bitdefender.com>
On 07/08/2014 09:16, Razvan Cojocaru wrote:
> The test now also checks that EIP was modified after emulating
> instructions after (and including) the "movq %mm3,(%ecx)..."
> code block.
>
> Signed-off-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
These checks do check that the instruction pointer has changed, which
catches your problem, but doesn't check that it has changed correctly.
You need to work out exactly how long the instruction is a verify that
eip points to first byte of the next instruction.
~Andrew
> ---
> tools/tests/x86_emulator/test_x86_emulator.c | 30 +++++++++++++++++---------
> 1 file changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/tools/tests/x86_emulator/test_x86_emulator.c b/tools/tests/x86_emulator/test_x86_emulator.c
> index 0a00d5a..dd4e986 100644
> --- a/tools/tests/x86_emulator/test_x86_emulator.c
> +++ b/tools/tests/x86_emulator/test_x86_emulator.c
> @@ -615,7 +615,8 @@ int main(int argc, char **argv)
> regs.eip = (unsigned long)&instr[0];
> regs.ecx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) )
> + if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> printf("okay\n");
> }
> @@ -637,7 +638,8 @@ int main(int argc, char **argv)
> regs.ecx = 0;
> regs.edx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( rc != X86EMUL_OKAY )
> + if ( rc != X86EMUL_OKAY ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> asm ( "pcmpeqb %%mm3, %%mm3\n\t"
> "pcmpeqb %%mm5, %%mm3\n\t"
> @@ -665,7 +667,8 @@ int main(int argc, char **argv)
> regs.eip = (unsigned long)&instr[0];
> regs.ecx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) )
> + if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> printf("okay\n");
> }
> @@ -687,7 +690,8 @@ int main(int argc, char **argv)
> regs.ecx = 0;
> regs.edx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( rc != X86EMUL_OKAY )
> + if ( rc != X86EMUL_OKAY ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> asm ( "pcmpeqb %%xmm2, %%xmm2\n\t"
> "pcmpeqb %%xmm4, %%xmm2\n\t"
> @@ -716,7 +720,8 @@ int main(int argc, char **argv)
> regs.eip = (unsigned long)&instr[0];
> regs.ecx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 16, 64) )
> + if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 16, 64) ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> printf("okay\n");
> }
> @@ -744,7 +749,8 @@ int main(int argc, char **argv)
> regs.ecx = 0;
> regs.edx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( rc != X86EMUL_OKAY )
> + if ( rc != X86EMUL_OKAY ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> #if 0 /* Don't use AVX2 instructions for now */
> asm ( "vpcmpeqb %%ymm2, %%ymm2, %%ymm2\n\t"
> @@ -784,7 +790,8 @@ int main(int argc, char **argv)
> regs.ecx = (unsigned long)(res + 2);
> regs.edx = 0;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) )
> + if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> printf("okay\n");
> }
> @@ -809,7 +816,8 @@ int main(int argc, char **argv)
> regs.ecx = 0;
> regs.edx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( rc != X86EMUL_OKAY )
> + if ( rc != X86EMUL_OKAY ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> asm ( "cmpeqps %1, %%xmm7\n\t"
> "movmskps %%xmm7, %0" : "=r" (rc) : "m" (res[8]) );
> @@ -837,7 +845,8 @@ int main(int argc, char **argv)
> regs.ecx = (unsigned long)(res + 2);
> regs.edx = 0;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) )
> + if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> printf("okay\n");
> }
> @@ -862,7 +871,8 @@ int main(int argc, char **argv)
> regs.ecx = 0;
> regs.edx = (unsigned long)res;
> rc = x86_emulate(&ctxt, &emulops);
> - if ( rc != X86EMUL_OKAY )
> + if ( rc != X86EMUL_OKAY ||
> + (regs.eip == (unsigned long)&instr[0]) )
> goto fail;
> asm ( "vcmpeqps %1, %%ymm7, %%ymm0\n\t"
> "vmovmskps %%ymm0, %0" : "=r" (rc) : "m" (res[8]) );
next prev parent reply other threads:[~2014-08-07 8:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-07 8:16 [PATCH] tools/tests: Add EIP check to test_x86_emulator.c Razvan Cojocaru
2014-08-07 8:18 ` Andrew Cooper [this message]
2014-08-07 8:32 ` Jan Beulich
2014-08-07 8:35 ` Razvan Cojocaru
2014-08-07 8:45 ` Jan Beulich
2014-08-07 8:53 ` Razvan Cojocaru
2014-08-07 9:17 ` Razvan Cojocaru
2014-08-07 9:35 ` Andrew Cooper
2014-08-07 8:23 ` Jürgen Groß
2014-08-07 8:27 ` Razvan Cojocaru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53E3365E.5030507@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=rcojocaru@bitdefender.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.