Skip to contentSkip to conversation

sound: fix PCM substream list

PATCH In review Akinobu Mita 2 participants 2 messages Nov 22, 2006 – Nov 23, 2006 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound: fix PCM substream list

If snd_pcm_new_stream() fails to initalize a substream (if snd_pcm_substream_proc_init() returns error), snd_pcm_new_stream() immediately return without unlinking that kfree()d substram.

It causes oops when snd_pcm_free() iterates the list of substream to free them by invalid reference.

Cc Takashi Iwai <[email protected]>
Cc Jaroslav Kysela <[email protected]>
---
 sound/core/pcm.c |    4 ++++
 1 file changed, 4 insertions(+)
sound/core/pcm.c +4 -0
Index: work-fault-inject/sound/core/pcm.c
===================================================================
@@ -638,6 +638,10 @@ int snd_pcm_new_stream(struct snd_pcm *p
 		err = snd_pcm_substream_proc_init(substream);
 		if (err < 0) {
 			snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
+			if (prev == NULL)
+				pstr->substream = NULL;
+			else
+				prev->next = NULL;
 			kfree(substream);
 			return err;
 		}
#1 lore raw

At Thu, 23 Nov 2006 03:51:45 +0900,

Quoted 11 lines · Akinobu Mita

If snd_pcm_new_stream() fails to initalize a substream (if snd_pcm_substream_proc_init() returns error), snd_pcm_new_stream() immediately return without unlinking that kfree()d substram.

It causes oops when snd_pcm_free() iterates the list of substream to free them by invalid reference.

Cc Takashi Iwai <[email protected]>
Cc Jaroslav Kysela <[email protected]>

Merged this one to ALSA tree, too.
Thanks.

Takashi

Quoted 21 lines
---
 sound/core/pcm.c |    4 ++++
 1 file changed, 4 insertions(+)

Index: work-fault-inject/sound/core/pcm.c
===================================================================

sound/core/pcm.c +4 -0
@@ -638,6 +638,10 @@ int snd_pcm_new_stream(struct snd_pcm *p
 		err = snd_pcm_substream_proc_init(substream);
 		if (err < 0) {
 			snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
+			if (prev == NULL)
+				pstr->substream = NULL;
+			else
+				prev->next = NULL;
 			kfree(substream);
 			return err;
 		}