]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages
authorXiaoyang Xu <xuxiaoyang2@huawei.com>
Fri, 16 Oct 2020 09:35:58 +0000 (17:35 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 08:07:12 +0000 (09:07 +0100)
[ Upstream commit 2e6cfd496f5b57034cf2aec738799571b5a52124 ]

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: a54eb55045ae ("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>
drivers/vfio/vfio_iommu_type1.c

index 9c8ed9d7f9aa5297fd7c3c027d69959bf3335948..bfbe5236239bd23533d3c2b738e22f44a8a4c896 100644 (file)
@@ -629,7 +629,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;
                }
        }