Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH v2 iommu/next] iommu: Fix default domain setup
@ 2023-06-19  8:49 Vasant Hegde
  2023-06-19 11:31 ` Jason Gunthorpe
  2023-06-20  6:31 ` Baolu Lu
  0 siblings, 2 replies; 9+ messages in thread
From: Vasant Hegde @ 2023-06-19  8:49 UTC (permalink / raw)
  To: iommu, joro
  Cc: suravee.suthikulpanit, baolu.lu, Vasant Hegde,
	Dheeraj Kumar Srivastava, Jason Gunthorpe

Commit 1000dccd5d13 ("iommu: Allow IOMMU_RESV_DIRECT to work on ARM")
accidently restored "group->domain" to "old_domain" while keeping
"group->default_domain" to new domain. Also freed new domain.

This works fine during boot as 'old_domain' is NULL. But if we try
change domain via sysfs using below command then kernel crashes with
"kernel NULL pointer dereference".

Change domain command :
  - Go to /sys/kernel/iommu_groups/<group id>/
  - Unbind device driver for all devices in the group
  - echo "<dom type>" > /sys/kernel/iommu_groups/<group id>/type

Fix above described issue by handling error path properly.

Reported-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Fixes: 1000dccd5d13 ("iommu: Allow IOMMU_RESV_DIRECT to work on ARM")
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Tested-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
Changes in v2:
  - Addressed review comments from Baolu

@Joerg,
  This patch applies on top of iommu/next branch.

-Vasant
 drivers/iommu/iommu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9e0228ef612b..e74e45f42c75 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2915,10 +2915,15 @@ static int iommu_setup_default_domain(struct iommu_group *group,
 		}
 	}
 
+	if (old_dom)
+		iommu_domain_free(old_dom);
+	return ret;
+
 err_restore:
 	if (old_dom) {
 		__iommu_group_set_domain_internal(
 			group, old_dom, IOMMU_SET_DOMAIN_MUST_SUCCEED);
+		group->default_domain = old_dom;
 		iommu_domain_free(dom);
 		old_dom = NULL;
 	}
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-06-23  4:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-19  8:49 [PATCH v2 iommu/next] iommu: Fix default domain setup Vasant Hegde
2023-06-19 11:31 ` Jason Gunthorpe
2023-06-20  5:11   ` Vasant Hegde
2023-06-20  6:31 ` Baolu Lu
2023-06-20 11:42   ` Jason Gunthorpe
2023-06-22  4:59     ` Vasant Hegde
2023-06-22 13:55       ` Jason Gunthorpe
2023-06-23  3:08         ` Baolu Lu
2023-06-23  4:38         ` Vasant Hegde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox