846bc92
From cef7f62d5881e886cd514436bc386a7202af25f1 Mon Sep 17 00:00:00 2001
846bc92
From: Nicolai Stange <nicstange@gmail.com>
846bc92
Date: Tue, 15 Mar 2016 13:35:06 +0100
846bc92
Subject: [PATCH] sound/usb: fix NULL dereference in usb_audio_probe()
846bc92
846bc92
With commit
846bc92
846bc92
  aebb2b89bff0 ("[media] sound/usb: Use Media Controller API to share
846bc92
                 media resources")
846bc92
846bc92
an access to quirk->media_device without checking for quirk != NULL has
846bc92
been introduced in usb_audio_probe().
846bc92
846bc92
With a Plantronics USB headset (device ID 0x047f:0xc010) attached,
846bc92
this results in the following splat at boot time:
846bc92
846bc92
  BUG: unable to handle kernel NULL pointer dereference at 0000000000000014
846bc92
  IP: [<ffffffffa089aa6c>] usb_audio_probe+0x2cc/0x9a0 [snd_usb_audio]
846bc92
  Oops: 0000 [#1] SMP
846bc92
  [...]
846bc92
  CPU: 2 PID: 696 Comm: systemd-udevd Not tainted 4.5.0-next-20160315 #13
846bc92
  Hardware name: Dell Inc. Latitude E6540/0725FP, BIOS A10 06/26/2014
846bc92
  task: ffff88021c88d7c0 ti: ffff88003d5b0000 task.ti: ffff88003d5b0000
846bc92
  RIP: 0010:[<ffffffffa089aa6c>]  [<ffffffffa089aa6c>]
846bc92
                                usb_audio_probe+0x2cc/0x9a0 [snd_usb_audio]
846bc92
  [...]
846bc92
  Call Trace:
846bc92
   [<ffffffff815a8e16>] usb_probe_interface+0x136/0x2d0
846bc92
   [<ffffffff81509edc>] driver_probe_device+0x22c/0x440
846bc92
   [<ffffffff8150a1c1>] __driver_attach+0xd1/0xf0
846bc92
   [<ffffffff8150a0f0>] ? driver_probe_device+0x440/0x440
846bc92
   [<ffffffff815077ec>] bus_for_each_dev+0x6c/0xc0
846bc92
   [<ffffffff815095ce>] driver_attach+0x1e/0x20
846bc92
   [<ffffffff81509013>] bus_add_driver+0x1c3/0x280
846bc92
   [<ffffffff8150ab10>] driver_register+0x60/0xe0
846bc92
   [<ffffffff815a7711>] usb_register_driver+0x81/0x140
846bc92
   [<ffffffffa08c7000>] ? 0xffffffffa08c7000
846bc92
   [<ffffffffa08c701e>] usb_audio_driver_init+0x1e/0x1000 [snd_usb_audio]
846bc92
   [<ffffffff81002123>] do_one_initcall+0xb3/0x1f0
846bc92
   [<ffffffff811fb091>] ? __vunmap+0x81/0xd0
846bc92
   [<ffffffff8121b8d2>] ? kmem_cache_alloc_trace+0x182/0x1d0
846bc92
   [<ffffffff811b0267>] ? do_init_module+0x27/0x1d8
846bc92
   [<ffffffff811b029f>] do_init_module+0x5f/0x1d8
846bc92
   [<ffffffff8112ce35>] load_module+0x1fe5/0x27a0
846bc92
   [<ffffffff81129870>] ? __symbol_put+0x60/0x60
846bc92
   [<ffffffff81241690>] ? vfs_read+0x110/0x130
846bc92
   [<ffffffff8112d866>] SYSC_finit_module+0xe6/0x120
846bc92
   [<ffffffff8112d8be>] SyS_finit_module+0xe/0x10
846bc92
   [<ffffffff81003d94>] do_syscall_64+0x64/0x110
846bc92
   [<ffffffff817c0b61>] entry_SYSCALL64_slow_path+0x25/0x25
846bc92
846bc92
After encountering this, the system-udevd process seems to be blocked
846bc92
until it is killed when hitting its timeout of 3min.
846bc92
846bc92
In analogy to the other accesses to members of quirk in usb_audio_probe(),
846bc92
check for quirk != NULL before accessing its ->media_device.
846bc92
846bc92
Fixes: aebb2b89bff0 ("[media] sound/usb: Use Media Controller API to share
846bc92
                      media resources")
846bc92
Signed-off-by: Nicolai Stange <nicstange@gmail.com>
846bc92
---
846bc92
 sound/usb/card.c | 2 +-
846bc92
 1 file changed, 1 insertion(+), 1 deletion(-)
846bc92
846bc92
diff --git a/sound/usb/card.c b/sound/usb/card.c
846bc92
index 63244bbba8c7..479621e775bc 100644
846bc92
--- a/sound/usb/card.c
846bc92
+++ b/sound/usb/card.c
846bc92
@@ -612,7 +612,7 @@ static int usb_audio_probe(struct usb_interface *intf,
846bc92
 	if (err < 0)
846bc92
 		goto __error;
846bc92
 
846bc92
-	if (quirk->media_device) {
846bc92
+	if (quirk && quirk->media_device) {
846bc92
 		/* don't want to fail when media_snd_device_create() fails */
846bc92
 		media_snd_device_create(chip, intf);
846bc92
 	}
846bc92
-- 
846bc92
2.5.5
846bc92