]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
memory: tegra20-emc: fix an OF node reference bug in tegra_emc_find_node_by_ram_code()
authorJoe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Tue, 17 Dec 2024 09:14:34 +0000 (18:14 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:50:05 +0000 (12:50 +0100)
commitc3def10c610ae046aaa61d00528e7bd15e4ad8d3
treec20a29319040dd1f083c630712f6b43a6b7a3df0
parentd9f36f957bb22d94fa6be46caad98e1cce6022d5
memory: tegra20-emc: fix an OF node reference bug in tegra_emc_find_node_by_ram_code()

[ Upstream commit b9784e5cde1f9fb83661a70e580e381ae1264d12 ]

As of_find_node_by_name() release the reference of the argument device
node, tegra_emc_find_node_by_ram_code() releases some device nodes while
still in use, resulting in possible UAFs. According to the bindings and
the in-tree DTS files, the "emc-tables" node is always device's child
node with the property "nvidia,use-ram-code", and the "lpddr2" node is a
child of the "emc-tables" node. Thus utilize the
for_each_child_of_node() macro and of_get_child_by_name() instead of
of_find_node_by_name() to simplify the code.

This bug was found by an experimental verification tool that I am
developing.

Fixes: 96e5da7c8424 ("memory: tegra: Introduce Tegra20 EMC driver")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Link: https://lore.kernel.org/r/20241217091434.1993597-1-joe@pf.is.s.u-tokyo.ac.jp
Link: https://lore.kernel.org/r/20241218024415.2494267-3-joe@pf.is.s.u-tokyo.ac.jp
[krzysztof: applied v1, adjust the commit msg to incorporate v2 parts]
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/memory/tegra/tegra20-emc.c