general protection fault in snd_usb_create_mixer

17 views
Skip to first unread message

syzbot

unread,
Nov 21, 2019, 10:25:10 AM11/21/19
to alsa-...@alsa-project.org, andre...@google.com, benq...@gmail.com, dan.ca...@oracle.com, g...@b4.vu, gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, pe...@perex.cz, syzkall...@googlegroups.com, ti...@suse.com, wang...@umn.edu
Hello,

syzbot found the following crash on:

HEAD commit: 46178223 usb: gadget: add raw-gadget interface
git tree: https://github.com/google/kasan.git usb-fuzzer
console output: https://syzkaller.appspot.com/x/log.txt?x=176f9836e00000
kernel config: https://syzkaller.appspot.com/x/.config?x=99c88c44660624e7
dashboard link: https://syzkaller.appspot.com/bug?extid=a36ab65c6653d7ccdd62
compiler: gcc (GCC) 9.0.0 20181231 (experimental)
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1447d3bae00000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17ef3a86e00000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+a36ab6...@syzkaller.appspotmail.com

usb 1-1: 208:241 : does not exist
usb 1-1: 208:242 : does not exist
usb 1-1: 208:243 : does not exist
usb 1-1: 208:244 : does not exist
usb 1-1: 208:245 : does not exist
usb 1-1: 208:246 : does not exist
usb 1-1: 208:247 : does not exist
usb 1-1: 208:248 : does not exist
usb 1-1: 208:249 : does not exist
usb 1-1: 208:250 : does not exist
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] SMP KASAN
CPU: 1 PID: 22 Comm: kworker/1:1 Not tainted 5.4.0-rc6+ #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Workqueue: usb_hub_wq hub_event
RIP: 0010:snd_usb_mixer_controls_badd sound/usb/mixer.c:2931 [inline]
RIP: 0010:snd_usb_create_mixer+0xbb9/0x1890 sound/usb/mixer.c:3441
Code: ee e8 9b 23 a6 fc 41 39 ee 74 a4 e8 a1 22 a6 fc 48 8b 7c 24 28 89 ee
e8 25 59 b4 fe 48 8d 78 10 48 89 c3 48 89 f8 48 c1 e8 03 <42> 0f b6 04 28
84 c0 74 08 3c 03 0f 8e 2f 09 00 00 8b 6b 10 bf 01
RSP: 0018:ffff8881d932f0a0 EFLAGS: 00010202
RAX: 0000000000000002 RBX: 0000000000000000 RCX: ffffffff834c5dac
RDX: 0000000000000000 RSI: ffffffff834c5e1b RDI: 0000000000000010
RBP: 0000000000000021 R08: ffff8881da24e000 R09: fffffbfff11aadb5
R10: fffffbfff11aadb4 R11: ffffffff88d56da7 R12: 00000000000000da
R13: dffffc0000000000 R14: 00000000000000d0 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000043f100 CR3: 0000000006c21000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
usb_audio_probe+0xc76/0x2010 sound/usb/card.c:653
usb_probe_interface+0x305/0x7a0 drivers/usb/core/driver.c:361
really_probe+0x281/0x6d0 drivers/base/dd.c:548
driver_probe_device+0x104/0x210 drivers/base/dd.c:721
__device_attach_driver+0x1c2/0x220 drivers/base/dd.c:828
bus_for_each_drv+0x162/0x1e0 drivers/base/bus.c:430
__device_attach+0x217/0x360 drivers/base/dd.c:894
bus_probe_device+0x1e4/0x290 drivers/base/bus.c:490
device_add+0xae6/0x16f0 drivers/base/core.c:2202
usb_set_configuration+0xdf6/0x1670 drivers/usb/core/message.c:2023
generic_probe+0x9d/0xd5 drivers/usb/core/generic.c:210
usb_probe_device+0x99/0x100 drivers/usb/core/driver.c:266
really_probe+0x281/0x6d0 drivers/base/dd.c:548
driver_probe_device+0x104/0x210 drivers/base/dd.c:721
__device_attach_driver+0x1c2/0x220 drivers/base/dd.c:828
bus_for_each_drv+0x162/0x1e0 drivers/base/bus.c:430
__device_attach+0x217/0x360 drivers/base/dd.c:894
bus_probe_device+0x1e4/0x290 drivers/base/bus.c:490
device_add+0xae6/0x16f0 drivers/base/core.c:2202
usb_new_device.cold+0x6a4/0xe79 drivers/usb/core/hub.c:2537
hub_port_connect drivers/usb/core/hub.c:5184 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5324 [inline]
port_event drivers/usb/core/hub.c:5470 [inline]
hub_event+0x1df8/0x3800 drivers/usb/core/hub.c:5552
process_one_work+0x92b/0x1530 kernel/workqueue.c:2269
worker_thread+0x96/0xe20 kernel/workqueue.c:2415
kthread+0x318/0x420 kernel/kthread.c:255
ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352
Modules linked in:
---[ end trace 1d30a29898ec11e8 ]---
RIP: 0010:snd_usb_mixer_controls_badd sound/usb/mixer.c:2931 [inline]
RIP: 0010:snd_usb_create_mixer+0xbb9/0x1890 sound/usb/mixer.c:3441
Code: ee e8 9b 23 a6 fc 41 39 ee 74 a4 e8 a1 22 a6 fc 48 8b 7c 24 28 89 ee
e8 25 59 b4 fe 48 8d 78 10 48 89 c3 48 89 f8 48 c1 e8 03 <42> 0f b6 04 28
84 c0 74 08 3c 03 0f 8e 2f 09 00 00 8b 6b 10 bf 01
RSP: 0018:ffff8881d932f0a0 EFLAGS: 00010202
RAX: 0000000000000002 RBX: 0000000000000000 RCX: ffffffff834c5dac
RDX: 0000000000000000 RSI: ffffffff834c5e1b RDI: 0000000000000010
RBP: 0000000000000021 R08: ffff8881da24e000 R09: fffffbfff11aadb5
R10: fffffbfff11aadb4 R11: ffffffff88d56da7 R12: 00000000000000da
R13: dffffc0000000000 R14: 00000000000000d0 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff8881db300000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000043f100 CR3: 0000000006c21000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


