1
0
Fork 0

vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages

[ Upstream commit 2e6cfd496f ]

pfn is not added to pfn_list when vfio_add_to_pfn_list fails.
vfio_unpin_page_external will exit directly without calling
vfio_iova_put_vfio_pfn.  This will lead to a memory leak.

Fixes: a54eb55045 ("vfio iommu type1: Add support for mediated devices")
Signed-off-by: Xiaoyang Xu <xuxiaoyang2@huawei.com>
[aw: simplified logic, add Fixes]
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
5.4-rM2-2.2.x-imx-squashed
Xiaoyang Xu 2020-10-16 17:35:58 +08:00 committed by Greg Kroah-Hartman
parent f54d8a9e37
commit b4035b3d64
1 changed files with 2 additions and 1 deletions

View File

@ -631,7 +631,8 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,
ret = vfio_add_to_pfn_list(dma, iova, phys_pfn[i]);
if (ret) {
vfio_unpin_page_external(dma, iova, do_accounting);
if (put_pfn(phys_pfn[i], dma->prot) && do_accounting)
vfio_lock_acct(dma, -1, true);
goto pin_unwind;
}
}