linux/drivers/vfio
Steve Sistare eafb81c50d vfio/type1: prevent underflow of locked_vm via exec()
commit 046eca5018 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-10 09:40:13 +01:00
..
fsl-mc vfio: Use kconfig if XX/endif blocks instead of repeating 'depends on' 2021-08-26 10:36:51 -06:00
mdev VFIO update for v5.15-rc1 2021-09-02 13:41:33 -07:00
pci vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used 2022-04-20 09:34:13 +02:00
platform vfio: platform: Do not pass return buffer to ACPI _RST method 2022-12-31 13:14:27 +01:00
Kconfig vfio: Use kconfig if XX/endif blocks instead of repeating 'depends on' 2021-08-26 10:36:51 -06:00
Makefile
vfio_iommu_spapr_tce.c
vfio_iommu_type1.c vfio/type1: prevent underflow of locked_vm via exec() 2023-03-10 09:40:13 +01:00
vfio_spapr_eeh.c
vfio.c vfio: Clear the caps->buf to NULL after free 2022-08-25 11:40:41 +02:00
virqfd.c