---
This bug is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

Dan Carpenter

unread,
Nov 21, 2019, 3:50:38 PM11/21/19
to syzbot, alsa-...@alsa-project.org, andre...@google.com, benq...@gmail.com, g...@b4.vu, gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, pe...@perex.cz, syzkall...@googlegroups.com, ti...@suse.com, wang...@umn.edu
On Thu, Nov 21, 2019 at 07:25:09AM -0800, syzbot wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit: 46178223 usb: gadget: add raw-gadget interface
> git tree: https://github.com/google/kasan.git usb-fuzzer
> console output: https://syzkaller.appspot.com/x/log.txt?x=176f9836e00000
> kernel config: https://syzkaller.appspot.com/x/.config?x=99c88c44660624e7
> dashboard link: https://syzkaller.appspot.com/bug?extid=a36ab65c6653d7ccdd62
> compiler: gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1447d3bae00000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=17ef3a86e00000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+a36ab6...@syzkaller.appspotmail.com
>
> usb 1-1: 208:241 : does not exist
> usb 1-1: 208:242 : does not exist
> usb 1-1: 208:243 : does not exist
> usb 1-1: 208:244 : does not exist
> usb 1-1: 208:245 : does not exist
> usb 1-1: 208:246 : does not exist
> usb 1-1: 208:247 : does not exist
> usb 1-1: 208:248 : does not exist
> usb 1-1: 208:249 : does not exist
> usb 1-1: 208:250 : does not exist

These error messages are because:

