Skip to contentSkip to conversation

ALSA: compress - move the buffer check

PATCH Applied Vinod Koul 2 participants 4 messages Sep 17, 2012

Subsystems (2)
lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

PATCH 1/2 ALSA: compress - move the buffer check

Commit ALSA: compress_core: integer overflow in snd_compr_allocate_buffer() added a new error check for input params.
this add new routine for input checks and moves buffer overflow check to this new routine. This allows the error value to be propogated to user space

---
 sound/core/compress_offload.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
sound/core/compress_offload.c +16 -4
index 68fe02c..bd7f28e 100644
@@ -407,10 +407,6 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
 	unsigned int buffer_size;
 	void *buffer;
 
-	if (params->buffer.fragment_size == 0 ||
-	    params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
-		return -EINVAL;
-
 	buffer_size = params->buffer.fragment_size * params->buffer.fragments;
 	if (stream->ops->copy) {
 		buffer = NULL;
@@ -429,6 +425,16 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
 	return 0;
 }
 
+static int snd_compress_check_input(struct snd_compr_params *params)
+{
+	/* first let's check the buffer parameter's */
+	if (params->buffer.fragment_size == 0 ||
+			params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 {
@@ -447,11 +453,17 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 			retval = -EFAULT;
 			goto out;
 		}
+
+		retval = snd_compress_check_input(params);
+		if (retval)
+			goto out;
+
 		retval = snd_compr_allocate_buffer(stream, params);
 		if (retval) {
 			retval = -ENOMEM;
 			goto out;
 		}
+
 		retval = stream->ops->set_params(stream, params);
 		if (retval)
 			goto out;
Signature · 1 line
1.7.0.4
author
#1 lore raw

PATCH 2/2 ALSA: Compress - add codec parameter checks

---
 include/sound/compress_params.h |    1 +
 sound/core/compress_offload.c   |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
include/sound/compress_params.h +1 -0
index da4a456..602dc6c 100644
@@ -72,6 +72,7 @@
 #define SND_AUDIOCODEC_IEC61937              ((__u32) 0x0000000B)
 #define SND_AUDIOCODEC_G723_1                ((__u32) 0x0000000C)
 #define SND_AUDIOCODEC_G729                  ((__u32) 0x0000000D)
+#define SND_AUDIOCODEC_MAX                   SND_AUDIOCODEC_G729
 
 /*
  * Profile and modes are listed with bit masks. This allows for a
sound/core/compress_offload.c +10 -0
index bd7f28e..c40ae57 100644
@@ -432,6 +432,16 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 			params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
 		return -EINVAL;
 
+	/* now codec parameters */
+	if (params->codec.id == 0 || params->codec.id > SND_AUDIOCODEC_MAX)
+		return -EINVAL;
+
+	if (params->codec.ch_in == 0 || params->codec.ch_out == 0)
+		return -EINVAL;
+
+	if (!(params->codec.sample_rate & SNDRV_PCM_RATE_8000_192000))
+		return -EINVAL;
+
 	return 0;
 }
 
Signature · 1 line
1.7.0.4
Applied
#2 lore raw

Re: [PATCH 2/2] ALSA: Compress - add codec parameter checks

At Mon, 17 Sep 2012 11:51:26 +0530,

Quoted 2 lines · Vinod Koul

Applied this one, too. Thanks.

Takashi

Quoted 41 lines
---
 include/sound/compress_params.h |    1 +
 sound/core/compress_offload.c   |   10 ++++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
include/sound/compress_params.h +1 -0
index da4a456..602dc6c 100644
@@ -72,6 +72,7 @@
 #define SND_AUDIOCODEC_IEC61937              ((__u32) 0x0000000B)
 #define SND_AUDIOCODEC_G723_1                ((__u32) 0x0000000C)
 #define SND_AUDIOCODEC_G729                  ((__u32) 0x0000000D)
+#define SND_AUDIOCODEC_MAX                   SND_AUDIOCODEC_G729
 
 /*
  * Profile and modes are listed with bit masks. This allows for a
sound/core/compress_offload.c +10 -0
index bd7f28e..c40ae57 100644
@@ -432,6 +432,16 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 			params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
 		return -EINVAL;
 
+	/* now codec parameters */
+	if (params->codec.id == 0 || params->codec.id > SND_AUDIOCODEC_MAX)
+		return -EINVAL;
+
+	if (params->codec.ch_in == 0 || params->codec.ch_out == 0)
+		return -EINVAL;
+
+	if (!(params->codec.sample_rate & SNDRV_PCM_RATE_8000_192000))
+		return -EINVAL;
+
 	return 0;
 }
 
Signature · 1 line
1.7.0.4
Applied
#3 lore raw
In reply to Vinod Koul

At Mon, 17 Sep 2012 11:51:25 +0530,

Quoted 7 lines · Vinod Koul

Commit ALSA: compress_core: integer overflow in snd_compr_allocate_buffer() added a new error check for input params.
this add new routine for input checks and moves buffer overflow check to this new routine. This allows the error value to be propogated to user space

Applied, thanks.

Takashi

Quoted 57 lines
---
 sound/core/compress_offload.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
sound/core/compress_offload.c +16 -4
index 68fe02c..bd7f28e 100644
@@ -407,10 +407,6 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
 	unsigned int buffer_size;
 	void *buffer;
 
-	if (params->buffer.fragment_size == 0 ||
-	    params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
-		return -EINVAL;
-
 	buffer_size = params->buffer.fragment_size * params->buffer.fragments;
 	if (stream->ops->copy) {
 		buffer = NULL;
@@ -429,6 +425,16 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
 	return 0;
 }
 
+static int snd_compress_check_input(struct snd_compr_params *params)
+{
+	/* first let's check the buffer parameter's */
+	if (params->buffer.fragment_size == 0 ||
+			params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 {
@@ -447,11 +453,17 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 			retval = -EFAULT;
 			goto out;
 		}
+
+		retval = snd_compress_check_input(params);
+		if (retval)
+			goto out;
+
 		retval = snd_compr_allocate_buffer(stream, params);
 		if (retval) {
 			retval = -ENOMEM;
 			goto out;
 		}
+
 		retval = stream->ops->set_params(stream, params);
 		if (retval)
 			goto out;
Signature · 1 line
1.7.0.4