iommu/arm-smmu: fix null-pointer dereference in arm_smmu_add_device
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
@@ -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
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 inlegacy_bindingpath as redundant which is wrong. It needs to be updated after fwspec initialisation inarm_smmu_register_legacy_master()as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.Signed-off-by Artem Savkov <[email protected]>--- drivers/iommu/arm-smmu.c | 1 + 1 file changed, 1 insertion(+)drivers/iommu/arm-smmu.c +0
-0
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
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
@@ -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
Quoted 5 lines · Artem Savkov
Commit c54451a "iommu/arm-smmu: Fix the error path in
arm_smmu_add_device" removed fwspec assignment inlegacy_bindingpath as redundant which is wrong. It needs to be updated after fwspec initialisation inarm_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
Signed-off-by Artem Savkov <[email protected]>--- drivers/iommu/arm-smmu.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/iommu/arm-smmu.c +7
-0@@ -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) {
Will Deacon
Acked-by[+ 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 inlegacy_bindingpath as redundant which is wrong. It needs to be updated after fwspec initialisation inarm_smmu_register_legacy_master()as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.Reviewed-by Robin Murphy <[email protected]>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
Signed-off-by Artem Savkov <[email protected]>--- drivers/iommu/arm-smmu.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/iommu/arm-smmu.c +7
-0@@ -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) {
David Daney
Acked-byQuoted 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 inlegacy_bindingpath as redundant which is wrong. It needs to be updated after fwspec initialisation inarm_smmu_register_legacy_master()as it is dereferenced later. Without this there is a NULL-pointer dereference panic during boot on some hosts.Reviewed-by Robin Murphy <[email protected]>
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:
Acked-by Will Deacon <[email protected]>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
Signed-off-by Artem Savkov <[email protected]>--- drivers/iommu/arm-smmu.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/iommu/arm-smmu.c +0
-0@@ -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
-0if (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