sound/usb/card.c
128 static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
129 {
130 struct usb_device *dev = chip->dev;
131 struct usb_host_interface *alts;
132 struct usb_interface_descriptor *altsd;
133 struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
134
135 if (!iface) {
136 dev_err(&dev->dev, "%u:%d : does not exist\n",
137 ctrlif, interface);
138 return -EINVAL;
139 }

"iface" is NULL. The caller ignores the -EINVAL (correctly I think).

Then the NULL dereference happens in snd_usb_mixer_controls_badd()

sound/usb/mixer.c
2903 static int snd_usb_mixer_controls_badd(struct usb_mixer_interface *mixer,
2904 int ctrlif)
2905 {
2906 struct usb_device *dev = mixer->chip->dev;
2907 struct usb_interface_assoc_descriptor *assoc;
2908 int badd_profile = mixer->chip->badd_profile;
2909 struct uac3_badd_profile *f;
2910 const struct usbmix_ctl_map *map;
2911 int p_chmask = 0, c_chmask = 0, st_chmask = 0;
2912 int i;
2913
2914 assoc = usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
2915
2916 /* Detect BADD capture/playback channels from AS EP descriptors */
2917 for (i = 0; i < assoc->bInterfaceCount; i++) {
2918 int intf = assoc->bFirstInterface + i;
2919
2920 struct usb_interface *iface;
2921 struct usb_host_interface *alts;
2922 struct usb_interface_descriptor *altsd;
2923 unsigned int maxpacksize;
2924 char dir_in;
2925 int chmask, num;
2926
2927 if (intf == ctrlif)
2928 continue;
2929
2930 iface = usb_ifnum_to_if(dev, intf);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
iface is not checked.

Should it be "if (!iface) continue;?"

2931 num = iface->num_altsetting;
2932
2933 if (num < 2)
2934 return -EINVAL;
2935

I'm not sure.

regards,
dan carpenter

Takashi Iwai

unread,
Nov 22, 2019, 6:28:08 AM11/22/19
to Dan Carpenter, syzbot, alsa-...@alsa-project.org, andre...@google.com, benq...@gmail.com, g...@b4.vu, gre...@linuxfoundation.org, linux-...@vger.kernel.org, linu...@vger.kernel.org, pe...@perex.cz, syzkall...@googlegroups.com, ti...@suse.com, wang...@umn.edu
Right, that should fix the problem. Although the interface number
referred in snd_usb_mixer_controls_badd() can be different from the
one checked in snd_usb_create_stream(), the culprit is the missing
NULL check there.


thanks,

Takashi

Wayne Bai

unread,
Mar 22, 2024, 6:53:46 AMMar 22
to syzkaller-bugs
please test the following patch

#syz test

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 03745a3d5a82d09ac..91c692f936d6feb68 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -811,6 +811,10 @@ static int usb_audio_probe(struct usb_interface *intf,
  if (!chip) {
  /* it\'s a fresh one.
   * now look for an empty slot and create a new card instance
+  */
+ if (!dev) {
+ err = -EINVAL;
+ goto __error;
  }
  for (i = 0; i < SNDRV_CARDS; i++)
  if (!usb_chip[i] &&
@@ -836,6 +840,11 @@ static int usb_audio_probe(struct usb_interface *intf,
 
  usb_chip[chip->index] = chip;
  chip->num_interfaces++;
+ usb_set_intfdata(intf, chip);
+ atomic_dec(&chip->active);
+ mutex_unlock(&register_mutex);
+ return 0;
+
 __error:
  if (chip) {
  /* chip->active is inside the chip->card object,
@@ -848,8 +857,7 @@ __error:
  snd_card_free(chip->card);
  }
  }
- mutex_unlock(&register_mutex);
- return err;
+ goto limit_error;
 
  limit_error:
  /* we hit the limit; it should not happen */
@@ -964,6 +972,7 @@ __error:
  if (!chip->num_interfaces)
  snd_card_free(chip->card);
  mutex_unlock(&register_mutex);
+ return err;
 }
 
 /*
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 03c429c297b7a4b51297..163fe43d27d776e7cff3 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -663,27 +663,36 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
   int ignore_error)
 {
  static struct snd_device_ops dev_ops = {
- .dev_free = snd_usb_mixer_dev_free
+ .dev_free = snd_usb_mixer_dev_free,
+ .dev_register = snd_usb_mixer_dev_register
  };
  struct usb_mixer_interface *mixer;
  int err;
 
+ if (!chip->dev) {
+ err = -EINVAL;
+ goto limit_error;
+ }
+
  strcpy(chip->card->mixername, "USB Mixer");
 
  mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
  if (!mixer)
  return -ENOMEM;
+ mixer->chip = chip;
  mixer->ignore_ctl_error = ignore_error;
  mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems),
    GFP_KERNEL);
  if (!mixer->id_elems) {
  kfree(mixer);
- return -ENOMEM;
+ err = -ENOMEM;
+ goto limit_error;
  }
 
  mixer->hostif = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0];
  switch (get_iface_desc(mixer->hostif)->bInterfaceProtocol) {
  case UAC_VERSION_1:
  default:
+ limit_error:
  mixer->protocol = UAC_VERSION_1;
  break;
  case UAC_VERSION_2:
@@ -699,6 +708,13 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
  return -EINVAL;
  }
 
+ if (chip->protocol == UAC_VERSION_3 &&
+ chip->badd_profile >= UAC3_FUNCTION_SUBCLASS_GENERIC_IO) {
+ err = snd_usb_mixer_controls_badd(mixer, ctrlif);
+ if (err < 0)
+ return err;
+ } else {
+
  err = snd_usb_mixer_controls(mixer);
  if (err < 0)
  goto _error;
@@ -731,6 +747,7 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
  list_add(&mixer->list, &chip->mixer_list);
  return 0;
 
+ }
 _error:
  snd_usb_mixer_free(mixer);
  return err;
@@ -838,6 +855,9 @@ out:
  snd_card_disconnect(chip->card);
  usb_set_intfdata(iface, NULL);
  strlcpy(card->mixername, "", sizeof(card->mixername));
+ chip->dev= NULL;
+ __error:
+ snd_card_free(card);
 out:
  return ret;
 }
@@ -2929,7 +2949,7 @@ static int build_connector_control(struct usb_mixer_interface *mixer,

 
 static int snd_usb_mixer_controls_badd(struct usb_mixer_interface *mixer,
         int ctrlif)
-{
+{

  struct usb_device *dev = mixer->chip->dev;
  struct usb_interface_assoc_descriptor *assoc;
  int badd_profile = mixer->chip->badd_profile;', role='assistant', function_call=None, tool_calls=None)

Reply all
Reply to author
Forward
0 new messages