Skip to content

Commit 97ab304

Browse files
Amadeusz Sławińskibroonie
authored andcommitted
ASoC: topology: Fix references to freed memory
Most users after parsing a topology file, release memory used by it, so having pointer references directly into topology file contents is wrong. Use devm_kmemdup(), to allocate memory as needed. Reported-by: Jason Montleon <jmontleo@redhat.com> Link: thesofproject/avs-topology-xml#22 (comment) Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com> Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com> Link: https://lore.kernel.org/r/20240603102818.36165-2-amadeuszx.slawinski@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2ed2216 commit 97ab304

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

sound/soc/soc-topology.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,15 +1060,32 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
10601060
break;
10611061
}
10621062

1063-
route->source = elem->source;
1064-
route->sink = elem->sink;
1063+
route->source = devm_kmemdup(tplg->dev, elem->source,
1064+
min(strlen(elem->source),
1065+
SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
1066+
GFP_KERNEL);
1067+
route->sink = devm_kmemdup(tplg->dev, elem->sink,
1068+
min(strlen(elem->sink), SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
1069+
GFP_KERNEL);
1070+
if (!route->source || !route->sink) {
1071+
ret = -ENOMEM;
1072+
break;
1073+
}
10651074

10661075
/* set to NULL atm for tplg users */
10671076
route->connected = NULL;
1068-
if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0)
1077+
if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) {
10691078
route->control = NULL;
1070-
else
1071-
route->control = elem->control;
1079+
} else {
1080+
route->control = devm_kmemdup(tplg->dev, elem->control,
1081+
min(strlen(elem->control),
1082+
SNDRV_CTL_ELEM_ID_NAME_MAXLEN),
1083+
GFP_KERNEL);
1084+
if (!route->control) {
1085+
ret = -ENOMEM;
1086+
break;
1087+
}
1088+
}
10721089

10731090
/* add route dobj to dobj_list */
10741091
route->dobj.type = SND_SOC_DOBJ_GRAPH;

0 commit comments

Comments
 (0)