* [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner
@ 2023-01-03 6:30 Miaoqian Lin
2023-01-03 23:12 ` Jason Gunthorpe
0 siblings, 1 reply; 5+ messages in thread
From: Miaoqian Lin @ 2023-01-03 6:30 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu, Eric Auger,
Jason Gunthorpe, Kevin Tian, iommu, linux-kernel
Cc: linmq006
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.
Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
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(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index de91dd88705b..5f6a85aea501 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -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) {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner
2023-01-03 6:30 [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner Miaoqian Lin
@ 2023-01-03 23:12 ` Jason Gunthorpe
0 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2023-01-03 23:12 UTC (permalink / raw)
To: Miaoqian Lin
Cc: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu, Eric Auger,
Kevin Tian, iommu, linux-kernel
On Tue, Jan 03, 2023 at 10:30:17AM +0400, Miaoqian Lin wrote:
> 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.
>
> Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> 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(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Joerg, can you pick this for rc?
Thanks,
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner
2022-12-30 8:31 Miaoqian Lin
2023-01-03 1:26 ` Baolu Lu
@ 2023-01-13 12:39 ` Joerg Roedel
1 sibling, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2023-01-13 12:39 UTC (permalink / raw)
To: Miaoqian Lin
Cc: Will Deacon, Robin Murphy, Lu Baolu, Kevin Tian, Eric Auger,
Jason Gunthorpe, iommu, linux-kernel
On Fri, Dec 30, 2022 at 12:31:00PM +0400, Miaoqian Lin wrote:
> iommu_group_get() returns the group with the reference incremented.
> Move iommu_group_get() after owner check to fix the refcount leak.
>
> Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> drivers/iommu/iommu.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
Applied for 6.2, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner
2022-12-30 8:31 Miaoqian Lin
@ 2023-01-03 1:26 ` Baolu Lu
2023-01-13 12:39 ` Joerg Roedel
1 sibling, 0 replies; 5+ messages in thread
From: Baolu Lu @ 2023-01-03 1:26 UTC (permalink / raw)
To: Miaoqian Lin, Joerg Roedel, Will Deacon, Robin Murphy,
Kevin Tian, Eric Auger, Jason Gunthorpe, iommu, linux-kernel
Cc: baolu.lu
On 12/30/22 4:31 PM, Miaoqian Lin wrote:
> iommu_group_get() returns the group with the reference incremented.
> Move iommu_group_get() after owner check to fix the refcount leak.
An empty @owner is a more serious problem than refcount leak. It should
not happen, so a WARN_ON() was added there.
Anyway, your change makes the code better.
>
> Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> drivers/iommu/iommu.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index de91dd88705b..3a7dd8b61fab 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -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 = NULL;
No need to set NULL to 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) {
Others look good to me.
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
--
Best regards,
baolu
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner
@ 2022-12-30 8:31 Miaoqian Lin
2023-01-03 1:26 ` Baolu Lu
2023-01-13 12:39 ` Joerg Roedel
0 siblings, 2 replies; 5+ messages in thread
From: Miaoqian Lin @ 2022-12-30 8:31 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu, Kevin Tian,
Eric Auger, Jason Gunthorpe, iommu, linux-kernel
Cc: linmq006
iommu_group_get() returns the group with the reference incremented.
Move iommu_group_get() after owner check to fix the refcount leak.
Fixes: 89395ccedbc1 ("iommu: Add device-centric DMA ownership interfaces")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/iommu/iommu.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index de91dd88705b..3a7dd8b61fab 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -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 = NULL;
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) {
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-13 12:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03 6:30 [PATCH] iommu: Fix refcount leak in iommu_device_claim_dma_owner Miaoqian Lin
2023-01-03 23:12 ` Jason Gunthorpe
-- strict thread matches above, loose matches on Subject: below --
2022-12-30 8:31 Miaoqian Lin
2023-01-03 1:26 ` Baolu Lu
2023-01-13 12:39 ` Joerg Roedel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.