1. 21 5月, 2019 2 次提交
  2. 03 5月, 2019 2 次提交
  3. 25 4月, 2019 1 次提交
  4. 20 4月, 2019 1 次提交
    • A
      USB: core: Fix bug caused by duplicate interface PM usage counter · c2b71462
      Alan Stern 提交于
      The syzkaller fuzzer reported a bug in the USB hub driver which turned
      out to be caused by a negative runtime-PM usage counter.  This allowed
      a hub to be runtime suspended at a time when the driver did not expect
      it.  The symptom is a WARNING issued because the hub's status URB is
      submitted while it is already active:
      
      	URB 0000000031fb463e submitted while active
      	WARNING: CPU: 0 PID: 2917 at drivers/usb/core/urb.c:363
      
      The negative runtime-PM usage count was caused by an unfortunate
      design decision made when runtime PM was first implemented for USB.
      At that time, USB class drivers were allowed to unbind from their
      interfaces without balancing the usage counter (i.e., leaving it with
      a positive count).  The core code would take care of setting the
      counter back to 0 before allowing another driver to bind to the
      interface.
      
      Later on when runtime PM was implemented for the entire kernel, the
      opposite decision was made: Drivers were required to balance their
      runtime-PM get and put calls.  In order to maintain backward
      compatibility, however, the USB subsystem adapted to the new
      implementation by keeping an independent usage counter for each
      interface and using it to automatically adjust the normal usage
      counter back to 0 whenever a driver was unbound.
      
      This approach involves duplicating information, but what is worse, it
      doesn't work properly in cases where a USB class driver delays
      decrementing the usage counter until after the driver's disconnect()
      routine has returned and the counter has been adjusted back to 0.
      Doing so would cause the usage counter to become negative.  There's
      even a warning about this in the USB power management documentation!
      
      As it happens, this is exactly what the hub driver does.  The
      kick_hub_wq() routine increments the runtime-PM usage counter, and the
      corresponding decrement is carried out by hub_event() in the context
      of the hub_wq work-queue thread.  This work routine may sometimes run
      after the driver has been unbound from its interface, and when it does
      it causes the usage counter to go negative.
      
      It is not possible for hub_disconnect() to wait for a pending
      hub_event() call to finish, because hub_disconnect() is called with
      the device lock held and hub_event() acquires that lock.  The only
      feasible fix is to reverse the original design decision: remove the
      duplicate interface-specific usage counter and require USB drivers to
      balance their runtime PM gets and puts.  As far as I know, all
      existing drivers currently do this.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-and-tested-by: syzbot+7634edaea4d0b341c625@syzkaller.appspotmail.com
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c2b71462
  5. 17 4月, 2019 1 次提交
    • A
      USB: core: Don't unbind interfaces following device reset failure · 381419fa
      Alan Stern 提交于
      The SCSI core does not like to have devices or hosts unregistered
      while error recovery is in progress.  Trying to do so can lead to
      self-deadlock: Part of the removal code tries to obtain a lock already
      held by the error handler.
      
      This can cause problems for the usb-storage and uas drivers, because
      their error handler routines perform a USB reset, and if the reset
      fails then the USB core automatically goes on to unbind all drivers
      from the device's interfaces -- all while still in the context of the
      SCSI error handler.
      
      As it turns out, practically all the scenarios leading to a USB reset
      failure end up causing a device disconnect (the main error pathway in
      usb_reset_and_verify_device(), at the end of the routine, calls
      hub_port_logical_disconnect() before returning).  As a result, the
      hub_wq thread will soon become aware of the problem and will unbind
      all the device's drivers in its own context, not in the
      error-handler's context.
      
      This means that usb_reset_device() does not need to call
      usb_unbind_and_rebind_marked_interfaces() in cases where
      usb_reset_and_verify_device() has returned an error, because hub_wq
      will take care of everything anyway.
      
      This particular problem was observed in somewhat artificial
      circumstances, by using usbfs to tell a hub to power-down a port
      connected to a USB-3 mass storage device using the UAS protocol.  With
      the port turned off, the currently executing command timed out and the
      error handler started running.  The USB reset naturally failed,
      because the hub port was off, and the error handler deadlocked as
      described above.  Not carrying out the call to
      usb_unbind_and_rebind_marked_interfaces() fixes this issue.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: NKento Kobayashi <Kento.A.Kobayashi@sony.com>
      Tested-by: NKento Kobayashi <Kento.A.Kobayashi@sony.com>
      CC: Bart Van Assche <bvanassche@acm.org>
      CC: Martin K. Petersen <martin.petersen@oracle.com>
      CC: Jacky Cao <Jacky.Cao@sony.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      381419fa
  6. 16 4月, 2019 2 次提交
    • A
      USB: core: Fix unterminated string returned by usb_string() · c01c348e
      Alan Stern 提交于
      Some drivers (such as the vub300 MMC driver) expect usb_string() to
      return a properly NUL-terminated string, even when an error occurs.
      (In fact, vub300's probe routine doesn't bother to check the return
      code from usb_string().)  When the driver goes on to use an
      unterminated string, it leads to kernel errors such as
      stack-out-of-bounds, as found by the syzkaller USB fuzzer.
      
      An out-of-range string index argument is not at all unlikely, given
      that some devices don't provide string descriptors and therefore list
      0 as the value for their string indexes.  This patch makes
      usb_string() return a properly terminated empty string along with the
      -EINVAL error code when an out-of-range index is encountered.
      
      And since a USB string index is a single-byte value, indexes >= 256
      are just as invalid as values of 0 or below.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: syzbot+b75b85111c10b8d680f1@syzkaller.appspotmail.com
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c01c348e
    • M
      USB: hub: Remove returned value 'status' since never used · 3bee346b
      Mathieu Malaterre 提交于
      The returned value in status has never been used since
      commit 4296c70a ("USB/xHCI: Enable USB 3.0 hub remote wakeup.")
      So remove 'status' completely.
      
      Remove warning (W=1):
      
        drivers/usb/core/hub.c:3671:8: warning: variable 'status' set but not used [-Wunused-but-set-variable]
      Signed-off-by: NMathieu Malaterre <malat@debian.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3bee346b
  7. 26 3月, 2019 3 次提交
  8. 02 3月, 2019 1 次提交
  9. 28 2月, 2019 1 次提交
  10. 22 2月, 2019 1 次提交
  11. 20 2月, 2019 2 次提交
  12. 19 2月, 2019 1 次提交
    • G
      usb: core: config: Use struct_size() in kzalloc() · 5ebf5c89
      Gustavo A. R. Silva 提交于
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct foo {
          int stuff;
          struct boo entry[];
      };
      
      size = sizeof(struct foo) + count * sizeof(struct boo);
      instance = kzalloc(size, GFP_KERNEL);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
      
      Notice that, in this case, variable len is not necessary, hence
      it is removed.
      
      This code was detected with the help of Coccinelle.
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5ebf5c89
  13. 08 2月, 2019 2 次提交
    • N
      USB: Fix configuration selection issues introduced in v4.20.0 · 25b01614
      Nikolay Yakimov 提交于
      Commit f13912d3 introduced changes to the usb_choose_configuration function
      to better support USB Audio UAC3-compatible devices. However, there are a few
      problems with this patch. First of all, it adds new "if" clauses in the middle
      of an existing "if"/"else if" tree, which obviously breaks pre-existing logic.
      Secondly, since it continues iterating over configurations in one of the branches,
      other code in the loop can choose an unintended configuration. Finally,
      if an audio device's first configuration is UAC3-compatible, and there
      are multiple UAC3 configurations, the second one would be chosen, due to
      the first configuration never being checked for UAC3-compatibility.
      
      Commit ff2a8c53 tries to fix the second issue, but it goes about it in a
      somewhat unnecessarily convoluted way, in my opinion, and does nothing
      to fix the first or the last one.
      
      This patch tries to rectify problems described by essentially rewriting
      code introduced in f13912d3. Notice the code was moved to *before*
      the "if"/"else if" tree.
      Signed-off-by: NNikolay Yakimov <root@livid.pp.ru>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      25b01614
    • J
      usb: handle warm-reset port requests on hub resume · 4fdc1790
      Jan-Marek Glogowski 提交于
      On plug-in of my USB-C device, its USB_SS_PORT_LS_SS_INACTIVE
      link state bit is set. Greping all the kernel for this bit shows
      that the port status requests a warm-reset this way.
      
      This just happens, if its the only device on the root hub, the hub
      therefore resumes and the HCDs status_urb isn't yet available.
      If a warm-reset request is detected, this sets the hubs event_bits,
      which will prevent any auto-suspend and allows the hubs workqueue
      to warm-reset the port later in port_event.
      Signed-off-by: NJan-Marek Glogowski <glogow@fbihome.de>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4fdc1790
  14. 04 2月, 2019 1 次提交
  15. 30 1月, 2019 1 次提交
  16. 25 1月, 2019 2 次提交
  17. 22 1月, 2019 1 次提交
  18. 18 1月, 2019 4 次提交
    • K
      USB: Consolidate LPM checks to avoid enabling LPM twice · d7a6c0ce
      Kai-Heng Feng 提交于
      USB Bluetooth controller QCA ROME (0cf3:e007) sometimes stops working
      after S3:
      [ 165.110742] Bluetooth: hci0: using NVM file: qca/nvm_usb_00000302.bin
      [ 168.432065] Bluetooth: hci0: Failed to send body at 4 of 1953 (-110)
      
      After some experiments, I found that disabling LPM can workaround the
      issue.
      
      On some platforms, the USB power is cut during S3, so the driver uses
      reset-resume to resume the device. During port resume, LPM gets enabled
      twice, by usb_reset_and_verify_device() and usb_port_resume().
      
      Consolidate all checks into new LPM helpers to make sure LPM only gets
      enabled once.
      
      Fixes: de68bab4 ("usb: Don't enable USB 2.0 Link PM by default.”)
      Signed-off-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: stable <stable@vger.kernel.org> # after much soaking
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d7a6c0ce
    • K
      USB: Add new USB LPM helpers · 7529b257
      Kai-Heng Feng 提交于
      Use new helpers to make LPM enabling/disabling more clear.
      
      This is a preparation to subsequent patch.
      Signed-off-by: NKai-Heng Feng <kai.heng.feng@canonical.com>
      Cc: stable <stable@vger.kernel.org> # after much soaking
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7529b257
    • N
      usb: hub: add retry routine after intr URB submit error · 8eb58994
      Nicolas Saenz Julienne 提交于
      The hub sends hot-plug events to the host trough it's interrupt URB. The
      driver takes care of completing the URB and re-submitting it. Completion
      errors are handled in the hub_event() work, yet submission errors are
      ignored, rendering the device unresponsive. All further events are lost.
      
      It is fairly hard to find this issue in the wild, since you have to time
      the USB hot-plug event with the URB submission failure. For instance it
      could be the system running out of memory or some malfunction in the USB
      controller driver. Nevertheless, it's pretty reasonable to think it'll
      happen sometime. One can trigger this issue using eBPF's function
      override feature (see BCC's inject.py script).
      
      This patch adds a retry routine to the event of a submission error. The
      HUB driver will try to re-submit the URB once every second until it's
      successful or the HUB is disconnected.
      
      As some USB subsystems already take care of this issue, the
      implementation was inspired from usbhid/hid_core.c's.
      Signed-off-by: NNicolas Saenz Julienne <nsaenzjulienne@suse.de>
      Reviewed-by: NOliver Neukum <oneukum@suse.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8eb58994
    • C
      USB: leds: fix regression in usbport led trigger · 91f7d2e8
      Christian Lamparter 提交于
      The patch "usb: simplify usbport trigger" together with "leds: triggers:
      add device attribute support" caused an regression for the usbport
      trigger. it will no longer enumerate any active usb hub ports under the
      "ports" directory in the sysfs class directory, if the usb host drivers
      are fully initialized before the usbport trigger was loaded.
      
      The reason is that the usbport driver tries to register the sysfs
      entries during the activate() callback. And this will fail with -2 /
      ENOENT because the patch "leds: triggers: add device attribute support"
      made it so that the sysfs "ports" group was only being added after the
      activate() callback succeeded.
      
      This version of the patch reverts parts of the "usb: simplify usbport
      trigger" patch and restores usbport trigger's functionality.
      
      Fixes: 6f7b0bad ("usb: simplify usbport trigger")
      Signed-off-by: NChristian Lamparter <chunkeey@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: NJacek Anaszewski <jacek.anaszewski@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      91f7d2e8
  19. 08 1月, 2019 5 次提交
  20. 04 1月, 2019 1 次提交
    • L
      Remove 'type' argument from access_ok() function · 96d4f267
      Linus Torvalds 提交于
      Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
      of the user address range verification function since we got rid of the
      old racy i386-only code to walk page tables by hand.
      
      It existed because the original 80386 would not honor the write protect
      bit when in kernel mode, so you had to do COW by hand before doing any
      user access.  But we haven't supported that in a long time, and these
      days the 'type' argument is a purely historical artifact.
      
      A discussion about extending 'user_access_begin()' to do the range
      checking resulted this patch, because there is no way we're going to
      move the old VERIFY_xyz interface to that model.  And it's best done at
      the end of the merge window when I've done most of my merges, so let's
      just get this done once and for all.
      
      This patch was mostly done with a sed-script, with manual fix-ups for
      the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
      
      There were a couple of notable cases:
      
       - csky still had the old "verify_area()" name as an alias.
      
       - the iter_iov code had magical hardcoded knowledge of the actual
         values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
         really used it)
      
       - microblaze used the type argument for a debug printout
      
      but other than those oddities this should be a total no-op patch.
      
      I tried to fix up all architectures, did fairly extensive grepping for
      access_ok() uses, and the changes are trivial, but I may have missed
      something.  Any missed conversion should be trivially fixable, though.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      96d4f267
  21. 12 12月, 2018 1 次提交
  22. 06 12月, 2018 1 次提交
  23. 05 12月, 2018 3 次提交
    • H
      usb: quirk: add no-LPM quirk on SanDisk Ultra Flair device · 2f2dde6b
      Harry Pan 提交于
      Some lower volume SanDisk Ultra Flair in 16GB, which the VID:PID is
      in 0781:5591, will aggressively request LPM of U1/U2 during runtime,
      when using this thumb drive as the OS installation key we found the
      device will generate failure during U1 exit path making it dropped
      from the USB bus, this causes a corrupted installation in system at
      the end.
      
      i.e.,
      [  166.918296] hub 2-0:1.0: state 7 ports 7 chg 0000 evt 0004
      [  166.918327] usb usb2-port2: link state change
      [  166.918337] usb usb2-port2: do warm reset
      [  166.970039] usb usb2-port2: not warm reset yet, waiting 50ms
      [  167.022040] usb usb2-port2: not warm reset yet, waiting 200ms
      [  167.276043] usb usb2-port2: status 02c0, change 0041, 5.0 Gb/s
      [  167.276050] usb 2-2: USB disconnect, device number 2
      [  167.276058] usb 2-2: unregistering device
      [  167.276060] usb 2-2: unregistering interface 2-2:1.0
      [  167.276170] xhci_hcd 0000:00:15.0: shutdown urb ffffa3c7cc695cc0 ep1in-bulk
      [  167.284055] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
      [  167.284064] sd 0:0:0:0: [sda] tag#0 CDB: Read(10) 28 00 00 33 04 90 00 01 00 00
      ...
      
      Analyzed the USB trace in the link layer we realized it is because
      of the 6-ms timer of tRecoveryConfigurationTimeout which documented
      on the USB 3.2 Revision 1.0, the section 7.5.10.4.2 of "Exit from
      Recovery.Configuration"; device initiates U1 exit -> Recovery.Active
      -> Recovery.Configuration, then the host timer timeout makes the link
      transits to eSS.Inactive -> Rx.Detect follows by a Warm Reset.
      
      Interestingly, the other higher volume of SanDisk Ultra Flair sharing
      the same VID:PID, such as 64GB, would not request LPM during runtime,
      it sticks at U0 always, thus disabling LPM does not affect those thumb
      drives at all.
      
      The same odd occures in SanDisk Ultra Fit 16GB, VID:PID in 0781:5583.
      Signed-off-by: NHarry Pan <harry.pan@intel.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2f2dde6b
    • A
      USB: Fix invalid-free bug in port_over_current_notify() · d81bb019
      Alan Stern 提交于
      Syzbot and KASAN found the following invalid-free bug in
      port_over_current_notify():
      
      --------------------------------------------------------------------------
      BUG: KASAN: double-free or invalid-free in port_over_current_notify
      drivers/usb/core/hub.c:5192 [inline]
      BUG: KASAN: double-free or invalid-free in port_event
      drivers/usb/core/hub.c:5241 [inline]
      BUG: KASAN: double-free or invalid-free in hub_event+0xd97/0x4140
      drivers/usb/core/hub.c:5384
      
      CPU: 1 PID: 32710 Comm: kworker/1:3 Not tainted 4.20.0-rc3+ #129
      Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
      Google 01/01/2011
      Workqueue: usb_hub_wq hub_event
      Call Trace:
        __dump_stack lib/dump_stack.c:77 [inline]
        dump_stack+0x244/0x39d lib/dump_stack.c:113
        print_address_description.cold.7+0x9/0x1ff mm/kasan/report.c:256
        kasan_report_invalid_free+0x64/0xa0 mm/kasan/report.c:336
        __kasan_slab_free+0x13a/0x150 mm/kasan/kasan.c:501
        kasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
        __cache_free mm/slab.c:3498 [inline]
        kfree+0xcf/0x230 mm/slab.c:3817
        port_over_current_notify drivers/usb/core/hub.c:5192 [inline]
        port_event drivers/usb/core/hub.c:5241 [inline]
        hub_event+0xd97/0x4140 drivers/usb/core/hub.c:5384
        process_one_work+0xc90/0x1c40 kernel/workqueue.c:2153
        worker_thread+0x17f/0x1390 kernel/workqueue.c:2296
        kthread+0x35a/0x440 kernel/kthread.c:246
        ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
      --------------------------------------------------------------------------
      
      The problem is caused by use of a static array to store
      environment-string pointers.  When the routine is called by multiple
      threads concurrently, the pointers from one thread can overwrite those
      from another.
      
      The solution is to use an ordinary automatic array instead of a static
      array.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: syzbot+98881958e1410ec7e53c@syzkaller.appspotmail.com
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d81bb019
    • M
      usb: hub: delay hub autosuspend if USB3 port is still link training · e8610894
      Mathias Nyman 提交于
      When initializing a hub we want to give a USB3 port in link training
      the same debounce delay time before autosuspening the hub as already
      trained, connected enabled ports.
      
      USB3 ports won't reach the enabled state with "current connect status" and
      "connect status change" bits set until the USB3 link training finishes.
      
      Catching the port in link training (polling) and adding the debounce delay
      prevents unnecessary failed attempts to autosuspend the hub.
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e8610894