Skip to contentSkip to conversation

intel-iommu: check return value of device_to_iommu() before using it

PATCH In review ethan zhao 3 participants 3 messages Jan 9, 2014 – Jan 10, 2014

Subsystems (2)
lore
Share & tools
lore

ethan zhao

author
#0 lore raw

PATCH 1/1 intel-iommu: check return value of device_to_iommu() before using it

in function iommu_support_dev_iotlb(),return value of device_to_iommu() is used without checking, this could cause NULL pointer issue.

this patch is for v3.12.6

---
 drivers/iommu/intel-iommu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/iommu/intel-iommu.c +2 -0
index 40203ad..5b4531a 100644
@@ -1105,6 +1105,8 @@ static struct device_domain_info *iommu_support_dev_iotlb(
     struct device_domain_info *info;
     struct intel_iommu *iommu = device_to_iommu(segment, bus, devfn);
 
+    if (!iommu)
+        return NULL;
     if (!ecap_dev_iotlb_support(iommu->ecap))
         return NULL;
 
Signature · 1 line
1.7.1
Quoted 1 line

From 27d8cdd3fcc6f4ff5cc2ba36d8d5ea0a97823a17 Mon Sep 17 00:00:00 2001

From: ethan.zhao <[email protected]>
Date: Thu, 9 Jan 2014 08:40:16 -0500
Subject: [PATCH] intel-iommu: check return value of device_to_iommu() before using it

in function iommu_support_dev_iotlb(),return value of device_to_iommu() is used without checking, this could cause NULL pointer issue.

this patch is for v3.12.6

---
 drivers/iommu/intel-iommu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/iommu/intel-iommu.c +2 -0
index 40203ad..5b4531a 100644
@@ -1105,6 +1105,8 @@ static struct device_domain_info *iommu_support_dev_iotlb(
 	struct device_domain_info *info;
 	struct intel_iommu *iommu = device_to_iommu(segment, bus, devfn);
 
+	if (!iommu)
+		return NULL;
 	if (!ecap_dev_iotlb_support(iommu->ecap))
 		return NULL;
 
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 8 lines · ethan zhao
 drivers/iommu/intel-iommu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/iommu/intel-iommu.c +0 -0
index 40203ad..5b4531a 100644

drivers/iommu/intel-iommu.c static struct device_domain_info · line 1112

Quoted 8 lines
drivers/iommu/intel-iommu.c +2 -0
@@ -1105,6 +1105,8 @@ static struct device_domain_info
 *iommu_support_dev_iotlb(
     struct device_domain_info *info;
     struct intel_iommu *iommu = device_to_iommu(segment, bus, devfn);
 
+    if (!iommu)
+        return NULL;
     if (!ecap_dev_iotlb_support(iommu->ecap))
         return NULL;

This call can not fail, iommu_support_dev_iotlb() is only called from domain_context_mapping_one() which does the iommu==NULL check on its own before the call.

Joerg

#2 lore raw
Quoted 13 lines · Joerg Roedel
Quoted 12 lines · ethan zhao
 drivers/iommu/intel-iommu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/iommu/intel-iommu.c +0 -0
index 40203ad..5b4531a 100644
@@ -1105,6 +1105,8 @@ static struct device_domain_info
 *iommu_support_dev_iotlb(
     struct device_domain_info *info;
     struct intel_iommu *iommu = device_to_iommu(segment, bus, devfn);
 
Quoted 9 lines

drivers/iommu/intel-iommu.c static struct device_domain_info *iommu_support_dev_iotlb( · line 1111

Quoted 4 lines
drivers/iommu/intel-iommu.c +2 -0
+    if (!iommu)
+        return NULL;
     if (!ecap_dev_iotlb_support(iommu->ecap))
         return NULL;

This call can not fail, iommu_support_dev_iotlb() is only called from domain_context_mapping_one() which does the iommu==NULL check on its own before the call.

Agree, till now, was checked in domain_context_mapping_one(), but how about if we query information with iommu_support_dev_iotlb() in other code ?

Thanks,
Ethan

Quoted 8 lines

Joerg

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html