[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] fix undefined bit shifting in mmio emulation path


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
  • From: "He, Qing" <qing.he@xxxxxxxxx>
  • Date: Fri, 23 Mar 2007 18:05:45 +0800
  • Delivery-date: Fri, 23 Mar 2007 03:05:05 -0700
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>
  • Thread-index: AcdtMtJ5C4EEucW2S3ysRNJgN9bDjQ==
  • Thread-topic: [PATCH] fix undefined bit shifting in mmio emulation path

In functions set_eflags_* (xen/arch/x86/hvm/io.c), if the first argument
"size" equals sizeof(long), the following code will produce unintended
and invalid result:
        unsigned long mask = (1 << (8 * size)) - 1;

In ANSI C, if the shift amount is greater or equal to the width of the
data type, the result is undefined. Specifically on x86, a bit mask is
applied to the shift amount, so that more significant bits are ignored.
So the above expression results 0x0 instead of the intended ~0UL.

This patch fixes this issue. Because size=0 is not a valid parameter,
rewriting the code using right shift avoids an additional condition
check.

Signed-off-by: Qing He <qing.he@xxxxxxxxx>

Attachment: mmio_instr_emu_safe_shift.patch
Description: mmio_instr_emu_safe_shift.patch

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.