ALSA: pcm: Avoid possible info leaks from PCM stream buffers
PATCH 1/1 ALSA: pcm: Avoid possible info leaks from PCM stream buffers
The current PCM code doesn't initialize explicitly the buffers allocated for PCM streams, hence it might leak some uninitialized kernel data or previous stream contents by mmapping or reading the buffer before actually starting the stream.
Since this is a common problem, this patch simply adds the clearance of the buffer data at hw_params callback. Although this does only zero-clear no matter which format is used, which doesn't mean the silence for some formats, but it should be OK because the intention is just to clear the previous data on the buffer.
---
This is a revised patch of the previous one
[email protected]
sound/core/pcm_native.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/core/pcm_native.c +4 -0
@@ -739,6 +739,10 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,while (runtime->boundary *2 <=LONG_MAX - runtime->buffer_size) runtime->boundary *=2 ; +/* clear the buffer for avoiding possible kernel info leaks */ +if (runtime->dma_area && !substream->ops->copy_user) +memset (runtime->dma_area,0 , runtime->dma_bytes); +snd_pcm_timer_resolution_change (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_SETUP );
Signature · 6 lines
2.16.4 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 10 lines · Takashi Iwai
The current PCM code doesn't initialize explicitly the buffers allocated for PCM streams, hence it might leak some uninitialized kernel data or previous stream contents by mmapping or reading the buffer before actually starting the stream.
Since this is a common problem, this patch simply adds the clearance of the buffer data at
hw_paramscallback. Although this does only zero-clear no matter which format is used, which doesn't mean the silence for some formats, but it should be OK because the intention is just to clear the previous data on the buffer.
I have tested this patch on the same way I tested the previous one and didn't experience any leakage of data.
Thanks for helping putting that together.
Kind regards,
Lionel
Quoted 17 lines
Reported-by Lionel Koenig <[email protected]>Cc <[email protected]>Signed-off-by Takashi Iwai <[email protected]>---
This is a revised patch of the previous one
[email protected]sound/core/pcm_native.c | 4 ++++ 1 file changed, 4 insertions(+)sound/core/pcm_native.c +0
-0
sound/core/pcm_native.c static int snd_pcm_hw_params(struct snd_pcm_substream *substream, · line 748
Quoted 10 lines
sound/core/pcm_native.c +4
-0@@ -739,6 +739,10 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,while (runtime->boundary *2 <=LONG_MAX - runtime->buffer_size) runtime->boundary *=2 ; +/* clear the buffer for avoiding possible kernel info leaks */ +if (runtime->dma_area && !substream->ops->copy_user) +memset (runtime->dma_area,0 , runtime->dma_bytes); +snd_pcm_timer_resolution_change (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_SETUP );
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel