vfio/pci: Add missing range check in vfio_pci_mmap
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20210412140238.184e141f@omen
PATCH 1/1 vfio/pci: Add missing range check in vfio_pci_mmap
When mmaping an extra device region verify that the region index derived from the mmap offset is valid.
Fixes a15b1883fee1 ("vfio_pci: Allow mapping extra regions")
Signed-off-by Christian A. Ehrhardt <[email protected]>
--- drivers/vfio/pci/vfio_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci.c +3 -1
@@ -1656,6 +1656,8 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT -PAGE_SHIFT ); +if (index >=VFIO_PCI_NUM_REGIONS + vdev->num_regions) +return -EINVAL ;if (vma->vm_end < vma->vm_start)return -EINVAL ;if ((vma->vm_flags &VM_SHARED ) ==0 )
@@ -1664,7 +1666,7 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)int regnum = index -VFIO_PCI_NUM_REGIONS ;struct vfio_pci_region *region = vdev->region + regnum; -if (region && region->ops && region->ops->mmap && +if (region->ops && region->ops->mmap && (region->flags &VFIO_REGION_INFO_FLAG_MMAP ))return region->ops->mmap (vdev, region, vma);return -EINVAL ;
Signature · 1 line
2.25.1
Quoted 7 lines · Christian A. Ehrhardt
When mmaping an extra device region verify that the region index derived from the mmap offset is valid.
Fixes a15b1883fee1 ("vfio_pci: Allow mapping extra regions")Signed-off-by Christian A. Ehrhardt <[email protected]>
Reviewed-by David Gibson <[email protected]>
Quoted 26 lines
--- drivers/vfio/pci/vfio_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/vfio/pci/vfio_pci.c +3
-1@@ -1656,6 +1656,8 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT -PAGE_SHIFT ); +if (index >=VFIO_PCI_NUM_REGIONS + vdev->num_regions) +return -EINVAL ;if (vma->vm_end < vma->vm_start)return -EINVAL ;if ((vma->vm_flags &VM_SHARED ) ==0 )@@ -1664,7 +1666,7 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)int regnum = index -VFIO_PCI_NUM_REGIONS ;struct vfio_pci_region *region = vdev->region + regnum; -if (region && region->ops && region->ops->mmap && +if (region->ops && region->ops->mmap && (region->flags &VFIO_REGION_INFO_FLAG_MMAP ))return region->ops->mmap (vdev, region, vma);return -EINVAL ;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 9 lines · On Mon, 12 Apr 2021 23:41:24 +0200 "Christian A. Ehrhardt" <[email protected]> wrote:
When mmaping an extra device region verify that the region index derived from the mmap offset is valid.
Fixes a15b1883fee1 ("vfio_pci: Allow mapping extra regions")Signed-off-by Christian A. Ehrhardt <[email protected]>--- drivers/vfio/pci/vfio_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by Cornelia Huck <[email protected]>