Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp284185pxx; Wed, 28 Oct 2020 05:01:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNl87+TVXLGPKuZ7LHbh9D9vv7/ep6TL5uVHk+7UVBMjKA0XlacZqUx3jmK8iuz0Ft8ZJ7 X-Received: by 2002:a17:906:4306:: with SMTP id j6mr7433384ejm.523.1603886479552; Wed, 28 Oct 2020 05:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603886479; cv=none; d=google.com; s=arc-20160816; b=fqHYoFIj9CJp6jiW8S9TWqbLxXND/2enFOKYM4oaZWYQdp7PdurI2XajZZnVhq4bPx WGeU8///3Hp/ZMCmzWS549Oqc5EjGTss3CsBjW8Kf4jj44nbRALY1aovSuZ728CgzbJ5 LaryN8IBp3Ji4TzD2bEwy6xWCV/0PJvirior2iAD27mpRCDH9No16RlE9haeRtlC4yXa hy/zgvlB5SBgoWKKQEIk6QLvzzkPRXjnrr+NW3tizT4X4ATW6QQKPBALqvGaBo+eFNwq IizN5ixBNFm4CdK6FknOWf9MkD5it3RQOt1YOF87A3rOTAoKXSJruuc977MQCvEpq/fB Q30Q== 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=F33tZpVQULpmlegUHp90R6G8Z1wx4Ah9uwH6xkMpilA=; b=Wqkqh5qqBYB9PUl2e8Adq/Gtzfilxm+eBSkGwzFKyd30Vf3HqO1bMZT5rhkVdvrOcw Jxt8n+/3nSCIQsmI9Mz37HL7H8unykWOS6DgIpkFRwAcUCjog2oSZxbPB0p4lYR1tMyV rZHB3R3mW3bQNgdG+6G2Rbg48ex3cQ4Wv2QLCddzTfVYtsMNYHa9GtR7n+tVRBsh8RJl fvq60bb86pXllDj+e0SlNMO1RWtQWr03aNawQIcrwyEW9nhfeoG9bcLCscxxpQohH+np cJmKqLOgBLCxKxP2bNxx6NnXkeg1xKyKDPRavF/YWltfNB2WFlQ/UDKhmI54MxYCebC/ J3Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U7HO0Pit; 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 f19si2736409edx.542.2020.10.28.05.00.56; Wed, 28 Oct 2020 05:01:19 -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=U7HO0Pit; 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 S1795021AbgJ0POy (ORCPT + 99 others); Tue, 27 Oct 2020 11:14:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:44628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1793916AbgJ0PJJ (ORCPT ); Tue, 27 Oct 2020 11:09:09 -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 E074C206F4; Tue, 27 Oct 2020 15:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811349; bh=xY4tDXnwwKQuGgM7gkuKXttAzi3VIUbCG+AB6r+fZOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U7HO0PitKK09giS5xN6yhLe62H/aN6N1wK2+WEXsvf6QfBQs2m+D2Ja6fFv51c1n8 1M+TczU4Ju/xZVkhWrDYGH0Dg1FJ0VAdTcWt6sTnJhjoN9GCytPVuJtSjgn+dfPino WnCywUeVXjp3T6XRTv6ApzLy5s5sxjVUcJbhdD4o= 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.8 462/633] vfio iommu type1: Fix memory leak in vfio_iommu_type1_pin_pages Date: Tue, 27 Oct 2020 14:53:25 +0100 Message-Id: <20201027135544.395337555@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 eb7bb14e4f62a..00d3cf12e92c3 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