Skip to content

Commit

Permalink
ALSA: prevent heap corruption in snd_ctl_new()
Browse files Browse the repository at this point in the history
The snd_ctl_new() function in sound/core/control.c allocates space for a
snd_kcontrol struct by performing arithmetic operations on a
user-provided size without checking for integer overflow.  If a user
provides a large enough size, an overflow will occur, the allocated
chunk will be too small, and a second user-influenced value will be
written repeatedly past the bounds of this chunk.  This code is
reachable by unprivileged users who have permission to open
a /dev/snd/controlC* device (on many distros, this is group "audio") via
the SNDRV_CTL_IOCTL_ELEM_ADD and SNDRV_CTL_IOCTL_ELEM_REPLACE ioctls.

Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com>
Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Dan Rosenberg authored and Takashi Iwai committed Sep 28, 2010
1 parent e68d3b3 commit 5591bf0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sound/core/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

/* max number of user-defined controls */
#define MAX_USER_CONTROLS 32
#define MAX_CONTROL_COUNT 1028

struct snd_kctl_ioctl {
struct list_head list; /* list of all ioctls */
Expand Down Expand Up @@ -195,6 +196,10 @@ static struct snd_kcontrol *snd_ctl_new(struct snd_kcontrol *control,

if (snd_BUG_ON(!control || !control->count))
return NULL;

if (control->count > MAX_CONTROL_COUNT)
return NULL;

kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
if (kctl == NULL) {
snd_printk(KERN_ERR "Cannot allocate control instance\n");
Expand Down

0 comments on commit 5591bf0

Please sign in to comment.