Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp233253pxx; Wed, 28 Oct 2020 03:36:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB8XrmbWv/WPHPLKkKA8KieNCcTI4AI1Ik8XAv06AGhVrJhzsZ2ZFI0yOpSc2WSzwZ1tW1 X-Received: by 2002:a17:906:a250:: with SMTP id bi16mr6334191ejb.265.1603881388982; Wed, 28 Oct 2020 03:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603881388; cv=none; d=google.com; s=arc-20160816; b=k7KF9EQNDazkprpcRfNOAMFiAfcHj6+2XGm3H4VJ7xyDU5VwDpnZqo8Qm+kEkmb2MW aZ2A3GB9dGYAzUqUKHiX25nu3fx2s26TRybGn/mrkbFWFEqMod9vfeM93GJx1+dH0JGx 7sqHCv5eintux60w0YDab2VtzzNAnZ9A0e5uinTzeYjmrmbEhPA+jV+J9cCEaFDFTZwW XRiJrGT2FfBaLQieoPEFkalxzDzVBuibuI3A5RHRbMKQ0nHaOKvtiX7MmYMZ+zOLOxS5 pMo28aapMkFs3EfgFMpUVM3kg/XH0+KZlpvCTpFeXZe7Bf8UTOsZshtYnKdE6AeBP5GX +KnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rckpf3E8D4xqy9dp1G7enugoMyoKlYul1xCef8KJf5I=; b=hxSqzdJW7yImO0U6YOlXJylaapzHmGmWJMechX37OKgxYjCZ6kvby5PhiX/wCr+EWh Mw0z0P5mNvtYGOr23RV90rdlUUIRrgSgsv/DySYEy5jP9A15arUry/5/T8lzq31rHEGd TZTpqkjOTpZQ++z29hnLG9u9Q55ZusW93SgC1I8OBQFnGF+HUNo/iLXqg9DR4tpi2Q8u yD1NvsLVjby89PAtz4TjUXMVZT8edQ4DdYL2lcteCFuH6q8l3DpgZJPWzFbhrg10/KL1 15TP/1s32lvO1liGJOlmhav0FRb16+I5sLgJyBdXeXnhlk2p0/zt3U09ZsYQ3t1EmdAl Xc9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R8SuN+BM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p17si2879649ejg.48.2020.10.28.03.36.06; Wed, 28 Oct 2020 03:36:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R8SuN+BM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762674AbgJ0OoA (ORCPT + 99 others); Tue, 27 Oct 2020 10:44:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:41714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762330AbgJ0OmI (ORCPT ); Tue, 27 Oct 2020 10:42:08 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9394B21D7B; Tue, 27 Oct 2020 14:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809728; bh=yRM82I+6u7DGFMoDjo+E1l6C32AScqshhd5DqhVuvIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R8SuN+BMDDuIVl/xuUxURv0BZcOn+ragxEOzzhFUKCRQ/56Yy5YgFKQsr6Z4LNkTV 2NKrUmgEpz183uhqmYdc9CH9NVRPfcTJ1ejZqaNslSVtylFEGpfEtcriToadlBoUgo yUNpFNWSQ0l/HhTRzwiO559blaHaTZx0z/O6IKYA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoyang Xu , Alex Williamson , Sasha Levin Subject: [PATCH 5.4 281/408] vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages Date: Tue, 27 Oct 2020 14:53:39 +0100 Message-Id: <20201027135508.082675862@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoyang Xu [ 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 [aw: simplified logic, add Fixes] Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- 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 c6220f57fdf3e..3b31e83a92155 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -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; } } -- 2.25.1