Skip to contentSkip to conversation

iommu: Fix error unwind in iommu_group_alloc()

PATCH Applied Jason Gunthorpe 3 participants 3 messages Feb 16, 2023 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu: Fix error unwind in iommu_group_alloc()

If either iommu_group_grate_file() fails then then the iommu_group is leaked.

Destroy it on these error paths.

Found by kselftest/iommu/iommufd_fail_nth

Fixes bc7d12b91bd3 ("iommu: Implement reserved_regions iommu-group sysfs file")
Fixes c52c72d3dee8 ("iommu: Add sysfs attribyte for domain type")
---
 drivers/iommu/iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +6 -2
index dd9b60897c8673..e41c9df1504ba3 100644
@@ -775,12 +775,16 @@ struct iommu_group *iommu_group_alloc(void)
 
 	ret = iommu_group_create_file(group,
 				      &iommu_group_attr_reserved_regions);
-	if (ret)
+	if (ret) {
+		kobject_put(group->devices_kobj);
 		return ERR_PTR(ret);
+	}
 
 	ret = iommu_group_create_file(group, &iommu_group_attr_type);
-	if (ret)
+	if (ret) {
+		kobject_put(group->devices_kobj);
 		return ERR_PTR(ret);
+	}
 
 	pr_debug("Allocated group %d\n", group->id);
 

base-commit: c643eb52cb7c1f6747ddc60d8a187a3ca0746a12

Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Jason Gunthorpe

If either iommu_group_grate_file() fails then then the iommu_group

iommu_group_create_file()

Quoted 9 lines

is leaked.

Destroy it on these error paths.

Found by kselftest/iommu/iommufd_fail_nth

Fixes bc7d12b91bd3 ("iommu: Implement reserved_regions iommu-group sysfs file")
Fixes c52c72d3dee8 ("iommu: Add sysfs attribyte for domain type")

Other look good to me.

Best regards,
baolu

Quoted 29 lines
---
  drivers/iommu/iommu.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +6 -2
index dd9b60897c8673..e41c9df1504ba3 100644
@@ -775,12 +775,16 @@ struct iommu_group *iommu_group_alloc(void)
 
  	ret = iommu_group_create_file(group,
  				      &iommu_group_attr_reserved_regions);
-	if (ret)
+	if (ret) {
+		kobject_put(group->devices_kobj);
  		return ERR_PTR(ret);
+	}
 
  	ret = iommu_group_create_file(group, &iommu_group_attr_type);
-	if (ret)
+	if (ret) {
+		kobject_put(group->devices_kobj);
  		return ERR_PTR(ret);
+	}
 
  	pr_debug("Allocated group %d\n", group->id);
 

base-commit: c643eb52cb7c1f6747ddc60d8a187a3ca0746a12

Applied
#2 lore raw
In reply to Jason Gunthorpe
Quoted 5 lines · Jason Gunthorpe

If either iommu_group_grate_file() fails then then the iommu_group is leaked.

Destroy it on these error paths.

Quoted 8 lines

Found by kselftest/iommu/iommufd_fail_nth

Fixes bc7d12b91bd3 ("iommu: Implement reserved_regions iommu-group sysfs file")
Fixes c52c72d3dee8 ("iommu: Add sysfs attribyte for domain type")
---
 drivers/iommu/iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Applied, thanks.