ASoC: soc-core: fix init platform memory handling

snd_soc_init_platform initializes pointers to snd_soc_dai_link which is
statically allocated and it does this by devm_kzalloc. In the event of
an EPROBE_DEFER the memory will be freed and the pointers are left
dangling. snd_soc_init_platform sees the dangling pointers and assumes
they are pointing to initialized memory and does not reallocate them on
the second probe attempt which results in a use after free bug since
devm has freed the memory from the first probe attempt.

Since the intention for snd_soc_dai_link->platform is that it can be set
statically by the machine driver we need to respect the pointer in the
event we did not set it but still catch dangling pointers. The solution
is to add a flag to track whether the pointer was dynamically allocated
or not.

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Curtis Malainey 2019-01-10 16:21:04 -08:00 committed by Mark Brown
parent 04eb1efcd6
commit 09ac6a817b
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 12 additions and 5 deletions

View File

@ -985,6 +985,12 @@ struct snd_soc_dai_link {
/* Do not create a PCM for this DAI link (Backend link) */ /* Do not create a PCM for this DAI link (Backend link) */
unsigned int ignore:1; unsigned int ignore:1;
/*
* This driver uses legacy platform naming. Set by the core, machine
* drivers should not modify this value.
*/
unsigned int legacy_platform:1;
struct list_head list; /* DAI link list of the soc card */ struct list_head list; /* DAI link list of the soc card */
struct snd_soc_dobj dobj; /* For topology */ struct snd_soc_dobj dobj; /* For topology */
}; };

View File

@ -1034,7 +1034,7 @@ static int snd_soc_init_platform(struct snd_soc_card *card,
* this function should be removed in the future * this function should be removed in the future
*/ */
/* convert Legacy platform link */ /* convert Legacy platform link */
if (!platform) { if (!platform || dai_link->legacy_platform) {
platform = devm_kzalloc(card->dev, platform = devm_kzalloc(card->dev,
sizeof(struct snd_soc_dai_link_component), sizeof(struct snd_soc_dai_link_component),
GFP_KERNEL); GFP_KERNEL);
@ -1042,6 +1042,7 @@ static int snd_soc_init_platform(struct snd_soc_card *card,
return -ENOMEM; return -ENOMEM;
dai_link->platform = platform; dai_link->platform = platform;
dai_link->legacy_platform = 1;
platform->name = dai_link->platform_name; platform->name = dai_link->platform_name;
platform->of_node = dai_link->platform_of_node; platform->of_node = dai_link->platform_of_node;
platform->dai_name = NULL; platform->dai_name = NULL;