lkml.org 
[lkml]   [2020]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.9 555/757] vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages
    Date
    From: Xiaoyang Xu <xuxiaoyang2@huawei.com>

    [ 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 | 3 ++-
    1 file changed, 2 insertions(+), 1 deletion(-)

    diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
    index d0438388feebe..9dde5ed852fd0 100644
    --- a/drivers/vfio/vfio_iommu_type1.c
    +++ b/drivers/vfio/vfio_iommu_type1.c
    @@ -693,7 +693,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;
    }

    --
    2.25.1


    \
     
     \ /
      Last update: 2020-10-27 17:41    [W:3.098 / U:0.064 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site