From: Dragos Tarcatu Date: Wed, 18 Dec 2019 00:05:18 +0000 (-0600) Subject: ASoC: topology: Prevent use-after-free in snd_soc_get_pcm_runtime() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=72b46612d06b83851e2e4f7b538a0bbeb69c10de;p=linux.git ASoC: topology: Prevent use-after-free in snd_soc_get_pcm_runtime() remove_link() is currently calling snd_soc_remove_pcm_runtime() after it has already freed the memory for the link name. But this is later read from snd_soc_get_pcm_runtime() causing a KASAN use-after-free warning. Reorder the cleanups to fix this issue. Reviewed-by: Ranjani Sridharan Signed-off-by: Dragos Tarcatu Signed-off-by: Pierre-Louis Bossart Acked-by: Kuninori Morimoto Link: https://lore.kernel.org/r/20191218000518.5830-4-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown --- diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index f8bd406c61989..2b3c74a0b1269 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -548,14 +548,14 @@ static void remove_link(struct snd_soc_component *comp, if (dobj->ops && dobj->ops->link_unload) dobj->ops->link_unload(comp, dobj); - kfree(link->name); - kfree(link->stream_name); - kfree(link->cpus->dai_name); - list_del(&dobj->list); snd_soc_remove_pcm_runtime(comp->card, snd_soc_get_pcm_runtime(comp->card, link)); + + kfree(link->name); + kfree(link->stream_name); + kfree(link->cpus->dai_name); kfree(link); }