spi: tegra20-slink: fix UAF in tegra_slink_remove()
authorYang Yingliang <yangyingliang@huawei.com>
Wed, 13 Jul 2022 09:40:23 +0000 (17:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:12 +0000 (14:23 +0200)
commit415b4ce61308f24583912d887772dfcbf97f1d20
treeadbbf1004bdca7fd5556216a6e325cc9f508648e
parent445fb9c19cf45bd9472fd9babaa31c5e6c7d2720
spi: tegra20-slink: fix UAF in tegra_slink_remove()

[ Upstream commit 7e9984d183bb1e99e766c5c2b950ff21f7f7b6c0 ]

After calling spi_unregister_master(), the refcount of master will
be decrease to 0, and it will be freed in spi_controller_release(),
the device data also will be freed, so it will lead a UAF when using
'tspi'. To fix this, get the master before unregister and put it when
finish using it.

Fixes: 26c863418221 ("spi: tegra20-slink: Don't use resource-managed spi_register helper")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20220713094024.1508869-1-yangyingliang@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spi-tegra20-slink.c