Skip to content

Commit 220345e

Browse files
committed
ALSA: usb-audio: Fix OOB access of mixer element list
The USB-audio mixer code holds a linked list of usb_mixer_elem_list, and several operations are performed for each mixer element. A few of them (snd_usb_mixer_notify_id() and snd_usb_mixer_interrupt_v2()) assume each mixer element being a usb_mixer_elem_info object that is a subclass of usb_mixer_elem_list, cast via container_of() and access it members. This may result in an out-of-bound access when a non-standard list element has been added, as spotted by syzkaller recently. This patch adds a new field, is_std_info, in usb_mixer_elem_list to indicate that the element is the usb_mixer_elem_info type or not, and skip the access to such an element if needed. Reported-by: [email protected] Reported-by: [email protected] Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent a32a1fc commit 220345e

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

sound/usb/mixer.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,9 @@ static int check_matrix_bitmap(unsigned char *bmap,
581581
* if failed, give up and free the control instance.
582582
*/
583583

584-
int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
585-
struct snd_kcontrol *kctl)
584+
int snd_usb_mixer_add_list(struct usb_mixer_elem_list *list,
585+
struct snd_kcontrol *kctl,
586+
bool is_std_info)
586587
{
587588
struct usb_mixer_interface *mixer = list->mixer;
588589
int err;
@@ -596,6 +597,7 @@ int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
596597
return err;
597598
}
598599
list->kctl = kctl;
600+
list->is_std_info = is_std_info;
599601
list->next_id_elem = mixer->id_elems[list->id];
600602
mixer->id_elems[list->id] = list;
601603
return 0;
@@ -3234,8 +3236,11 @@ void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid)
32343236
unitid = delegate_notify(mixer, unitid, NULL, NULL);
32353237

32363238
for_each_mixer_elem(list, mixer, unitid) {
3237-
struct usb_mixer_elem_info *info =
3238-
mixer_elem_list_to_info(list);
3239+
struct usb_mixer_elem_info *info;
3240+
3241+
if (!list->is_std_info)
3242+
continue;
3243+
info = mixer_elem_list_to_info(list);
32393244
/* invalidate cache, so the value is read from the device */
32403245
info->cached = 0;
32413246
snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
@@ -3315,6 +3320,8 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
33153320

33163321
if (!list->kctl)
33173322
continue;
3323+
if (!list->is_std_info)
3324+
continue;
33183325

33193326
info = mixer_elem_list_to_info(list);
33203327
if (count > 1 && info->control != control)

sound/usb/mixer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct usb_mixer_elem_list {
6666
struct usb_mixer_elem_list *next_id_elem; /* list of controls with same id */
6767
struct snd_kcontrol *kctl;
6868
unsigned int id;
69+
bool is_std_info;
6970
usb_mixer_elem_dump_func_t dump;
7071
usb_mixer_elem_resume_func_t resume;
7172
};
@@ -103,8 +104,12 @@ void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
103104
int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
104105
int request, int validx, int value_set);
105106

106-
int snd_usb_mixer_add_control(struct usb_mixer_elem_list *list,
107-
struct snd_kcontrol *kctl);
107+
int snd_usb_mixer_add_list(struct usb_mixer_elem_list *list,
108+
struct snd_kcontrol *kctl,
109+
bool is_std_info);
110+
111+
#define snd_usb_mixer_add_control(list, kctl) \
112+
snd_usb_mixer_add_list(list, kctl, true)
108113

109114
void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list,
110115
struct usb_mixer_interface *mixer,

sound/usb/mixer_quirks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
158158
return -ENOMEM;
159159
}
160160
kctl->private_free = snd_usb_mixer_elem_free;
161-
return snd_usb_mixer_add_control(list, kctl);
161+
/* don't use snd_usb_mixer_add_control() here, this is a special list element */
162+
return snd_usb_mixer_add_list(list, kctl, false);
162163
}
163164

164165
/*

0 commit comments

Comments
 (0)