Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2895592pxb; Tue, 24 Aug 2021 10:04:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6M0alAQy2NEYNGU5BrT9FkbGqCRrSF5J74Q/iLlygTCwhxKZEvJRVzwdT5loKrqI9nDGy X-Received: by 2002:a05:6638:f87:: with SMTP id h7mr7178434jal.77.1629824676617; Tue, 24 Aug 2021 10:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824676; cv=none; d=google.com; s=arc-20160816; b=N8QWkwyFns9RbW9logbIRKwpFWYFFM+ff1L4L2h+73gCzHldXfO2axMLy03Qr/mbf4 CK31hSuRLhDy0bg4mXRaJtjqZ37IN2F0AhRjpPRD1e1ZGD2hB0BUblIZ/Mdb1Vf9dzQD hVTskt0rA5vsytxqrprNMNd5DYzdc/HDFVnBq6dd5FuM0/qyb18+Q3T/uxt2U9MvhWL7 sCYlQcvtAd3QZRQfbWKDdXyeHOZQn44zSf8UGOUSQqR0pTd+xmo00McBbCl/bLTCaKGV N7g0S9F3TNrM2espWwr8/LR/VR5W3Z1lp7bUQ9c1+Iq8U5xUn/jwzPEz8Q4NM5RDnsN7 eQCg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ocP02oKzTb9FpYcV7lIykc/jOVNqBJwlfZWTqEW+C+A=; b=pupn7fgtwae3OL7NhYndXhjss5PDPzhxdVupGwoK1xzVlRTR6jbkQLSMBeC7rG1TNk 2CsiJAH5MBeEgxmInL/YRyo/+d6zsOy4naqP7d30r7CDYcDDU1tgH0BJJwxwYEQIs6pg ASsJVsTviDiBN6duox/9gzWPgVAzAFcsNWpG5jL3lfXXfSCyEhCF3Af9pLKTsGqPcovC OZbb3oKPlspfiuP9y79Z0ngxJpfSXWU4jsPSMaKCUklyBMZqBBeOf88udSujLdR0rbMw btoeWOG6xeIrMzyBV8GSmScByAnyzBi5ljsr3AipcJhiVsnMHvYGvHlD3BAOk5RQa6yZ xoqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hylBdZKY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a10si12588170ios.4.2021.08.24.10.04.23; Tue, 24 Aug 2021 10:04:36 -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=k20201202 header.b=hylBdZKY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236525AbhHXRCc (ORCPT + 99 others); Tue, 24 Aug 2021 13:02:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:38858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238912AbhHXQ7M (ORCPT ); Tue, 24 Aug 2021 12:59:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1DDB7611AF; Tue, 24 Aug 2021 16:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824252; bh=oE9uR7V4OH3XiW1tDEuMmOgRU8YCLANasm1e6deDn3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hylBdZKYVWfY6xXo8fYncrevYHaN/7ssXQMN9PIIRjv29zX0XRvYCB2NAQjSpKOfw Tz6uceUYPBxfvbSglJ/qS1ZMGyMKh28T7Oj9UzTvOLUkE5YIWLA8V85Cxd/TxATG8b YzIPDfn3GVkwlpwjTsoUV6XpfEhFp3tHznO0b+jH4RX9bu2wCoiUrLH36p5n1xhuWO 7QkQvihSBv9olfGvDP79HgS+P5vxjYv89tnYkkUAUC7L9C++/4DbzTjl8PWpJ1xchL jVxHsWnr2MXu3raPFpai24+Nfdwb1zOUDB6wnGikv+WycOQYehfCM58mDqqEX0GWzq t9ylvY9CcMj3g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ezequiel Garcia , Christoph Hellwig , Joerg Roedel , Sasha Levin Subject: [PATCH 5.13 085/127] iommu/dma: Fix leak in non-contiguous API Date: Tue, 24 Aug 2021 12:55:25 -0400 Message-Id: <20210824165607.709387-86-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ezequiel Garcia [ Upstream commit 0fbea680540108b09db7b26d9f4d24236d58a6ad ] Currently, iommu_dma_alloc_noncontiguous() allocates a struct dma_sgt_handle object to hold some state needed for iommu_dma_free_noncontiguous(). However, the handle is neither freed nor returned explicitly by the ->alloc_noncontiguous method, and therefore seems leaked. This was found by code inspection, so please review carefully and test. As a side note, it appears the struct dma_sgt_handle type is exposed to users of the DMA-API by linux/dma-map-ops.h, but is has no users or functions returning the type explicitly. This may indicate it's a good idea to move the struct dma_sgt_handle type to drivers/iommu/dma-iommu.c. The decision is left to maintainers :-) Cc: stable@vger.kernel.org Fixes: e817ee5f2f95c ("dma-iommu: implement ->alloc_noncontiguous") Signed-off-by: Ezequiel Garcia Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20210723010552.50969-1-ezequiel@collabora.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/dma-iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 5d96fcc45fec..698707699327 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -768,6 +768,7 @@ static void iommu_dma_free_noncontiguous(struct device *dev, size_t size, __iommu_dma_unmap(dev, sgt->sgl->dma_address, size); __iommu_dma_free_pages(sh->pages, PAGE_ALIGN(size) >> PAGE_SHIFT); sg_free_table(&sh->sgt); + kfree(sh); } #endif /* CONFIG_DMA_REMAP */ -- 2.30.2