Skip to content
Snippets Groups Projects
  1. May 14, 2021
  2. Mar 17, 2021
    • Pavel Skripkin's avatar
      ALSA: usb-audio: fix use after free in usb_audio_disconnect · 29bc89c8
      Pavel Skripkin authored
      
      commit c5aa956e upstream.
      
      The problem was in wrong "if" placement. chip->quirk_type is freed
      in snd_card_free_when_closed(), but inside if statement it's accesed.
      
      Fixes: 97991108 ("ALSA: usb-audio: Disable USB autosuspend properly in setup_disable_autosuspend()")
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/16da19126ff461e5e64a9aec648cce28fb8ed73e.1615242183.git.paskripkin@gmail.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29bc89c8
    • Pavel Skripkin's avatar
      ALSA: usb-audio: fix NULL ptr dereference in usb_audio_probe · d2fdcc82
      Pavel Skripkin authored
      
      commit 30dea071 upstream.
      
      syzbot reported null pointer dereference in usb_audio_probe.
      The problem was in case, when quirk == NULL. It's not an
      error condition, so quirk must be checked before dereferencing.
      
      Call Trace:
       usb_probe_interface+0x315/0x7f0 drivers/usb/core/driver.c:396
       really_probe+0x291/0xe60 drivers/base/dd.c:554
       driver_probe_device+0x26b/0x3d0 drivers/base/dd.c:740
       __device_attach_driver+0x1d1/0x290 drivers/base/dd.c:846
       bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:431
       __device_attach+0x228/0x4a0 drivers/base/dd.c:914
       bus_probe_device+0x1e4/0x290 drivers/base/bus.c:491
       device_add+0xbdb/0x1db0 drivers/base/core.c:3242
       usb_set_configuration+0x113f/0x1910 drivers/usb/core/message.c:2164
       usb_generic_driver_probe+0xba/0x100 drivers/usb/core/generic.c:238
       usb_probe_device+0xd9/0x2c0 drivers/usb/core/driver.c:293
       really_probe+0x291/0xe60 drivers/base/dd.c:554
       driver_probe_device+0x26b/0x3d0 drivers/base/dd.c:740
       __device_attach_driver+0x1d1/0x290 drivers/base/dd.c:846
       bus_for_each_drv+0x15f/0x1e0 drivers/base/bus.c:431
       __device_attach+0x228/0x4a0 drivers/base/dd.c:914
       bus_probe_device+0x1e4/0x290 drivers/base/bus.c:491
       device_add+0xbdb/0x1db0 drivers/base/core.c:3242
       usb_new_device.cold+0x721/0x1058 drivers/usb/core/hub.c:2555
       hub_port_connect drivers/usb/core/hub.c:5223 [inline]
       hub_port_connect_change drivers/usb/core/hub.c:5363 [inline]
       port_event drivers/usb/core/hub.c:5509 [inline]
       hub_event+0x2357/0x4320 drivers/usb/core/hub.c:5591
       process_one_work+0x98d/0x1600 kernel/workqueue.c:2275
       worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
       kthread+0x3b1/0x4a0 kernel/kthread.c:292
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
      
      Reported-by: default avatar <syzbot+719da9b149a931f5143f@syzkaller.appspotmail.com>
      Fixes: 97991108 ("ALSA: usb-audio: Disable USB autosuspend properly in setup_disable_autosuspend()")
      Signed-off-by: default avatarPavel Skripkin <paskripkin@gmail.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/f1ebad6e721412843bd1b12584444c0a63c6b2fb.1615242183.git.paskripkin@gmail.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d2fdcc82
    • Kai-Heng Feng's avatar
      ALSA: usb-audio: Disable USB autosuspend properly in setup_disable_autosuspend() · e4493974
      Kai-Heng Feng authored
      
      commit 97991108 upstream.
      
      Rear audio on Lenovo ThinkStation P620 stops working after commit
      1965c436 ("ALSA: usb-audio: Disable autosuspend for Lenovo
      ThinkStation P620"):
      [    6.013526] usbcore: registered new interface driver snd-usb-audio
      [    6.023064] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x100, wIndex = 0x0, type = 1
      [    6.023083] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x202, wIndex = 0x0, type = 4
      [    6.023090] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x100, wIndex = 0x0, type = 1
      [    6.023098] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x202, wIndex = 0x0, type = 4
      [    6.023103] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x100, wIndex = 0x0, type = 1
      [    6.023110] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x202, wIndex = 0x0, type = 4
      [    6.045846] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x100, wIndex = 0x0, type = 1
      [    6.045866] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x202, wIndex = 0x0, type = 4
      [    6.045877] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x100, wIndex = 0x0, type = 1
      [    6.045886] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x202, wIndex = 0x0, type = 4
      [    6.045894] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x100, wIndex = 0x0, type = 1
      [    6.045908] usb 3-6: cannot get ctl value: req = 0x81, wValue = 0x202, wIndex = 0x0, type = 4
      
      I overlooked the issue because when I was working on the said commit,
      only the front audio is tested. Apology for that.
      
      Changing supports_autosuspend in driver is too late for disabling
      autosuspend, because it was already used by USB probe routine, so it can
      break the balance on the following code that depends on
      supports_autosuspend.
      
      Fix it by using usb_disable_autosuspend() helper, and balance the
      suspend count in disconnect callback.
      
      Fixes: 1965c436 ("ALSA: usb-audio: Disable autosuspend for Lenovo ThinkStation P620")
      Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20210304043419.287191-1-kai.heng.feng@canonical.com
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e4493974
  3. Dec 30, 2020
  4. Nov 16, 2020
  5. Aug 20, 2020
    • Takashi Iwai's avatar
      ALSA: usb-audio: Move device rename and profile quirks to an internal table · 5436f59b
      Takashi Iwai authored
      So far we've added the devices that need vendor/product string renames
      or the profile setup into the standard quirk table in quirks-table.h.
      This table is imported into the primary USB audio device entry, hence
      it's all exported for the probing so that udev and co can take a look
      at it.  OTOH, for renaming or profile setup, we don't need to expose
      those explicit entries because the probe itself follows the standard
      way.  That said, we're exposing unnecessarily too many entries.
      
      This patch moves such internal quirk entries into the own table, and
      reduces the exported device table size.  Along with the moving items,
      re-arrange the entries in the proper order.
      
      Link: https://lore.kernel.org/r/20200817082140.20232-2-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      5436f59b
  6. Jul 09, 2020
  7. Jun 08, 2020
  8. Jun 04, 2020
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix inconsistent card PM state after resume · 862b2509
      Takashi Iwai authored
      
      When a USB-audio interface gets runtime-suspended via auto-pm feature,
      the driver suspends all functionality and increment
      chip->num_suspended_intf.  Later on, when the system gets suspended to
      S3, the driver increments chip->num_suspended_intf again, skips the
      device changes, and sets the card power state to
      SNDRV_CTL_POWER_D3hot.  In return, when the system gets resumed from
      S3, the resume callback decrements chip->num_suspended_intf.  Since
      this refcount is still not zero (it's been runtime-suspended), the
      whole resume is skipped.  But there is a small pitfall here.
      
      The problem is that the driver doesn't restore the card power state
      after this resume call, leaving it as SNDRV_CTL_POWER_D3hot.  So,
      even after the system resume finishes, the card instance still appears
      as if it were system-suspended, and this confuses many ioctl accesses
      that are blocked unexpectedly.
      
      In details, we have two issues behind the scene: one is that the card
      power state is changed only when the refcount becomes zero, and
      another is that the prior auto-suspend check is kept in a boolean
      flag.  Although the latter problem is almost negligible since the
      auto-pm feature is imposed only on the primary interface, but this can
      be a potential problem on the devices with multiple interfaces.
      
      This patch addresses those issues by the following:
      
      - Replace chip->autosuspended boolean flag with chip->system_suspend
        counter
      
      - At the first system-suspend, chip->num_suspended_intf is recorded to
        chip->system_suspend
      
      - At system-resume, the card power state is restored when the
        chip->num_suspended_intf refcount reaches to chip->system_suspend,
        i.e. the state returns to the auto-suspended
      
      Also, the patch fixes yet another hidden problem by the code
      refactoring along with the fixes above: namely, when some resume
      procedure failed, the driver left chip->num_suspended_intf that was
      already decreased, and it might lead to the refcount unbalance.
      In the new code, the refcount decrement is done after the whole resume
      procedure, and the problem is avoided as well.
      
      Fixes: 0662292a ("ALSA: usb-audio: Handle normal and auto-suspend equally")
      Reported-and-tested-by: default avatarMacpaul Lin <macpaul.lin@mediatek.com>
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200603153709.6293-1-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      862b2509
  9. Mar 26, 2020
    • Takashi Iwai's avatar
      ALSA: usb-audio: Inform devices that need delayed registration · a4aad563
      Takashi Iwai authored
      The USB-audio driver may call snd_card_register() multiple times as
      its probe function is per USB interface while some USB-audio devices
      may provide multiple interfaces to assign different streams although
      they belong to the same device.  This works in most cases but the
      registration is racy, hence it may miss the device recognition,
      e.g. PA doesn't see certain devices when hotplugged.
      
      The recent addition of the delayed registration quirk allows to sync
      the registration at the last known interface, and the previous commit
      added a new module option to allow the dynamic setup for that
      purpose.
      
      Now, this patch tries to find out and notifies for such devices that
      require the delayed registration.  It shows a message like:
      
        Found post-registration device assignment: 1234abcd:02
      
      If you hit this message, you can pass delayed_register module option
      like:
      
        snd_usb_audio.delayed_register=1234abcd:02
      
      by just copying the last shown entry.  If this works, it can be added
      statically in the quirk list, registration_quirks[] found at the end
      of sound/usb/quirks.c.
      
      Link: https://lore.kernel.org/r/20200325103322.2508-4-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      a4aad563
    • Takashi Iwai's avatar
      ALSA: usb-audio: Add delayed_register option · b70038ef
      Takashi Iwai authored
      Add a new option for specifying the quirk for delayed registration of
      the certain device.  A list of devices can be passed in a form
      	ID:IFACE,ID:IFACE,ID:IFACE,....
      where ID is the 32bit hex number combo of vendor and device IDs and
      IFACE is the interface number to trigger the register.
      
      When a matching device is probed, the card registration is delayed
      until the given interface is probed.  It's needed for syncing the
      registration until the last interface when multiple interfaces are
      provided for the same card.
      
      Link: https://lore.kernel.org/r/20200325103322.2508-3-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      b70038ef
    • Takashi Iwai's avatar
      ALSA: usb-audio: Rewrite registration quirk handling · d8695bc5
      Takashi Iwai authored
      A slight refactoring of the registration quirk code.  Now it uses the
      table lookup for easy additions in future.  Also the return type was
      changed to bool, and got a few more comments.
      
      Link: https://lore.kernel.org/r/20200325103322.2508-2-tiwai@suse.de
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      d8695bc5
  10. Mar 14, 2020
  11. Jan 15, 2020
  12. Jan 13, 2020
  13. Nov 14, 2019
  14. May 30, 2019
  15. Apr 22, 2019
    • Shuah Khan's avatar
      media: sound/usb: Use Media Controller API to share media resources · 66354f18
      Shuah Khan authored
      
      Media Device Allocator API to allows multiple drivers share a media device.
      This API solves a very common use-case for media devices where one physical
      device (an USB stick) provides both audio and video. When such media device
      exposes a standard USB Audio class, a proprietary Video class, two or more
      independent drivers will share a single physical USB bridge. In such cases,
      it is necessary to coordinate access to the shared resource.
      
      Using this API, drivers can allocate a media device with the shared struct
      device as the key. Once the media device is allocated by a driver, other
      drivers can get a reference to it. The media device is released when all
      the references are released.
      
      Change the ALSA driver to use the Media Controller API to share media
      resources with DVB, and V4L2 drivers on a AU0828 media device.
      
      The Media Controller specific initialization is done after sound card is
      registered. ALSA creates Media interface and entity function graph nodes
      for Control, Mixer, PCM Playback, and PCM Capture devices.
      
      snd_usb_hw_params() will call Media Controller enable source handler
      interface to request the media resource. If resource request is granted,
      it will release it from snd_usb_hw_free(). If resource is busy, -EBUSY is
      returned.
      
      Media specific cleanup is done in usb_audio_disconnect().
      
      Reviewed-by: default avatarTakashi Iwai <tiwai@suse.de>
      Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
      Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
      Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
      66354f18
  16. Jan 15, 2019
  17. Jan 07, 2019
  18. Dec 03, 2018
  19. Jul 31, 2018
  20. May 29, 2018
    • Takashi Iwai's avatar
      ALSA: usb-audio: Allow non-vmalloc buffer for PCM buffers · f274baa4
      Takashi Iwai authored
      
      Currently, USB-audio driver allocates the PCM buffer via vmalloc(), as
      this serves merely as an intermediate buffer that is copied to each
      URB transfer buffer.  This works well in general on x86, but on some
      archs this may result in cache coherency issues when mmap is used.
      OTOH, it works also on such arch unless mmap is used.
      
      This patch is a step for mitigating the inconvenience; a new module
      option "use_vmalloc" is provided so that user can choose to allocate
      the DMA coherent buffer instead of the existing vmalloc buffer.
      The drawback is that it'd be the standard dma_alloc_coherent() calls
      and the system would require contiguous pages on non-x86 archs.
      
      Note that it's a global option and not dynamically switchable since
      the buffer is pre-allocated at the probe time.  In theory, it's
      possible to be switchable, but it'd be trickier and racier.
      
      As default use_vmalloc option is set to true, so that the old behavior
      is kept.  For allowing the coherent mmap on ARM or MIPS, pass
      use_vmalloc=0 option explicitly.
      
      Reported-and-tested-by: default avatarDaniel Danzberger <daniel@dd-wrt.com>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      f274baa4
  21. May 28, 2018
  22. May 13, 2018
    • Ruslan Bilovol's avatar
      ALSA: usb: add UAC3 BADD profiles support · 17156f23
      Ruslan Bilovol authored
      
      Recently released USB Audio Class 3.0 specification
      contains BADD (Basic Audio Device Definition) document
      which describes pre-defined UAC3 configurations.
      
      BADD support is mandatory for UAC3 devices, it should be
      implemented as a separate USB device configuration.
      As per BADD document, class-specific descriptors
      shall not be included in the Device’s Configuration
      descriptor ("inferred"), but host can guess them
      from BADD profile number, number of endpoints and
      their max packed sizes.
      
      This patch adds support of all BADD profiles from the spec
      
      Signed-off-by: default avatarRuslan Bilovol <ruslan.bilovol@gmail.com>
      Tested-by: default avatarJorge Sanjuan <jorge.sanjuan@codethink.co.uk>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      17156f23
  23. May 04, 2018
  24. May 02, 2018
    • Takashi Iwai's avatar
      ALSA: usb-audio: Allow to override the longname string · 07eca5fc
      Takashi Iwai authored
      
      Historically USB-audio driver sets the card's longname field with the
      details of the device and the bus information.  It's good per se, but
      not preferable when it's referred as the identifier for UCM profile.
      
      This patch adds a quirk profile_name field to override the card's
      longname string to a pre-defined one, so that one can create a unique
      and consistent ID string for the specific USB device via a quirk table
      to be used as a UCM profile name.
      
      The patch does a slight code refactoring to split out the functions to
      set shortname and longname fields as well.
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      07eca5fc
  25. Mar 21, 2018
    • Ruslan Bilovol's avatar
      ALSA: usb: initial USB Audio Device Class 3.0 support · 9a2fe9b8
      Ruslan Bilovol authored
      
      Recently released USB Audio Class 3.0 specification
      introduces many significant changes comparing to
      previous versions, like
       - new Power Domains, support for LPM/L1
       - new Cluster descriptor
       - changed layout of all class-specific descriptors
       - new High Capability descriptors
       - New class-specific String descriptors
       - new and removed units
       - additional sources for interrupts
       - removed Type II Audio Data Formats
       - ... and many other things (check spec)
      
      It also provides backward compatibility through
      multiple configurations, as well as requires
      mandatory support for BADD (Basic Audio Device
      Definition) on each ADC3.0 compliant device
      
      This patch adds initial support of UAC3 specification
      that is enough for Generic I/O Profile (BAOF, BAIF)
      device support from BADD document.
      
      Signed-off-by: default avatarRuslan Bilovol <ruslan.bilovol@gmail.com>
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      9a2fe9b8
  26. Nov 30, 2017
  27. Sep 22, 2017
    • Takashi Iwai's avatar
      ALSA: usb-audio: Check out-of-bounds access by corrupted buffer descriptor · bfc81a8b
      Takashi Iwai authored
      
      When a USB-audio device receives a maliciously adjusted or corrupted
      buffer descriptor, the USB-audio driver may access an out-of-bounce
      value at its parser.  This was detected by syzkaller, something like:
      
        BUG: KASAN: slab-out-of-bounds in usb_audio_probe+0x27b2/0x2ab0
        Read of size 1 at addr ffff88006b83a9e8 by task kworker/0:1/24
        CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted 4.14.0-rc1-42251-gebb2c2437d80 #224
        Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
        Workqueue: usb_hub_wq hub_event
        Call Trace:
         __dump_stack lib/dump_stack.c:16
         dump_stack+0x292/0x395 lib/dump_stack.c:52
         print_address_description+0x78/0x280 mm/kasan/report.c:252
         kasan_report_error mm/kasan/report.c:351
         kasan_report+0x22f/0x340 mm/kasan/report.c:409
         __asan_report_load1_noabort+0x19/0x20 mm/kasan/report.c:427
         snd_usb_create_streams sound/usb/card.c:248
         usb_audio_probe+0x27b2/0x2ab0 sound/usb/card.c:605
         usb_probe_interface+0x35d/0x8e0 drivers/usb/core/driver.c:361
         really_probe drivers/base/dd.c:413
         driver_probe_device+0x610/0xa00 drivers/base/dd.c:557
         __device_attach_driver+0x230/0x290 drivers/base/dd.c:653
         bus_for_each_drv+0x161/0x210 drivers/base/bus.c:463
         __device_attach+0x26e/0x3d0 drivers/base/dd.c:710
         device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
         bus_probe_device+0x1eb/0x290 drivers/base/bus.c:523
         device_add+0xd0b/0x1660 drivers/base/core.c:1835
         usb_set_configuration+0x104e/0x1870 drivers/usb/core/message.c:1932
         generic_probe+0x73/0xe0 drivers/usb/core/generic.c:174
         usb_probe_device+0xaf/0xe0 drivers/usb/core/driver.c:266
         really_probe drivers/base/dd.c:413
         driver_probe_device+0x610/0xa00 drivers/base/dd.c:557
         __device_attach_driver+0x230/0x290 drivers/base/dd.c:653
         bus_for_each_drv+0x161/0x210 drivers/base/bus.c:463
         __device_attach+0x26e/0x3d0 drivers/base/dd.c:710
         device_initial_probe+0x1f/0x30 drivers/base/dd.c:757
         bus_probe_device+0x1eb/0x290 drivers/base/bus.c:523
         device_add+0xd0b/0x1660 drivers/base/core.c:1835
         usb_new_device+0x7b8/0x1020 drivers/usb/core/hub.c:2457
         hub_port_connect drivers/usb/core/hub.c:4903
         hub_port_connect_change drivers/usb/core/hub.c:5009
         port_event drivers/usb/core/hub.c:5115
         hub_event+0x194d/0x3740 drivers/usb/core/hub.c:5195
         process_one_work+0xc7f/0x1db0 kernel/workqueue.c:2119
         worker_thread+0x221/0x1850 kernel/workqueue.c:2253
         kthread+0x3a1/0x470 kernel/kthread.c:231
         ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431
      
      This patch adds the checks of out-of-bounce accesses at appropriate
      places and bails out when it goes out of the given buffer.
      
      Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Tested-by: default avatarAndrey Konovalov <andreyknvl@google.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      bfc81a8b
  28. Aug 06, 2017
  29. Mar 31, 2017
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fake also USB device id when alias is given · 03a1f48e
      Takashi Iwai authored
      
      Recently snd-usb-audio driver received a new option, quirk_alias, to
      allow user to apply the existing quirk for a different device.  This
      works for many quirks as is, but some still need more tune-ups:
      namely, some quirks check the USB vendor/device IDs in various places,
      thus it doesn't work as long as the ID is different from the expected
      one.
      
      With this patch, the driver stores the aliased USB ID, so that these
      rest quirks per device ID are applied.  The transition to use the
      cached USB ID was already done in the past, so what we needed now is
      only to overwrite chip->usb_id.
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      03a1f48e
  30. Nov 29, 2016
  31. Nov 14, 2016
    • Takashi Iwai's avatar
      ALSA: usb-audio: Fix use-after-free of usb_device at disconnect · 6ff1a253
      Takashi Iwai authored
      
      The usb-audio driver implements the deferred device disconnection for
      the device in use.  In this mode, the disconnection callback returns
      immediately while the actual ALSA card object removal happens later
      when all files get closed.  As Shuah reported, this code flow,
      however, leads to a use-after-free, detected by KASAN:
      
       BUG: KASAN: use-after-free in snd_usb_audio_free+0x134/0x160 [snd_usb_audio] at addr ffff8801c863ce10
       Write of size 8 by task pulseaudio/2244
       Call Trace:
        [<ffffffff81b31473>] dump_stack+0x67/0x94
        [<ffffffff81564ef1>] kasan_object_err+0x21/0x70
        [<ffffffff8156518a>] kasan_report_error+0x1fa/0x4e0
        [<ffffffff81564ad7>] ? kasan_slab_free+0x87/0xb0
        [<ffffffff81565733>] __asan_report_store8_noabort+0x43/0x50
        [<ffffffffa0fc0f54>] ? snd_usb_audio_free+0x134/0x160 [snd_usb_audio]
        [<ffffffffa0fc0f54>] snd_usb_audio_free+0x134/0x160 [snd_usb_audio]
        [<ffffffffa0fc0fb1>] snd_usb_audio_dev_free+0x31/0x40 [snd_usb_audio]
        [<ffffffff8243c78a>] __snd_device_free+0x12a/0x210
        [<ffffffff8243d1f5>] snd_device_free_all+0x85/0xd0
        [<ffffffff8242cae4>] release_card_device+0x34/0x130
        [<ffffffff81ef1846>] device_release+0x76/0x1e0
        [<ffffffff81b37ad7>] kobject_release+0x107/0x370
        .....
       Object at ffff8801c863cc80, in cache kmalloc-2048 size: 2048
       Allocated:
        [<ffffffff810804eb>] save_stack_trace+0x2b/0x50
        [<ffffffff81564296>] save_stack+0x46/0xd0
        [<ffffffff8156450d>] kasan_kmalloc+0xad/0xe0
        [<ffffffff81560d1a>] kmem_cache_alloc_trace+0xfa/0x240
        [<ffffffff8214ea47>] usb_alloc_dev+0x57/0xc90
        [<ffffffff8216349d>] hub_event+0xf1d/0x35f0
        ....
       Freed:
        [<ffffffff810804eb>] save_stack_trace+0x2b/0x50
        [<ffffffff81564296>] save_stack+0x46/0xd0
        [<ffffffff81564ac1>] kasan_slab_free+0x71/0xb0
        [<ffffffff81560929>] kfree+0xd9/0x280
        [<ffffffff8214de6e>] usb_release_dev+0xde/0x110
        [<ffffffff81ef1846>] device_release+0x76/0x1e0
        ....
      
      It's the code trying to clear drvdata of the assigned usb_device where
      the usb_device itself was already released in usb_release_dev() after
      the disconnect callback.
      
      This patch fixes it by checking whether the code path is via the
      disconnect callback, i.e. chip->shutdown flag is set.
      
      Fixes: 79289e24 ('ALSA: usb-audio: Refer to chip->usb_id for quirks...')
      Reported-and-tested-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
      Cc: <stable@vger.kernel.org> # v4.6+
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      6ff1a253
  32. Jul 18, 2016
  33. May 08, 2016
  34. Mar 31, 2016
  35. Mar 03, 2016
Loading