Skip to content

Commit 7965919

Browse files
committed
iommu: Don't take group reference in iommu_alloc_default_domain()
The iommu_alloc_default_domain() function takes a reference to an IOMMU group without releasing it. This causes the group to never be released, with undefined side effects. The function has only one call-site, which takes a group reference on its own, so to fix this leak, do not take another reference in iommu_alloc_default_domain() and pass the group as a function parameter instead. Fixes: 6e1aa20 ("iommu: Move default domain allocation to iommu_probe_device()") Reported-by: Sai Prakash Ranjan <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Tested-by: Sai Prakash Ranjan <[email protected]> Cc: Sai Prakash Ranjan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reference: https://lore.kernel.org/lkml/[email protected]/
1 parent 70b8170 commit 7965919

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

drivers/iommu/iommu.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ static bool iommu_cmd_line_dma_api(void)
8080
return !!(iommu_cmd_line & IOMMU_CMD_LINE_DMA_API);
8181
}
8282

83-
static int iommu_alloc_default_domain(struct device *dev);
83+
static int iommu_alloc_default_domain(struct iommu_group *group,
84+
struct device *dev);
8485
static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
8586
unsigned type);
8687
static int __iommu_attach_device(struct iommu_domain *domain,
@@ -251,17 +252,17 @@ int iommu_probe_device(struct device *dev)
251252
if (ret)
252253
goto err_out;
253254

255+
group = iommu_group_get(dev);
256+
if (!group)
257+
goto err_release;
258+
254259
/*
255260
* Try to allocate a default domain - needs support from the
256261
* IOMMU driver. There are still some drivers which don't
257262
* support default domains, so the return value is not yet
258263
* checked.
259264
*/
260-
iommu_alloc_default_domain(dev);
261-
262-
group = iommu_group_get(dev);
263-
if (!group)
264-
goto err_release;
265+
iommu_alloc_default_domain(group, dev);
265266

266267
if (group->default_domain)
267268
ret = __iommu_attach_device(group->default_domain, dev);
@@ -1478,15 +1479,11 @@ static int iommu_group_alloc_default_domain(struct bus_type *bus,
14781479
return 0;
14791480
}
14801481

1481-
static int iommu_alloc_default_domain(struct device *dev)
1482+
static int iommu_alloc_default_domain(struct iommu_group *group,
1483+
struct device *dev)
14821484
{
1483-
struct iommu_group *group;
14841485
unsigned int type;
14851486

1486-
group = iommu_group_get(dev);
1487-
if (!group)
1488-
return -ENODEV;
1489-
14901487
if (group->default_domain)
14911488
return 0;
14921489

0 commit comments

Comments
 (0)