Skip to contentSkip to conversation

More IOMMU Fixes

PATCH In review Joerg Roedel 2 participants 5 messages Aug 21, 2014 IOMMU

lore
Share & tools
lore

Joerg Roedel

author maintainer
#0 lore raw

cover More IOMMU Fixes

Hi,

here are two patches that fix valid issues discovered by Coverity. Please review.

Thanks,

Joerg

Joerg Roedel (2):
iommu: Make iommu_group_get_for_dev() more robust iommu/vt-d: Check return value of acpi_bus_get_device()

 drivers/iommu/dmar.c  | 3 +--
 drivers/iommu/iommu.c | 8 +++++---
 2 files changed, 6 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH 1/2 iommu: Make iommu_group_get_for_dev() more robust

From: Joerg Roedel <[email protected]>

When a non-PCI device is passed to that function it might pass group == NULL to iommu_group_add_device() which then dereferences it and cause a crash this way. Fix it by just returning an error for non-PCI devices.

Fixes 104a1c13ac66e40cf8c6ae74d76ff14ff24b9b01
Cc Alex Williamson <[email protected]>
---
 drivers/iommu/iommu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iommu/iommu.c +5 -3
index 1698360..ef8da12 100644
@@ -678,15 +678,17 @@ static struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev)
  */
 struct iommu_group *iommu_group_get_for_dev(struct device *dev)
 {
-	struct iommu_group *group = ERR_PTR(-EIO);
+	struct iommu_group *group;
 	int ret;
 
 	group = iommu_group_get(dev);
 	if (group)
 		return group;
 
-	if (dev_is_pci(dev))
-		group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
+	if (!dev_is_pci(dev))
+		return ERR_PTR(-EINVAL);
+
+	group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
 
 	if (IS_ERR(group))
 		return group;
Signature · 1 line
1.9.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] iommu: Make iommu_group_get_for_dev() more robust

Quoted 19 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

When a non-PCI device is passed to that function it might pass group == NULL to iommu_group_add_device() which then dereferences it and cause a crash this way. Fix it by just returning an error for non-PCI devices.

Fixes 104a1c13ac66e40cf8c6ae74d76ff14ff24b9b01
Cc Alex Williamson <[email protected]>
---
 drivers/iommu/iommu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/iommu/iommu.c +0 -0
index 1698360..ef8da12 100644

drivers/iommu/iommu.c static struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev) · line 686

Quoted 10 lines
drivers/iommu/iommu.c +1 -1
@@ -678,15 +678,17 @@ static struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev)
  */
 struct iommu_group *iommu_group_get_for_dev(struct device *dev)
 {
-	struct iommu_group *group = ERR_PTR(-EIO);
+	struct iommu_group *group;
 	int ret;
 
 	group = iommu_group_get(dev);
 	if (group)
 		return group;

Hmm, I bet I had a second pointer for this case but mistakenly optimized it out refining the patch. This solution works too though.

Thanks!
Alex

Quoted 10 lines
drivers/iommu/iommu.c +4 -2
-	if (dev_is_pci(dev))
-		group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
+	if (!dev_is_pci(dev))
+		return ERR_PTR(-EINVAL);
+
+	group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
 
 	if (IS_ERR(group))
 		return group;
author maintainer
#3 lore raw

PATCH 2/2 iommu/vt-d: Check return value of acpi_bus_get_device()

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

Checking adev == NULL is not sufficient as acpi_bus_get_device() might not touch the value of this parameter in an error case, so check the return value directly.

Fixes ed40356b5fcf1ce28e026ab39c5b2b6939068b50
Cc David Woodhouse <[email protected]>
---
 drivers/iommu/dmar.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/dmar.c +1 -2
index 60ab474..06d268a 100644
@@ -678,8 +678,7 @@ static int __init dmar_acpi_dev_scope_init(void)
 				       andd->device_name);
 				continue;
 			}
-			acpi_bus_get_device(h, &adev);
-			if (!adev) {
+			if (acpi_bus_get_device(h, &adev)) {
 				pr_err("Failed to get device for ACPI object %s\n",
 				       andd->device_name);
 				continue;
Signature · 1 line
1.9.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] iommu/vt-d: Check return value of acpi_bus_get_device()

Quoted 19 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

Checking adev == NULL is not sufficient as acpi_bus_get_device() might not touch the value of this parameter in an error case, so check the return value directly.

Fixes ed40356b5fcf1ce28e026ab39c5b2b6939068b50
Cc David Woodhouse <[email protected]>
---
 drivers/iommu/dmar.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/dmar.c +0 -0
index 60ab474..06d268a 100644

drivers/iommu/dmar.c static int __init dmar_acpi_dev_scope_init(void) · line 684

Quoted 9 lines
drivers/iommu/dmar.c +1 -2
@@ -678,8 +678,7 @@ static int __init dmar_acpi_dev_scope_init(void)
 				       andd->device_name);
 				continue;
 			}
-			acpi_bus_get_device(h, &adev);
-			if (!adev) {
+			if (acpi_bus_get_device(h, &adev)) {
 				pr_err("Failed to get device for ACPI object %s\n",
 				       andd->device_name);
 				continue;