From: Keir Fraser Subject: Re: Unsigned bug in rdmsr_hypervisor_regs/wrmsr_hypervisor_regs Date: Thu, 27 Sep 2007 15:28:14 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1805341400==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Robert Phillips , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --===============1805341400== Content-type: multipart/alternative; boundary="B_3273751696_23476957" > This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --B_3273751696_23476957 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit The code is correct as it is. The function returns 1 if it supplies the requested CPUID leaf, else 0. It only currently supplies leaf 0x40000000, so it is correct to return 0 for all other index values. -- Keir On 27/9/07 15:21, "Robert Phillips" wrote: > The code, below, in rdmsr_hypervisor_regs (in xen/arch/x86/traps.c) looks > wrong. (The same code is in wrmsr_hypervisor_regs.) > > int rdmsr_hypervisor_regs( > uint32_t idx, uint32_t *eax, uint32_t *edx) > { > idx -= 0x40000000; > if ( idx > 0 ) > return 0; > ... > > The intent, apparently, is that the function should return zero if the > original idx exceeds 0x40000000. > However because idx is unsigned the function will always return zero unless > the original idx is precisely 0x40000000. > > The effect is that reading or writing any unexpected MSR will cause the guest > to get a GPF. > (The intended effect is, I think, reading any MSR less than 0x40000001 should > simply return 0 > and writing any such MSR should bug. Injecting a GPF should only happen with > MSRs greater than 0x40000000.) > > Replacing the test with > if ( (int32_t)idx > 0 ) > seems to cause problems of its own. > > If this change is wrong, what is a proper fix? > > -- rsp > --B_3273751696_23476957 Content-type: text/html; charset="US-ASCII" Content-transfer-encoding: quoted-printable Re: [Xen-devel] Unsigned bug in rdmsr_hypervisor_regs/wrmsr_hypervis= or_regs The c= ode is correct as it is. The function returns 1 if it supplies the requested= CPUID leaf, else 0. It only currently supplies leaf 0x40000000, so it is co= rrect to return 0 for all other index values.

 -- Keir

On 27/9/07 15:21, "Robert Phillips" <rsp.vi.xen@gmail.com> = wrote:

The code, below, in rdmsr_hypervisor_regs (in xen/arch/= x86/traps.c) looks wrong.  (The same code is in wrmsr_hypervisor_regs.)=

int rdmsr_hypervisor_regs(
    uint32_t idx, uint32_t *eax, uint32_t *edx)
{
    idx -=3D 0x40000000;
    if ( idx > 0 )
        return 0;
...

The intent, apparently, is that the function should return zero if the orig= inal idx exceeds 0x40000000.
However because idx is unsigned the function will always return zero unless= the original idx is precisely 0x40000000.

The effect is that reading or writing any unexpected MSR will cause the gue= st to get a GPF.
(The intended effect is, I think, reading any MSR less than 0x40000001 shou= ld simply return 0
and writing any such MSR should bug.  Injecting a GPF should only happ= en with MSRs greater than 0x40000000.)

Replacing the test with
   if ( (int32_t)idx > 0 )
 seems to cause problems of its own.

If this change is wrong, what is a proper fix?

-- rsp


--B_3273751696_23476957-- --===============1805341400== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1805341400==--