WSL2-Linux-Kernel/sound/soc/mediatek/mt8195
Trevor Wu 2a4f0ad59d ASoC: mediatek: mt8195: fix use-after-free in driver remove path
[ Upstream commit dc93f0dcb4 ]

During mt8195_afe_init_clock(), mt8195_audsys_clk_register() was called
followed by several other devm functions. At mt8195_afe_deinit_clock()
located at mt8195_afe_pcm_dev_remove(), mt8195_audsys_clk_unregister()
was called.

However, there was an issue with the order in which these functions were
called. Specifically, the remove callback of platform_driver was called
before devres released the resource, resulting in a use-after-free issue
during remove time.

At probe time, the order of calls was:
1. mt8195_audsys_clk_register
2. afe_priv->clk = devm_kcalloc
3. afe_priv->clk[i] = devm_clk_get

At remove time, the order of calls was:
1. mt8195_audsys_clk_unregister
3. free afe_priv->clk[i]
2. free afe_priv->clk

To resolve the problem, we can utilize devm_add_action_or_reset() in
mt8195_audsys_clk_register() so that the remove order can be changed to
3->2->1.

Fixes: 6746cc8582 ("ASoC: mediatek: mt8195: add platform driver")
Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20230601033318.10408-3-trevor.wu@mediatek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-06-14 11:13:08 +02:00
..
Makefile ASoC: mediatek: mt8195: add machine driver with mt6359, rt1019 and rt5682 2021-08-24 19:13:58 +01:00
mt8195-afe-clk.c ASoC: mediatek: mt8195: fix use-after-free in driver remove path 2023-06-14 11:13:08 +02:00
mt8195-afe-clk.h ASoC: mediatek: mt8195: fix use-after-free in driver remove path 2023-06-14 11:13:08 +02:00
mt8195-afe-common.h ASoC: mediatek: mt8195: add platform driver 2021-08-24 19:13:56 +01:00
mt8195-afe-pcm.c ASoC: mediatek: mt8195: fix use-after-free in driver remove path 2023-06-14 11:13:08 +02:00
mt8195-audsys-clk.c ASoC: mediatek: mt8195: fix use-after-free in driver remove path 2023-06-14 11:13:08 +02:00
mt8195-audsys-clk.h ASoC: mediatek: mt8195: fix use-after-free in driver remove path 2023-06-14 11:13:08 +02:00
mt8195-audsys-clkid.h
mt8195-dai-adda.c ASoC: mediatek: mt8195: support adda in platform driver 2021-08-24 19:13:54 +01:00
mt8195-dai-etdm.c ASoC: mediatek: mt8195: add missing initialization 2023-03-11 13:57:32 +01:00
mt8195-dai-pcm.c ASoC: mediatek: mt8195: correct pcmif BE dai control flow 2022-01-27 11:04:17 +01:00
mt8195-mt6359-rt1019-rt5682.c ASoC: mediatek: mt8195: Add missing of_node_put() 2021-11-25 09:48:24 +01:00
mt8195-reg.h ASoC: mediatek: mt8195: correct pcmif BE dai control flow 2022-01-27 11:04:17 +01:00