From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] target/i386: trap on instructions longer than >15 bytes
Date: Thu, 12 Oct 2017 23:43:53 +0200 [thread overview]
Message-ID: <f5592714-d129-9580-57d7-06de323503d8@redhat.com> (raw)
In-Reply-To: <449dd7e8-42cd-fd4a-da2b-35f22552bc39@linaro.org>
On 12/10/2017 21:30, Richard Henderson wrote:
> On 10/12/2017 07:35 AM, Paolo Bonzini wrote:
>> Besides being more correct, arbitrarily long instruction allow the
>> generation of a translation block that spans three pages. This
>> confuses the generator and even allows ring 3 code to poison the
>> translation block cache and inject code into other processes that are
>> in guest ring 3.
>>
>> This is an improved (and more invasive) fix for the bug fixed in commit
>> 30663fd ("tcg/i386: Check the size of instruction being translated",
>> 2017-03-24). In addition to being more precise (and generating the
>> right exception, which is #GP rather than #UD), it distinguishes better
>> between page faults and too long instructions, as shown by this test case:
>>
>> #include <sys/mman.h>
>> #include <string.h>
>> #include <stdio.h>
>>
>> int main()
>> {
>> char *x = mmap(NULL, 8192, PROT_READ|PROT_WRITE|PROT_EXEC,
>> MAP_PRIVATE|MAP_ANON, -1, 0);
>> memset(x, 0x66, 4096);
>> x[4096] = 0x90;
>> x[4097] = 0xc3;
>> char *i = x + 4096 - 15;
>> mprotect(x + 4096, 4096, PROT_READ|PROT_WRITE);
>> ((void(*)(void)) i) ();
>> }
>>
>> ... which produces a #GP without the mprotect, and a #PF with it.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> target/i386/translate.c | 29 ++++++++++++++++++++++-------
>> 1 file changed, 22 insertions(+), 7 deletions(-)
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
>> + if (sigsetjmp(s->jmpbuf, 0) != 0) {
>
> Any particular reason to use sigsetjmp(x, 0) instead of setjmp(x)?
> Certainly there are no signal frames that the longjmp will pass...
sigsetjmp is used to _not_ save the signal mask. On OS X setjmp saves
the signal mask by default, which is slower.
Paolo
next prev parent reply other threads:[~2017-10-12 21:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-12 14:35 [Qemu-devel] [PATCH 0/2] target/i386: trap on instructions longer than >15 bytes Paolo Bonzini
2017-10-12 14:35 ` [Qemu-devel] [PATCH 1/2] target/i386: introduce x86_ld*_code Paolo Bonzini
2017-10-12 16:30 ` Richard Henderson
2017-10-12 14:35 ` [Qemu-devel] [PATCH 2/2] target/i386: trap on instructions longer than >15 bytes Paolo Bonzini
2017-10-12 19:30 ` Richard Henderson
2017-10-12 21:43 ` Paolo Bonzini [this message]
2017-10-13 18:12 ` Richard Henderson
2017-10-12 16:55 ` [Qemu-devel] [PATCH 0/2] " no-reply
2017-10-12 19:07 ` no-reply
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=f5592714-d129-9580-57d7-06de323503d8@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).