public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Vinod Koul <vinod.koul@linux.intel.com>,
	alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Jesper Juhl <jj@chaosbits.net>,
	Namarta Kohli <namartax.kohli@intel.com>
Subject: Re: [patch] ALSA: compress_core: integer overflow in snd_compr_allocate_buffer()
Date: Wed, 05 Sep 2012 13:40:06 +0000	[thread overview]
Message-ID: <s5hwr08ziyx.wl%tiwai@suse.de> (raw)
In-Reply-To: <20120905123217.GD6128@elgon.mountain>

At Wed, 5 Sep 2012 15:32:18 +0300,
Dan Carpenter wrote:
> 
> These are 32 bit values that come from the user, we need to check for
> integer overflows or we could end up allocating a smaller buffer than
> expected.

The buffer size here is supposed to be fairly small that kmalloc can
handle.  So, the overflow check is good, but in practice it'd return
-ENOMEM.  Of course, it's fine to put the sanity check, but such
checks could be better peformed in snd_compr_set_params() before
calling the allocation, I think.


thanks,

Takashi

> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
> index ec2118d..5a733e7 100644
> --- a/sound/core/compress_offload.c
> +++ b/sound/core/compress_offload.c
> @@ -409,6 +409,10 @@ 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;
> 

  reply	other threads:[~2012-09-05 13:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05 12:32 [patch] ALSA: compress_core: integer overflow in snd_compr_allocate_buffer() Dan Carpenter
2012-09-05 13:40 ` Takashi Iwai [this message]
2012-09-06 14:59   ` Dan Carpenter
2012-09-06 15:19     ` Takashi Iwai
2012-09-14  9:06       ` Takashi Iwai
2012-09-14  9:36         ` Vinod Koul
2012-09-14  9:35           ` Dan Carpenter
2012-09-14  9:40           ` Vinod Koul
2012-09-14  9:45             ` Takashi Iwai
2012-09-14  9:52               ` Vinod Koul
2012-09-14 10:00                 ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hwr08ziyx.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dan.carpenter@oracle.com \
    --cc=jj@chaosbits.net \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=namartax.kohli@intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=vinod.koul@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox