diff options
author | Alexandru Elisei <alexandru.elisei@arm.com> | 2020-04-14 15:39:41 +0100 |
---|---|---|
committer | Will Deacon <will@kernel.org> | 2020-04-15 16:27:17 +0100 |
commit | 3665392ae3929c81ff48d306e56eea5fa0567c17 (patch) | |
tree | 8e0afdc7b19ed2884b34f6770897381fd9b0d91e | |
parent | 5b7fef16262a09d37be4760fca1bfbb4edd48984 (diff) | |
download | kvmtool-3665392ae3929c81ff48d306e56eea5fa0567c17.tar.gz |
vfio/pci: Don't access unallocated regions
Don't try to configure a BAR if there is no region associated with it.
Also move the variable declarations from inside the loop to the start of
the function for consistency.
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r-- | vfio/pci.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -645,16 +645,19 @@ static int vfio_pci_parse_cfg_space(struct vfio_device *vdev) static int vfio_pci_fixup_cfg_space(struct vfio_device *vdev) { int i; + u64 base; ssize_t hdr_sz; struct msix_cap *msix; struct vfio_region_info *info; struct vfio_pci_device *pdev = &vdev->pci; + struct vfio_region *region; /* Initialise the BARs */ for (i = VFIO_PCI_BAR0_REGION_INDEX; i <= VFIO_PCI_BAR5_REGION_INDEX; ++i) { - u64 base; - struct vfio_region *region = &vdev->regions[i]; + if ((u32)i == vdev->info.num_regions) + break; + region = &vdev->regions[i]; /* Construct a fake reg to match what we've mapped. */ if (region->is_ioport) { base = (region->port_base & PCI_BASE_ADDRESS_IO_MASK) | @@ -853,11 +856,12 @@ static int vfio_pci_configure_bar(struct kvm *kvm, struct vfio_device *vdev, u32 bar; size_t map_size; struct vfio_pci_device *pdev = &vdev->pci; - struct vfio_region *region = &vdev->regions[nr]; + struct vfio_region *region; if (nr >= vdev->info.num_regions) return 0; + region = &vdev->regions[nr]; bar = pdev->hdr.bar[nr]; region->vdev = vdev; |