Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp189572pxx; Wed, 28 Oct 2020 02:11:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzmvUT5EHRT9bfzSgKXR93UbGAAOhwOMeHRdYKw2npQXp9D5GAQUD0w+UHgO8iM66RCoQV X-Received: by 2002:a17:906:af87:: with SMTP id mj7mr6559356ejb.178.1603876277788; Wed, 28 Oct 2020 02:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603876277; cv=none; d=google.com; s=arc-20160816; b=SmPf6lZc8iZKvHHVXzseTCUiML44ezHYiQAfoiqzZXZCtfQO+VAh1zNjC0Adk98Z36 BuLbo6o3kFvkPT0sUjR+2WOvIXXSCZGYKTcJfPglDuslqm/oR/RdC1054857wxpwcbz5 0KlyuRMARMStI8MdJMvKcU2OkjI+mGGfWxPTcV/Qm8qclfJ4vGT9GDLFKsRJW06pHmZd CkiAObDaTaoVa6Qlwc9k51WiThERyE/8sZdEElHkAe3G8wKUaadtYYqMlr5Ka4mgdMlU MlAY/FyNg7pCYm1E2LM7XpMS/eqlGoPlLIaX8hBz8AfBX3HdQLhae6QUa3/yXH+fw8EV yzZQ== 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=BjamAAbO//97wrJf9KDiJ+uiojumlCwIgMevaWKmL6Y=; b=LwTttTcnyhGMhXTZp6FfILGmneVVNCoAbuYTxgdrYn09K3XJAzTB0zfyF+8mpbHVgH WwStZVNGMd2hAEAKIX0TFsxJaEyLULVcB3t6zlIc+G1KG6bdiNtIgvEK3d8SDdFdXYQl n/M+0A8HGXyA3qIgLrYhgDTVzaBhoH9PYtuQUw3jKvAVfoi/0qRfco6DBAiIbSjv+Leb /d6X/kT9dldLjqpi2bprSuZbghbM7c6ZsgKrgSDJ/QM7hAWJcJpkj7EW9RApdBdMIiUo aStqYMr+ZeF7sbwCMYGrHfuBxTP61TNsF4mp4ltcmsJMUmvdITJLMgXyrJFPbc7T11w0 +khA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="LRaCi/CG"; 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 g8si3473416ejm.389.2020.10.28.02.10.56; Wed, 28 Oct 2020 02:11:17 -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="LRaCi/CG"; 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 S1757244AbgJ0ORB (ORCPT + 99 others); Tue, 27 Oct 2020 10:17:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:34586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2507323AbgJ0ONO (ORCPT ); Tue, 27 Oct 2020 10:13:14 -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 B97962072D; Tue, 27 Oct 2020 14:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807994; bh=5+ZEnv38tX0bSTtZFBcShu/N2igvDJs0/DWtyflHcmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LRaCi/CGVorR69MnI8GHFnyXwzzvHb+yWXe1zQHHO/G57s1mty8K31DfZMUfSg9lj G/SO7FiLq3M6ciajO8xIRPQzJa8Bl1Ng37ggqdU7/wdrYoIFl2qNTd0wtpeYQn3rwY QpkDWDrds0q+sK27CAi6bhDt0ktPihd6Eu9q2bz0= 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 4.14 118/191] vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages Date: Tue, 27 Oct 2020 14:49:33 +0100 Message-Id: <20201027134915.373064109@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134909.701581493@linuxfoundation.org> References: <20201027134909.701581493@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 9c8ed9d7f9aa5..bfbe5236239bd 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -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; } } -- 2.25.1