Linux IOMMU Development
 help / color / mirror / Atom feed
* [RFC PATCH] iommu/vt-d: Add sanity check to iommu_sva_bind_device()
@ 2022-10-13 15:33 Jerry Snitselaar
  2022-10-13 15:37 ` Jerry Snitselaar
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Jerry Snitselaar @ 2022-10-13 15:33 UTC (permalink / raw)
  To: iommu, linux-kernel; +Cc: Joerg Roedel, Will Deacon, Robin Murphy, Lu Baolu

iommu_sva_bind_device() should only be called if
iommu_dev_enable_feature() succeeded. There has been one case already
where that hasn't been the case, which resulted in a null pointer
deref in dev_iommu_ops(). To avoid that happening in the future if
another driver makes that mistake, sanity check dev->iommu and
dev->iommu->iommu_dev prior to calling dev_iommu_ops().

Cc: Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
---
drivers/iommu/iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 4893c2429ca5..20ec75667529 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2746,7 +2746,15 @@ iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata)
 {
 	struct iommu_group *group;
 	struct iommu_sva *handle = ERR_PTR(-EINVAL);
-	const struct iommu_ops *ops = dev_iommu_ops(dev);
+	const struct iommu_ops *ops;
+
+	if (!dev->iommu || !dev->iommu->iommu_dev) {
+		dev_warn(dev, "%s called without checking succes of iommu_dev_enable_feature?\n",
+			__func__);
+		return ERR_PTR(-ENODEV);
+	}
+
+	ops = dev_iommu_ops(dev);
 
 	if (!ops->sva_bind)
 		return ERR_PTR(-ENODEV);
-- 
2.37.2


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

end of thread, other threads:[~2022-10-14 16:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-13 15:33 [RFC PATCH] iommu/vt-d: Add sanity check to iommu_sva_bind_device() Jerry Snitselaar
2022-10-13 15:37 ` Jerry Snitselaar
2022-10-13 16:33 ` Jerry Snitselaar
2022-10-13 17:13 ` [RFC PATCH v2] iommu: " Jerry Snitselaar
2022-10-14  1:52 ` [RFC PATCH] iommu/vt-d: " Baolu Lu
2022-10-14  2:10   ` Jerry Snitselaar
2022-10-14  2:22     ` Baolu Lu
2022-10-14  6:52       ` Jerry Snitselaar
2022-10-14 11:01         ` Robin Murphy
2022-10-14 15:25           ` Jerry Snitselaar
2022-10-14 16:50             ` Jerry Snitselaar

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