qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: andrew@andrewoates.com, rth@twiddle.net, ehabkost@redhat.com,
	qemu-devel@nongnu.org
Cc: Andrew Oates <aoates@google.com>
Subject: Re: [Qemu-devel] [PATCH] target-i386: fix segment limit check in ljmp
Date: Fri, 17 Aug 2018 19:38:37 +0200	[thread overview]
Message-ID: <b45d87b9-38ac-427a-8622-ac9c49350511@redhat.com> (raw)
In-Reply-To: <20180816011903.39816-1-andrew@andrewoates.com>

On 16/08/2018 03:19, andrew@andrewoates.com wrote:
> From: Andrew Oates <aoates@google.com>
> 
> The current implementation has three bugs,
>  * segment limits are not enforced in protected mode if the L bit is set
>    in the target segment descriptor[1]
>  * segment limits are not enforced in compatability mode (ljmp to 32-bit
>    code segment in long mode)
>  * #GP(new_cs) is generated rather than #GP(0)
> 
> Now the segment limits are enforced if we're not in long mode OR the
> target code segment doesn't have the L bit set.
> 
> [1] this is an invalid configuration (in protected mode the L bit is
> reserved and should be set to zero), but qemu doesn't enforce that.

Stupid question, why not fix that instead at least for this case?

> Signed-off-by: Andrew Oates <aoates@google.com>
> ---
> The limit check is still incorrect for ljmp-through-call-gate in 64-bit
> mode.  That's a larger fix I'm still working on.

Can you resend the call-gate for both ljmp and lcall when you're done
(there's plenty of time until 3.1)?

Thanks,

Paolo

>  target/i386/seg_helper.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/i386/seg_helper.c b/target/i386/seg_helper.c
> index 00301a0c04..975365fd30 100644
> --- a/target/i386/seg_helper.c
> +++ b/target/i386/seg_helper.c
> @@ -1628,8 +1628,8 @@ void helper_ljmp_protected(CPUX86State *env, int new_cs, target_ulong new_eip,
>          }
>          limit = get_seg_limit(e1, e2);
>          if (new_eip > limit &&
> -            !(env->hflags & HF_LMA_MASK) && !(e2 & DESC_L_MASK)) {
> -            raise_exception_err_ra(env, EXCP0D_GPF, new_cs & 0xfffc, GETPC());
> +            (!(env->hflags & HF_LMA_MASK) || !(e2 & DESC_L_MASK))) {
> +            raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC());
>          }
>          cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl,
>                         get_seg_base(e1, e2), limit, e2);
> 

  reply	other threads:[~2018-08-17 17:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-16  1:19 [Qemu-devel] [PATCH] target-i386: fix segment limit check in ljmp andrew
2018-08-17 17:38 ` Paolo Bonzini [this message]
2018-08-17 18:04   ` Andrew Oates
2018-08-20 10:06     ` Paolo Bonzini
2018-08-20 11:32       ` Andrew Oates
2018-08-20 11:55         ` Paolo Bonzini

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=b45d87b9-38ac-427a-8622-ac9c49350511@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=andrew@andrewoates.com \
    --cc=aoates@google.com \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).