Skip to content

Commit

Permalink
sound: oss: off by one bug
Browse files Browse the repository at this point in the history
The problem is that in the original code sound_nblocks could go up to 1024
which would be an array overflow.

This was found with a static checker and has been compile tested only.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
Dan Carpenter authored and Jaroslav Kysela committed Jan 8, 2010
1 parent 440b004 commit 444c195
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 9 additions & 7 deletions sound/oss/dev_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
return -(EBUSY);
}
d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));

if (sound_nblocks < 1024)
sound_nblocks++;
sound_nblocks++;
if (sound_nblocks >= MAX_MEM_BLOCKS)
sound_nblocks = MAX_MEM_BLOCKS - 1;

op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations)));
sound_nblocks++;
if (sound_nblocks >= MAX_MEM_BLOCKS)
sound_nblocks = MAX_MEM_BLOCKS - 1;

if (sound_nblocks < 1024)
sound_nblocks++;
if (d == NULL || op == NULL) {
printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
sound_unload_audiodev(num);
Expand Down Expand Up @@ -128,9 +129,10 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
until you unload sound! */

op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations)));
sound_nblocks++;
if (sound_nblocks >= MAX_MEM_BLOCKS)
sound_nblocks = MAX_MEM_BLOCKS - 1;

if (sound_nblocks < 1024)
sound_nblocks++;
if (op == NULL) {
printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
return -ENOMEM;
Expand Down
2 changes: 2 additions & 0 deletions sound/oss/sound_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@ static inline int translate_mode(struct file *file)
#define TIMER_ARMED 121234
#define TIMER_NOT_ARMED 1

#define MAX_MEM_BLOCKS 1024

#endif
4 changes: 2 additions & 2 deletions sound/oss/soundcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/*
* Table for permanently allocated memory (used when unloading the module)
*/
void * sound_mem_blocks[1024];
void * sound_mem_blocks[MAX_MEM_BLOCKS];
int sound_nblocks = 0;

/* Persistent DMA buffers */
Expand Down Expand Up @@ -574,7 +574,7 @@ static int __init oss_init(void)
NULL, "%s%d", dev_list[i].name, j);
}

if (sound_nblocks >= 1024)
if (sound_nblocks >= MAX_MEM_BLOCKS - 1)
printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");

return 0;
Expand Down

0 comments on commit 444c195

Please sign in to comment.