From: Alex Williamson Date: Tue, 28 Apr 2015 17:14:02 +0000 (-0600) Subject: vfio-pci: Further fix BAR size overflow X-Git-Tag: TizenStudio_2.0_p2.3.2~208^2~220^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07ceaf98800519ef9c5dc893af00f1fe1f9144e4;p=sdk%2Femulator%2Fqemu.git vfio-pci: Further fix BAR size overflow In an analysis by Laszlo, the resulting type of our calculation for the end of the MSI-X table, and thus the start of memory after the table, is uint32_t. We're therefore not correctly preventing the corner case overflow that we intended to fix here where a BAR >=4G could place the MSI-X table to end exactly at the 4G boundary. The MSI-X table offset is defined by the hardware spec to 32bits, so we simply use a cast rather than changing data structure types. This scenario is purely theoretically, typically the MSI-X table is located at the front of the BAR. Reported-by: Laszlo Ersek Reviewed-by: Laszlo Ersek Signed-off-by: Alex Williamson --- diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index cd15b20..495f5fd 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2400,7 +2400,7 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr) if (vdev->msix && vdev->msix->table_bar == nr) { uint64_t start; - start = HOST_PAGE_ALIGN(vdev->msix->table_offset + + start = HOST_PAGE_ALIGN((uint64_t)vdev->msix->table_offset + (vdev->msix->entries * PCI_MSIX_ENTRY_SIZE)); size = start < bar->region.size ? bar->region.size - start : 0;