alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: soc-pcm: fix fe and be race when accessing substream->runtime
@ 2022-09-26 16:35 Eugeniu Rosca
  2022-09-27  7:34 ` Amadeusz Sławiński
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Eugeniu Rosca @ 2022-09-26 16:35 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	alsa-devel, linux-kernel
  Cc: Yanmin Zhang, Eugeniu Rosca, Jiada Wang, Zhang Yanmin,
	Ramesh Babu, Dean Jenkins, Ramesh Babu B, Eugeniu Rosca, xiao jin

From: xiao jin <jin.xiao@intel.com>

After start of fe and be, fe might go to close without triggering
STOP, and substream->runtime is freed. However, be is still at
START state and its substream->runtime still points to the
freed runtime.

Later on, FE is opened/started again, and triggers STOP.
snd_pcm_do_stop => dpcm_fe_dai_trigger
                => dpcm_fe_dai_do_trigger
                => dpcm_be_dai_trigger
                => dpcm_do_trigger
                => soc_pcm_trigger
                => skl_platform_pcm_trigger
skl_platform_pcm_trigger accesses the freed old runtime data and
kernel panic.

The patch fixes it by assigning be_substream->runtime in
dpcm_be_dai_startup when be's state is START.

Signed-off-by: xiao jin <jin.xiao@intel.com>
Signed-off-by: Zhang Yanmin <yanmin.zhang@intel.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---
 sound/soc/soc-pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 4f60c0a83311..6ca1d02065ce 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1608,6 +1608,8 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
 		if (be->dpcm[stream].users++ != 0)
 			continue;
 
+		be_substream->runtime = be->dpcm[stream].runtime;
+
 		if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
 		    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
 			continue;
@@ -1615,7 +1617,6 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
 		dev_dbg(be->dev, "ASoC: open %s BE %s\n",
 			stream ? "capture" : "playback", be->dai_link->name);
 
-		be_substream->runtime = be->dpcm[stream].runtime;
 		err = __soc_pcm_open(be, be_substream);
 		if (err < 0) {
 			be->dpcm[stream].users--;
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-09-29 16:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-26 16:35 [PATCH] ASoC: soc-pcm: fix fe and be race when accessing substream->runtime Eugeniu Rosca
2022-09-27  7:34 ` Amadeusz Sławiński
2022-09-27 11:56   ` Eugeniu Rosca
2022-09-27  7:50 ` Cezary Rojewski
2022-09-27 11:00   ` Eugeniu Rosca
2022-09-28 14:24     ` Cezary Rojewski
2022-09-29 16:25       ` Eugeniu Rosca
2022-09-27  7:51 ` Pierre-Louis Bossart
2022-09-27 12:30   ` Eugeniu Rosca
2022-09-28  8:36     ` Pierre-Louis Bossart
2022-09-29 16:36       ` Eugeniu Rosca

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).