Skip to content

Commit b4035b3

Browse files
Xiaoyang Xugregkh
authored andcommitted
vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages
[ Upstream commit 2e6cfd4 ] 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: a54eb55 ("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>
1 parent f54d8a9 commit b4035b3

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/vfio/vfio_iommu_type1.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,
631631

632632
ret = vfio_add_to_pfn_list(dma, iova, phys_pfn[i]);
633633
if (ret) {
634-
vfio_unpin_page_external(dma, iova, do_accounting);
634+
if (put_pfn(phys_pfn[i], dma->prot) && do_accounting)
635+
vfio_lock_acct(dma, -1, true);
635636
goto pin_unwind;
636637
}
637638
}

0 commit comments

Comments
 (0)