Skip to contentSkip to conversation

ASoC: Fix use after free

PATCH Applied Lars-Peter Clausen 2 participants 2 messages Mar 12, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: Fix use after free

Freeing the current list element while iterating over the list will cause a use after free since the iterator function will still use the current element to look up the next. Use list_for_each_safe() and remove the element from the list before freeing it to avoid this.

Fixes 1438c2f60b ("ASoC: Add a per component dai list")
---
 sound/soc/soc-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/soc-core.c +3 -2
index f67cef4..dac616d 100644
@@ -3928,11 +3928,12 @@ static inline char *fmt_multiple_name(struct device *dev,
  */
 static void snd_soc_unregister_dais(struct snd_soc_component *component)
 {
-	struct snd_soc_dai *dai;
+	struct snd_soc_dai *dai, *_dai;
 
-	list_for_each_entry(dai, &component->dai_list, list) {
+	list_for_each_entry_safe(dai, _dai, &component->dai_list, list) {
 		dev_dbg(component->dev, "ASoC: Unregistered DAI '%s'\n",
 			dai->name);
+		list_del(&dai->list);
 		kfree(dai->name);
 		kfree(dai);
 	}
Signature · 1 line
1.8.0
maintainer Applied
#1 lore raw
Quoted 4 lines · Lars-Peter Clausen

Freeing the current list element while iterating over the list will cause a use after free since the iterator function will still use the current element to look up the next. Use list_for_each_safe() and remove the element from the list before freeing it to avoid this.

Applied, thanks.