Skip to content

Commit e98137f

Browse files
Alex Williamsonawilliam
authored andcommitted
vfio/pci: Fix double free in dma-buf feature
The error path through vfio_pci_core_feature_dma_buf() ignores its own advice to only use dma_buf_put() after dma_buf_export(), instead falling through the entire unwind chain. In the unlikely event that we encounter file descriptor exhaustion, this can result in an unbalanced refcount on the vfio device and double free of allocated objects. Avoid this by moving the "put" directly into the error path and return the errno rather than entering the unwind chain. Reported-by: Renato Marziano <renato@marziano.top> Fixes: 5d74781 ("vfio/pci: Add dma-buf export support for MMIO regions") Cc: stable@vger.kernel.org Acked-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@nvidia.com> Link: https://lore.kernel.org/r/20260323215659.2108191-3-alex.williamson@nvidia.com Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Alex Williamson <alex@shazbot.org>
1 parent 6de23f8 commit e98137f

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/vfio/pci/vfio_pci_dmabuf.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,10 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
301301
*/
302302
ret = dma_buf_fd(priv->dmabuf, get_dma_buf.open_flags);
303303
if (ret < 0)
304-
goto err_dma_buf;
304+
dma_buf_put(priv->dmabuf);
305+
305306
return ret;
306307

307-
err_dma_buf:
308-
dma_buf_put(priv->dmabuf);
309308
err_dev_put:
310309
vfio_device_put_registration(&vdev->vdev);
311310
err_free_phys:

0 commit comments

Comments
 (0)