* [PATCH] iommu/dma: Fix leak in non-contiguous API
@ 2021-07-23 1:05 Ezequiel Garcia
2021-07-23 5:09 ` Christoph Hellwig
2021-07-26 12:27 ` Joerg Roedel
0 siblings, 2 replies; 3+ messages in thread
From: Ezequiel Garcia @ 2021-07-23 1:05 UTC (permalink / raw)
To: iommu, linux-media
Cc: Will Deacon, stable, Ricardo Ribalda, kernel, Ezequiel Garcia,
Christoph Hellwig
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 <ezequiel@collabora.com>
---
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 4e34e8b26579..16c06a1aab80 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.32.0
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iommu/dma: Fix leak in non-contiguous API
2021-07-23 1:05 [PATCH] iommu/dma: Fix leak in non-contiguous API Ezequiel Garcia
@ 2021-07-23 5:09 ` Christoph Hellwig
2021-07-26 12:27 ` Joerg Roedel
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-07-23 5:09 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: stable, iommu, Ricardo Ribalda, kernel, Will Deacon,
Christoph Hellwig, linux-media
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
> 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 :-)
linux/dma-map-ops.h is a helper header for the dma_ops implementations,
not for users of the DMA API. sgt_handle, which references
dma_sgt_handle is used in kernel/dma/mapping.c
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iommu/dma: Fix leak in non-contiguous API
2021-07-23 1:05 [PATCH] iommu/dma: Fix leak in non-contiguous API Ezequiel Garcia
2021-07-23 5:09 ` Christoph Hellwig
@ 2021-07-26 12:27 ` Joerg Roedel
1 sibling, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2021-07-26 12:27 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: stable, iommu, Ricardo Ribalda, kernel, Will Deacon,
Christoph Hellwig, linux-media
On Thu, Jul 22, 2021 at 10:05:52PM -0300, Ezequiel Garcia wrote:
> drivers/iommu/dma-iommu.c | 1 +
> 1 file changed, 1 insertion(+)
Applied to iommu/fixes, thanks.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-26 12:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 1:05 [PATCH] iommu/dma: Fix leak in non-contiguous API Ezequiel Garcia
2021-07-23 5:09 ` Christoph Hellwig
2021-07-26 12:27 ` Joerg Roedel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).