On Thu, 30 Apr 2026 03:03:22 -0700
Matt Evans <[email protected]> wrote:
> A DMABUF exports access to BAR resources and, although they are
> requested at startup time, we need to ensure they really were reserved
> before exporting. Otherwise, it's possible to access unreserved
> resources through the export.
>
> Add a check to the DMABUF-creation path.
>
> Fixes: 5d74781ebc86c ("vfio/pci: Add dma-buf export support for MMIO regions")
> Signed-off-by: Matt Evans <[email protected]>
> ---
> drivers/vfio/pci/vfio_pci_dmabuf.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c
> b/drivers/vfio/pci/vfio_pci_dmabuf.c
> index f87fd32e4a01..3bc7d850e258 100644
> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
> @@ -244,9 +244,11 @@ int vfio_pci_core_feature_dma_buf(struct
> vfio_pci_core_device *vdev, u32 flags,
> return -EINVAL;
>
> /*
> - * For PCI the region_index is the BAR number like everything else.
> + * For PCI the region_index is the BAR number like everything
> + * else. Check that PCI resources have been claimed for it.
> */
> - if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX)
> + if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX ||
> + !IS_ERR(vfio_pci_core_get_iomap(vdev, get_dma_buf.region_index)))
Polarity of the test is wrong, should just be IS_ERR().
It would be good practice here to front-load the Fixes: patches in your
series. I'd suggest making this patch #2, using the existing
setup_barmap API, then include it in the conversion to iomap in patch
#3. Thanks,
Alex