iommu: Fix refcount leak in iommu_device_claim_dma_owner
PATCH 1/1 iommu: Fix refcount leak in iommu_device_claim_dma_owner
iommu_group_get() returns the group with the reference incremented. Also an empty @owner is a more serious problem than refcount leak. Move iommu_group_get() after owner check to fix the refcount leak.
---
changes in v2:
- Remove set NULL to group as suggested by Baolu Lu.
- Update commit message according to Lu's explanation.
--- drivers/iommu/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iommu/iommu.c +5 -3
@@ -3185,14 +3185,16 @@ EXPORT_SYMBOL_GPL(iommu_group_claim_dma_owner);*/ int iommu_device_claim_dma_owner (struct device *dev,void *owner) { -struct iommu_group *group =iommu_group_get (dev); +struct iommu_group *group;int ret =0 ; -if (!group) -return -ENODEV ;if (WARN_ON (!owner))return -EINVAL ; + group =iommu_group_get (dev); +if (!group) +return -ENODEV ; +mutex_lock (&group->mutex);if (group->owner_cnt) {if (group->owner != owner) {
Signature · 1 line
2.25.1
Quoted 6 lines · Miaoqian Lin
iommu_group_get()returns the group with the reference incremented. Also an empty @owner is a more serious problem than refcount leak. Moveiommu_group_get()after owner check to fix the refcount leak.Fixes 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")Signed-off-by Miaoqian Lin <[email protected]>
Quoted 7 lines
---
changes in v2:
- Remove set NULL to group as suggested by Baolu Lu.
- Update commit message according to Lu's explanation.--- drivers/iommu/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
Joerg, can you pick this for rc?
Thanks,
Jason