linux/sound/soc/mediatek
Trevor Wu dc93f0dcb4
ASoC: mediatek: mt8195: fix use-after-free in driver remove path
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>
2023-06-01 12:30:36 +01:00
..
common ASoC: mediatek: common: Fix refcount leak in parse_dai_link_info 2023-04-11 12:40:07 +01:00
mt2701 ASoC: mediatek: mt2701-afe-pcm: Convert to platform remove callback returning void 2023-03-20 13:08:36 +00:00
mt6797 ASoC: mediatek: mt6797-afe-pcm: Convert to platform remove callback returning void 2023-03-20 13:08:37 +00:00
mt8173 ASoC: mediatek: mt8173-afe-pcm: Convert to platform remove callback returning void 2023-03-20 13:08:38 +00:00
mt8183 ASoC: mediatek: mt8183-afe-pcm: Convert to platform remove callback returning void 2023-03-20 13:08:39 +00:00
mt8186 ASoC: mediatek: mt8186: Fix use-after-free in driver remove path 2023-05-15 10:21:13 +09:00
mt8188 ASoC: mediatek: mt8188: fix use-after-free in driver remove path 2023-06-01 12:30:35 +01:00
mt8192 ASoC: mediatek: mt8192-afe-pcm: Convert to platform remove callback returning void 2023-03-20 13:08:41 +00:00
mt8195 ASoC: mediatek: mt8195: fix use-after-free in driver remove path 2023-06-01 12:30:36 +01:00
Kconfig ASoC: mediatek: Add support for MT8188 SoC 2023-01-19 15:31:47 +00:00
Makefile ASoC: mediatek: mt8188: add platform driver 2023-01-16 11:16:26 +00:00