* [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate()
@ 2020-10-29 9:22 Yu Kuai
2020-10-29 10:08 ` Robin Murphy
0 siblings, 1 reply; 5+ messages in thread
From: Yu Kuai @ 2020-10-29 9:22 UTC (permalink / raw)
To: joro, heiko, robin.murphy, jeffy.chen
Cc: yi.zhang, linux-kernel, linux-rockchip, iommu, yukuai3, linux-arm-kernel
If of_find_device_by_node() failed in rk_iommu_of_xlate(), null pointer
dereference will be triggered. Thus return error code if
of_find_device_by_node() failed.
Fixes: 5fd577c3eac3("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/iommu/rockchip-iommu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index e5d86b7177de..090d149ef8e9 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1099,6 +1099,9 @@ static int rk_iommu_of_xlate(struct device *dev,
iommu_dev = of_find_device_by_node(args->np);
+ if (!iommu_dev)
+ return -ENODEV;
+
data->iommu = platform_get_drvdata(iommu_dev);
dev_iommu_priv_set(dev, data);
--
2.25.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate()
2020-10-29 9:22 [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate() Yu Kuai
@ 2020-10-29 10:08 ` Robin Murphy
2020-10-29 13:19 ` yukuai (C)
0 siblings, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2020-10-29 10:08 UTC (permalink / raw)
To: Yu Kuai, joro, heiko, jeffy.chen
Cc: linux-rockchip, iommu, linux-kernel, linux-arm-kernel, yi.zhang
On 2020-10-29 09:22, Yu Kuai wrote:
> If of_find_device_by_node() failed in rk_iommu_of_xlate(), null pointer
> dereference will be triggered. Thus return error code if
> of_find_device_by_node() failed.
How can that happen? (Given that ".suppress_bind_attrs = true")
Robin.
> Fixes: 5fd577c3eac3("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/iommu/rockchip-iommu.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> index e5d86b7177de..090d149ef8e9 100644
> --- a/drivers/iommu/rockchip-iommu.c
> +++ b/drivers/iommu/rockchip-iommu.c
> @@ -1099,6 +1099,9 @@ static int rk_iommu_of_xlate(struct device *dev,
>
> iommu_dev = of_find_device_by_node(args->np);
>
> + if (!iommu_dev)
> + return -ENODEV;
> +
> data->iommu = platform_get_drvdata(iommu_dev);
> dev_iommu_priv_set(dev, data);
>
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate()
2020-10-29 10:08 ` Robin Murphy
@ 2020-10-29 13:19 ` yukuai (C)
2020-10-29 13:51 ` Robin Murphy
0 siblings, 1 reply; 5+ messages in thread
From: yukuai (C) @ 2020-10-29 13:19 UTC (permalink / raw)
To: Robin Murphy, joro, heiko, jeffy.chen
Cc: linux-rockchip, iommu, linux-kernel, linux-arm-kernel, yi.zhang
On 2020/10/29 18:08, Robin Murphy wrote:
> On 2020-10-29 09:22, Yu Kuai wrote:
>> If of_find_device_by_node() failed in rk_iommu_of_xlate(), null pointer
>> dereference will be triggered. Thus return error code if
>> of_find_device_by_node() failed.
>
> How can that happen? (Given that ".suppress_bind_attrs = true")
>
> Robin.
I'm not sure if that could happen...
My thought is that it's better to do such checking to aviod any possible
problem.
Thanks!
Yu Kuai
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate()
2020-10-29 13:19 ` yukuai (C)
@ 2020-10-29 13:51 ` Robin Murphy
2020-10-30 1:27 ` yukuai (C)
0 siblings, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2020-10-29 13:51 UTC (permalink / raw)
To: yukuai (C), joro, heiko, jeffy.chen
Cc: linux-rockchip, iommu, linux-kernel, linux-arm-kernel, yi.zhang
On 2020-10-29 13:19, yukuai (C) wrote:
>
> On 2020/10/29 18:08, Robin Murphy wrote:
>> On 2020-10-29 09:22, Yu Kuai wrote:
>>> If of_find_device_by_node() failed in rk_iommu_of_xlate(), null pointer
>>> dereference will be triggered. Thus return error code if
>>> of_find_device_by_node() failed.
>>
>> How can that happen? (Given that ".suppress_bind_attrs = true")
>>
>> Robin.
>
> I'm not sure if that could happen...
>
> My thought is that it's better to do such checking to aviod any possible
> problem.
->of_xlate() is only invoked on the specific set of ops returned by
iommu_ops_from_fwnode(). In turn, iommu_ops_from_fwnode() will only
return those ops if the driver has successfully probed and called
iommu_register_device() with the relevant DT node. For the driver to
have been able to probe at all, a platform device associated with that
DT node must have been created, and therefore of_find_device_by_node()
cannot fail.
If there ever were some problem serious enough to break that fundamental
assumption, then I *want* these drivers to crash right here, with a nice
clear stack trace to start debugging from. So no, I firmly disagree that
adding redundant code, which will never do anything except attempt to
paper over catastrophic memory corruption, is "better". Sorry :)
Robin.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate()
2020-10-29 13:51 ` Robin Murphy
@ 2020-10-30 1:27 ` yukuai (C)
0 siblings, 0 replies; 5+ messages in thread
From: yukuai (C) @ 2020-10-30 1:27 UTC (permalink / raw)
To: Robin Murphy, joro, heiko, jeffy.chen
Cc: linux-rockchip, iommu, linux-kernel, linux-arm-kernel, yi.zhang
On 2020/10/29 21:51, Robin Murphy wrote:
> On 2020-10-29 13:19, yukuai (C) wrote:
>>
>> On 2020/10/29 18:08, Robin Murphy wrote:
>>> On 2020-10-29 09:22, Yu Kuai wrote:
>>>> If of_find_device_by_node() failed in rk_iommu_of_xlate(), null pointer
>>>> dereference will be triggered. Thus return error code if
>>>> of_find_device_by_node() failed.
>>>
>>> How can that happen? (Given that ".suppress_bind_attrs = true")
>>>
>>> Robin.
>>
>> I'm not sure if that could happen...
>>
>> My thought is that it's better to do such checking to aviod any possible
>> problem.
>
> ->of_xlate() is only invoked on the specific set of ops returned by
> iommu_ops_from_fwnode(). In turn, iommu_ops_from_fwnode() will only
> return those ops if the driver has successfully probed and called
> iommu_register_device() with the relevant DT node. For the driver to
> have been able to probe at all, a platform device associated with that
> DT node must have been created, and therefore of_find_device_by_node()
> cannot fail.
>
> If there ever were some problem serious enough to break that fundamental
> assumption, then I *want* these drivers to crash right here, with a nice
> clear stack trace to start debugging from. So no, I firmly disagree that
> adding redundant code, which will never do anything except attempt to
> paper over catastrophic memory corruption, is "better". Sorry :)
>
Sounds reasonable, thanks for your explanation
Yu Kuai
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-30 1:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 9:22 [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate() Yu Kuai
2020-10-29 10:08 ` Robin Murphy
2020-10-29 13:19 ` yukuai (C)
2020-10-29 13:51 ` Robin Murphy
2020-10-30 1:27 ` yukuai (C)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).