diff options
| author | Matt Evans <mattev@meta.com> | 2026-05-11 17:58:24 +0300 |
|---|---|---|
| committer | Alex Williamson <alex@shazbot.org> | 2026-05-14 20:39:03 +0300 |
| commit | 702809dabdecca807bdd50cfdcc1c980feb2ba62 (patch) | |
| tree | dbbe83b2e8867cd6415020c4a7ab68960fb06a0f | |
| parent | 05f2a68b407a6817fe141dd64972c6ab8725312d (diff) | |
| download | linux-702809dabdecca807bdd50cfdcc1c980feb2ba62.tar.xz | |
vfio/pci: Check BAR resources before exporting a DMABUF
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 <mattev@meta.com>
Link: https://lore.kernel.org/r/20260511145829.2993601-3-mattev@meta.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
| -rw-r--r-- | drivers/vfio/pci/vfio_pci_dmabuf.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c index fdc22e8b4656..1a177ce7de54 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 || + vfio_pci_core_setup_barmap(vdev, get_dma_buf.region_index)) return -ENODEV; dma_ranges = memdup_array_user(&arg->dma_ranges, get_dma_buf.nr_ranges, |
