Re: [PATCH v2 kvmtool 14/30] vfio/pci: Don't access potentially unallocated regions

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

 



Hi,

On 1/29/20 6:17 PM, Andre Przywara wrote:
> On Thu, 23 Jan 2020 13:47:49 +0000
> Alexandru Elisei <alexandru.elisei@xxxxxxx> wrote:
>
> Hi,
>
>> Don't try to configure a BAR if there is no region associated with it.
>>
>> Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx>
>> ---
>>  vfio/pci.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/vfio/pci.c b/vfio/pci.c
>> index 1f38f90c3ae9..f86a7d9b7032 100644
>> --- a/vfio/pci.c
>> +++ b/vfio/pci.c
>> @@ -652,6 +652,8 @@ static int vfio_pci_fixup_cfg_space(struct vfio_device *vdev)
>>  
>>  	/* Initialise the BARs */
>>  	for (i = VFIO_PCI_BAR0_REGION_INDEX; i <= VFIO_PCI_BAR5_REGION_INDEX; ++i) {
>> +		if ((u32)i == vdev->info.num_regions)
>> +			break;
> My inner check-patch complains that we should not have code before declarations.
> Can we solve this the same way as below?

Sure, I'll change it and update the commit message accordingly.

Thanks, Alex

>
> Cheers,
> Andre
>
>
>>  		u64 base;
>>  		struct vfio_region *region = &vdev->regions[i];
>>  
>> @@ -853,11 +855,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;



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux