All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Chris Lalancette <clalance@redhat.com>
Cc: mingo@redhat.com, x86@kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] Make sure get_user_desc() doesn't sign extend.
Date: Wed, 21 Oct 2009 11:52:57 +0200	[thread overview]
Message-ID: <4ADED9F9.3040006@redhat.com> (raw)
In-Reply-To: <1256110829-4188-1-git-send-email-clalance@redhat.com>

On 10/21/2009 09:40 AM, Chris Lalancette wrote:
> The current implementation of get_user_desc() sign extends
> the return value because of integer promotion rules.  For
> the most part, this doesn't matter, because the top bit of
> base2 is usually 0.  If, however, that bit is 1, then the
> entire value will be 0xffff... which is probably not what
> the caller intended.  This patch casts the entire thing
> to unsigned before returning, which generates almost the
> same assembly as the current code but replaces the final
> "cltq" (sign extend) with a "mov %eax %eax" (zero-extend).
> This fixes booting certain guests under KVM.

For the record, the reason why this wasn't noticed so far is that 
get_user_desc will be zero outside KVM except if used for FS and GS. 
KVM with the right guest will easily see a 0xC0000000 segment base, but 
you would need TLS data allocated above 2 GB to see the bug outside KVM. 
  TLS data is in the same mmap-ed memory that hosts the thread stacks, 
so it will typically be below the 2 GB mark and have its most 
significant bit cleared.

I suppose you could see the bug if you used pthread_attr_setstack, plus 
of course all the right circumstances---which are rare because all but 
the most obscure users anyway cast the result to u32.

Paolo

  reply	other threads:[~2009-10-21  9:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21  7:40 [PATCH] Make sure get_user_desc() doesn't sign extend Chris Lalancette
2009-10-21  9:52 ` Paolo Bonzini [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-10-23 11:20 Chris Lalancette

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=4ADED9F9.3040006@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=clalance@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=x86@kernel.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.