Skip to content

Commit 6ab55ec

Browse files
ZheyuMatiwai
authored andcommitted
ALSA: control: Fix an out-of-bounds bug in get_ctl_id_hash()
Since the user can control the arguments provided to the kernel by the ioctl() system call, an out-of-bounds bug occurs when the 'id->name' provided by the user does not end with '\0'. The following log can reveal it: [ 10.002313] BUG: KASAN: stack-out-of-bounds in snd_ctl_find_id+0x36c/0x3a0 [ 10.002895] Read of size 1 at addr ffff888109f5fe28 by task snd/439 [ 10.004934] Call Trace: [ 10.007140] snd_ctl_find_id+0x36c/0x3a0 [ 10.007489] snd_ctl_ioctl+0x6cf/0x10e0 Fix this by checking the bound of 'id->name' in the loop. Fixes: c27e1ef ("ALSA: control: Use xarray for faster lookups") Signed-off-by: Zheyu Ma <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 2e6481a commit 6ab55ec

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sound/core/control.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ static bool elem_id_matches(const struct snd_kcontrol *kctl,
385385
#define MULTIPLIER 37
386386
static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id)
387387
{
388+
int i;
388389
unsigned long h;
389-
const unsigned char *p;
390390

391391
h = id->iface;
392392
h = MULTIPLIER * h + id->device;
393393
h = MULTIPLIER * h + id->subdevice;
394-
for (p = id->name; *p; p++)
395-
h = MULTIPLIER * h + *p;
394+
for (i = 0; id->name[i] && i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN; i++)
395+
h = MULTIPLIER * h + id->name[i];
396396
h = MULTIPLIER * h + id->index;
397397
h &= LONG_MAX;
398398
return h;

0 commit comments

Comments
 (0)