linux-next/drivers/vfio
Steve Sistare 046eca5018 vfio/type1: prevent underflow of locked_vm via exec()
When a vfio container is preserved across exec, the task does not change,
but it gets a new mm with locked_vm=0, and loses the count from existing
dma mappings.  If the user later unmaps a dma mapping, locked_vm underflows
to a large unsigned value, and a subsequent dma map request fails with
ENOMEM in __account_locked_vm.

To avoid underflow, grab and save the mm at the time a dma is mapped.
Use that mm when adjusting locked_vm, rather than re-acquiring the saved
task's mm, which may have changed.  If the saved mm is dead, do nothing.

locked_vm is incremented for existing mappings in a subsequent patch.

Fixes: 73fa0d10d0 ("vfio: Type1 IOMMU implementation")
Cc: stable@vger.kernel.org
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/1675184289-267876-3-git-send-email-steven.sistare@oracle.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
2023-02-09 11:39:14 -07:00
..
fsl-mc vfio/fsl-mc: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations 2023-01-23 11:26:30 -07:00
mdev vfio/mdev: Use sysfs_emit() to instead of sprintf() 2023-01-30 12:16:13 -07:00
pci vfio/mlx5: Improve the target side flow to reduce downtime 2023-01-30 12:16:15 -07:00
platform vfio: platform: ignore missing reset if disabled at module init 2023-02-01 12:25:41 -07:00
container.c vfio: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations 2023-01-23 11:26:29 -07:00
group.c Driver Core changes for 6.2-rc1 2022-12-16 03:54:54 -08:00
iommufd.c vfio-iommufd: Support iommufd for emulated VFIO devices 2022-12-02 11:52:03 -04:00
iova_bitmap.c vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries 2022-12-02 10:09:25 -07:00
Kconfig VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
Makefile VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
vfio_iommu_spapr_tce.c vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c 2022-12-05 12:04:32 -07:00
vfio_iommu_type1.c vfio/type1: prevent underflow of locked_vm via exec() 2023-02-09 11:39:14 -07:00
vfio_main.c VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
vfio.h VFIO updates for v6.2-rc1 2022-12-15 13:12:15 -08:00
virqfd.c vfio: Use GFP_KERNEL_ACCOUNT for userspace persistent allocations 2023-01-23 11:26:29 -07:00