Skip to content

Commit 5591bf0

Browse files
Dan Rosenbergtiwai
authored andcommitted
ALSA: prevent heap corruption in snd_ctl_new()
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 <[email protected]> Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent e68d3b3 commit 5591bf0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sound/core/control.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
/* max number of user-defined controls */
3333
#define MAX_USER_CONTROLS 32
34+
#define MAX_CONTROL_COUNT 1028
3435

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

196197
if (snd_BUG_ON(!control || !control->count))
197198
return NULL;
199+
200+
if (control->count > MAX_CONTROL_COUNT)
201+
return NULL;
202+
198203
kctl = kzalloc(sizeof(*kctl) + sizeof(struct snd_kcontrol_volatile) * control->count, GFP_KERNEL);
199204
if (kctl == NULL) {
200205
snd_printk(KERN_ERR "Cannot allocate control instance\n");

0 commit comments

Comments
 (0)