Skip to contentSkip to conversation

iommu/arm-smmu: fix null-pointer dereference in arm_smmu_add_device

PATCH Superseded Artem Savkov 4 participants 6 messages Aug 8, 2017 – Aug 9, 2017 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/arm-smmu: fix null-pointer dereference in arm_smmu_add_device

Commit c54451a "iommu/arm-smmu: Fix the error path in arm_smmu_add_device" removed fwspec assignment in legacy_binding path as redundant which is wrong. It needs to be updated after fwspec initialisation in arm_smmu_register_legacy_master() as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.

---
 drivers/iommu/arm-smmu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/arm-smmu.c +1 -0
index b97188a..95f1c86 100644
@@ -1519,6 +1519,7 @@ static int arm_smmu_add_device(struct device *dev)
 
 	if (using_legacy_binding) {
 		ret = arm_smmu_register_legacy_master(dev, &smmu);
+		fwspec = dev->iommu_fwspec;
 		if (ret)
 			goto out_free;
 	} else if (fwspec && fwspec->ops == &arm_smmu_ops) {
Signature · 1 line
2.7.5
#1 lore raw

Hi Artem,

Thanks for the patch.

Quoted 16 lines · Artem Savkov

Commit c54451a "iommu/arm-smmu: Fix the error path in arm_smmu_add_device" removed fwspec assignment in legacy_binding path as redundant which is wrong. It needs to be updated after fwspec initialisation in arm_smmu_register_legacy_master() as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.

---
 drivers/iommu/arm-smmu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iommu/arm-smmu.c +0 -0
index b97188a..95f1c86 100644

drivers/iommu/arm-smmu.c static int arm_smmu_add_device(struct device *dev) · line 1525

Quoted 7 lines
drivers/iommu/arm-smmu.c +1 -0
@@ -1519,6 +1519,7 @@ static int arm_smmu_add_device(struct device *dev)
 
 	if (using_legacy_binding) {
 		ret = arm_smmu_register_legacy_master(dev, &smmu);
+		fwspec = dev->iommu_fwspec;
 		if (ret)
 			goto out_free;
 	} else if (fwspec && fwspec->ops == &arm_smmu_ops) {

Damn, you're completely right! Robin and I bashed our heads against this for a while and couldn't remember why the code was structured like it was, but that explains it. Can you add a comment saying that arm_smmu_register_legacy_master will allocate an fwspec if its initially NULL, please?

Cheers,

Will

#2 lore raw

PATCH v2 1/1 iommu/arm-smmu: fix null-pointer dereference in arm_smmu_add_device

Commit c54451a "iommu/arm-smmu: Fix the error path in arm_smmu_add_device" removed fwspec assignment in legacy_binding path as redundant which is wrong. It needs to be updated after fwspec initialisation in arm_smmu_register_legacy_master() as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.

---
 drivers/iommu/arm-smmu.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c +7 -0
index b97188a..2d80fa8 100644
@@ -1519,6 +1519,13 @@ static int arm_smmu_add_device(struct device *dev)
 
 	if (using_legacy_binding) {
 		ret = arm_smmu_register_legacy_master(dev, &smmu);
+
+		/*
+		 * If dev->iommu_fwspec is initally NULL, arm_smmu_register_legacy_master()
+		 * will allocate/initialise a new one. Thus we need to update fwspec for
+		 * later use.
+		 */
+		fwspec = dev->iommu_fwspec;
 		if (ret)
 			goto out_free;
 	} else if (fwspec && fwspec->ops == &arm_smmu_ops) {
Signature · 1 line
2.7.5
reviewer Reviewed-by on v2 1/1
#3 lore raw
Quoted 5 lines · Artem Savkov

Commit c54451a "iommu/arm-smmu: Fix the error path in arm_smmu_add_device" removed fwspec assignment in legacy_binding path as redundant which is wrong. It needs to be updated after fwspec initialisation in arm_smmu_register_legacy_master() as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.

Thanks for fixing it up, and sorry for failing to document the unfortunately subtle logic in the first place!

Robin.

Quoted 24 lines
---
 drivers/iommu/arm-smmu.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c +7 -0
index b97188a..2d80fa8 100644
@@ -1519,6 +1519,13 @@ static int arm_smmu_add_device(struct device *dev)
 
 	if (using_legacy_binding) {
 		ret = arm_smmu_register_legacy_master(dev, &smmu);
+
+		/*
+		 * If dev->iommu_fwspec is initally NULL, arm_smmu_register_legacy_master()
+		 * will allocate/initialise a new one. Thus we need to update fwspec for
+		 * later use.
+		 */
+		fwspec = dev->iommu_fwspec;
 		if (ret)
 			goto out_free;
 	} else if (fwspec && fwspec->ops == &arm_smmu_ops) {
Acked-by
#4 lore raw

[+ Joerg]

Quoted 11 lines · Robin Murphy
Quoted 5 lines · Artem Savkov

Commit c54451a "iommu/arm-smmu: Fix the error path in arm_smmu_add_device" removed fwspec assignment in legacy_binding path as redundant which is wrong. It needs to be updated after fwspec initialisation in arm_smmu_register_legacy_master() as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.

Thanks for fixing it up, and sorry for failing to document the unfortunately subtle logic in the first place!

Well, I was the one that messed it up:

Joerg, can you pick this up as a fix for 4.13, please?

Will

Quoted 25 lines
Quoted 24 lines
---
 drivers/iommu/arm-smmu.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c +7 -0
index b97188a..2d80fa8 100644
@@ -1519,6 +1519,13 @@ static int arm_smmu_add_device(struct device *dev)
 
 	if (using_legacy_binding) {
 		ret = arm_smmu_register_legacy_master(dev, &smmu);
+
+		/*
+		 * If dev->iommu_fwspec is initally NULL, arm_smmu_register_legacy_master()
+		 * will allocate/initialise a new one. Thus we need to update fwspec for
+		 * later use.
+		 */
+		fwspec = dev->iommu_fwspec;
 		if (ret)
 			goto out_free;
 	} else if (fwspec && fwspec->ops == &arm_smmu_ops) {
Acked-by
#5 lore raw
Quoted 12 lines · Will Deacon

[+ Joerg]

Quoted 9 lines · Robin Murphy
Quoted 5 lines · Artem Savkov

Commit c54451a "iommu/arm-smmu: Fix the error path in arm_smmu_add_device" removed fwspec assignment in legacy_binding path as redundant which is wrong. It needs to be updated after fwspec initialisation in arm_smmu_register_legacy_master() as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.

Quoted 8 lines
Quoted 2 lines

Thanks for fixing it up, and sorry for failing to document the unfortunately subtle logic in the first place!

Well, I was the one that messed it up:

Joerg, can you pick this up as a fix for 4.13, please?

I hit the Oops as well. This patch fixes it for me on a Cavium CN88xx system, so:

Thanks for working on this.

Quoted 34 lines

Will

Quoted 11 lines
Quoted 11 lines
---
  drivers/iommu/arm-smmu.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/iommu/arm-smmu.c +0 -0
index b97188a..2d80fa8 100644
@@ -1519,6 +1519,13 @@ static int arm_smmu_add_device(struct device *dev)
 
Quoted 14 lines

drivers/iommu/arm-smmu.c static int arm_smmu_add_device(struct device *dev) · line 1531

Quoted 13 lines
drivers/iommu/arm-smmu.c +7 -0
  	if (using_legacy_binding) {
  		ret = arm_smmu_register_legacy_master(dev, &smmu);
+
+		/*
+		 * If dev->iommu_fwspec is initally NULL, arm_smmu_register_legacy_master()
+		 * will allocate/initialise a new one. Thus we need to update fwspec for
+		 * later use.
+		 */
+		fwspec = dev->iommu_fwspec;
  		if (ret)
  			goto out_free;
  	} else if (fwspec && fwspec->ops == &arm_smmu_ops) {

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel