1. 31 8月, 2016 2 次提交
  2. 09 8月, 2016 8 次提交
    • P
      usb: core: of.c: fix defined but not declare warning · 0573f2c5
      Peter Chen 提交于
      The helper usb_of_get_child_node is defined at of.c, but missing its
      declare as a global function. Fix it by adding related header file
      as well as compile it on conditional of CONFIG_OF.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: linux-usb@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Cc: Ben Dooks <ben.dooks@codethink.co.uk>
      Cc: linux-kernel@lists.codethink.co.uk
      Signed-off-by: NPeter Chen <peter.chen@nxp.com>
      Reported-by: NBen Dooks <ben.dooks@codethink.co.uk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0573f2c5
    • M
      usb: remove redundant dependency on USB_SUPPORT · a26a1422
      Masahiro Yamada 提交于
      The whole Kconfig entries of the USB subsystem are surrounded with
      "if USB_SUPPORT" ... "endif", so CONFIG_USB_SUPPORT=y is surely met
      when these two Kconfig options are visible.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a26a1422
    • A
      USB: remove race condition in usbfs/libusb when using reap-after-disconnect · 5cce4382
      Alan Stern 提交于
      Hans de Goede has reported a difficulty in the Linux port of libusb.
      When a device is removed, the poll() system call in usbfs starts
      returning POLLERR as soon as udev->state is set to
      USB_STATE_NOTATTACHED, but the outstanding URBs are not available for
      reaping until some time later (after usbdev_remove() has been called).
      This is awkward for libusb or other usbfs clients, although not an
      insuperable problem.
      
      At any rate, it's easy to change usbfs so that it returns POLLHUP as
      soon as the state becomes USB_STATE_NOTATTACHED but it doesn't return
      POLLERR until after the outstanding URBs have completed.  That's what
      this patch does; it uses the fact that ps->list is always on the
      dev->filelist list until usbdev_remove() takes it off, which happens
      after all the outstanding URBs have been cancelled.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5cce4382
    • J
      usb: devio, do not warn when allocation fails · 70f7ca9a
      Jiri Slaby 提交于
      usbdev_mmap allocates a buffer. The size of the buffer is determined
      by a user. So with this code (no need to be root):
      
      	int fd = open("/dev/bus/usb/001/001", O_RDONLY);
      	mmap(NULL, 0x800000, PROT_READ, MAP_SHARED, fd, 0);
      
      we can see a warning:
      
      WARNING: CPU: 0 PID: 21771 at ../mm/page_alloc.c:3563 __alloc_pages_slowpath+0x1036/0x16e0()
      ...
      Call Trace:
       [<ffffffff8117a3ae>] ? warn_slowpath_null+0x2e/0x40
       [<ffffffff815178b6>] ? __alloc_pages_slowpath+0x1036/0x16e0
       [<ffffffff81516880>] ? warn_alloc_failed+0x250/0x250
       [<ffffffff8151226b>] ? get_page_from_freelist+0x75b/0x28b0
       [<ffffffff815184e3>] ? __alloc_pages_nodemask+0x583/0x6b0
       [<ffffffff81517f60>] ? __alloc_pages_slowpath+0x16e0/0x16e0
       [<ffffffff810565d4>] ? dma_generic_alloc_coherent+0x104/0x220
       [<ffffffffa0269e56>] ? hcd_buffer_alloc+0x1d6/0x3e0 [usbcore]
       [<ffffffffa0269c80>] ? hcd_buffer_destroy+0xa0/0xa0 [usbcore]
       [<ffffffffa0228f05>] ? usb_alloc_coherent+0x65/0x90 [usbcore]
       [<ffffffffa0275c05>] ? usbdev_mmap+0x1a5/0x770 [usbcore]
      ...
      
      Allocations like this one should be marked as __GFP_NOWARN. So do so.
      
      The size could be also clipped by something like:
      	if (size >= (1 << (MAX_ORDER + PAGE_SHIFT - 1)))
      		return -ENOMEM;
      But I think the overall limit of 16M (by usbfs_increase_memory_usage)
      is enough, so that we only silence the warning here.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: Steinar H. Gunderson <sesse@google.com>
      Cc: Markus Rechberger <mrechberger@gmail.com>
      Fixes: f7d34b44 (USB: Add support for usbfs zerocopy.)
      Cc: 4.6+ <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70f7ca9a
    • A
      USB: validate wMaxPacketValue entries in endpoint descriptors · aed9d65a
      Alan Stern 提交于
      Erroneous or malicious endpoint descriptors may have non-zero bits in
      reserved positions, or out-of-bounds values.  This patch helps prevent
      these from causing problems by bounds-checking the wMaxPacketValue
      entries in endpoint descriptors and capping the values at the maximum
      allowed.
      
      This issue was first discovered and tests were conducted by Jake Lamberson
      <jake.lamberson1@gmail.com>, an intern working for Rosie Hall.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: Nroswest <roswest@cisco.com>
      Tested-by: Nroswest <roswest@cisco.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aed9d65a
    • A
      USB: hub: change the locking in hub_activate · 07d316a2
      Alan Stern 提交于
      The locking in hub_activate() is not adequate to provide full mutual
      exclusion with hub_quiesce().  The subroutine locks the hub's
      usb_interface, but the callers of hub_quiesce() (such as
      hub_pre_reset() and hub_event()) hold the lock to the hub's
      usb_device.
      
      This patch changes hub_activate() to make it acquire the same lock as
      those other routines.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      CC: <stable@vger.kernel.org> #4.4+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      07d316a2
    • A
      USB: hub: fix up early-exit pathway in hub_activate · ca5cbc8b
      Alan Stern 提交于
      The early-exit pathway in hub_activate, added by commit e50293ef
      ("USB: fix invalid memory access in hub_activate()") needs
      improvement.  It duplicates code that is already present at the end of
      the subroutine, and it neglects to undo the effect of a
      usb_autopm_get_interface_no_resume() call.
      
      This patch fixes both problems by making the early-exit pathway jump
      directly to the end of the subroutine.  It simplifies the code at the
      end by merging two conditionals that actually test the same condition
      although they appear different: If type < HUB_INIT3 then type must be
      either HUB_INIT2 or HUB_INIT, and it can't be HUB_INIT because in that
      case the subroutine would have exited earlier.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      CC: <stable@vger.kernel.org> #4.4+
      Reviewed-by: NViresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ca5cbc8b
    • V
      usb: hub: Fix unbalanced reference count/memory leak/deadlocks · 6bb47e8a
      Viresh Kumar 提交于
      Memory leak and unbalanced reference count:
      
      If the hub gets disconnected while the core is still activating it, this
      can result in leaking memory of few USB structures.
      
      This will happen if we have done a kref_get() from hub_activate() and
      scheduled a delayed work item for HUB_INIT2/3. Now if hub_disconnect()
      gets called before the delayed work expires, then we will cancel the
      work from hub_quiesce(), but wouldn't do a kref_put(). And so the
      unbalance.
      
      kmemleak reports this as (with the commit e50293ef backported to
      3.10 kernel with other changes, though the same is true for mainline as
      well):
      
      unreferenced object 0xffffffc08af5b800 (size 1024):
        comm "khubd", pid 73, jiffies 4295051211 (age 6482.350s)
        hex dump (first 32 bytes):
          30 68 f3 8c c0 ff ff ff 00 a0 b2 2e c0 ff ff ff  0h..............
          01 00 00 00 00 00 00 00 00 94 7d 40 c0 ff ff ff  ..........}@....
        backtrace:
          [<ffffffc0003079ec>] create_object+0x148/0x2a0
          [<ffffffc000cc150c>] kmemleak_alloc+0x80/0xbc
          [<ffffffc000303a7c>] kmem_cache_alloc_trace+0x120/0x1ac
          [<ffffffc0006fa610>] hub_probe+0x120/0xb84
          [<ffffffc000702b20>] usb_probe_interface+0x1ec/0x298
          [<ffffffc0005d50cc>] driver_probe_device+0x160/0x374
          [<ffffffc0005d5308>] __device_attach+0x28/0x4c
          [<ffffffc0005d3164>] bus_for_each_drv+0x78/0xac
          [<ffffffc0005d4ee0>] device_attach+0x6c/0x9c
          [<ffffffc0005d42b8>] bus_probe_device+0x28/0xa0
          [<ffffffc0005d23a4>] device_add+0x324/0x604
          [<ffffffc000700fcc>] usb_set_configuration+0x660/0x6cc
          [<ffffffc00070a350>] generic_probe+0x44/0x84
          [<ffffffc000702914>] usb_probe_device+0x54/0x74
          [<ffffffc0005d50cc>] driver_probe_device+0x160/0x374
          [<ffffffc0005d5308>] __device_attach+0x28/0x4c
      
      Deadlocks:
      
      If the hub gets disconnected early enough (i.e. before INIT2/INIT3 are
      finished and the init_work is still queued), the core may call
      hub_quiesce() after acquiring interface device locks and it will wait
      for the work to be cancelled synchronously. But if the work handler is
      already running in parallel, it may try to acquire the same interface
      device lock and this may result in deadlock.
      
      Fix both the issues by removing the call to cancel_delayed_work_sync().
      
      CC: <stable@vger.kernel.org> #4.4+
      Fixes: e50293ef ("USB: fix invalid memory access in hub_activate()")
      Reported-by: NManu Gautam <mgautam@codeaurora.org>
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6bb47e8a
  3. 18 7月, 2016 1 次提交
  4. 14 7月, 2016 1 次提交
  5. 27 6月, 2016 1 次提交
    • A
      USB: don't free bandwidth_mutex too early · ab2a4bf8
      Alan Stern 提交于
      The USB core contains a bug that can show up when a USB-3 host
      controller is removed.  If the primary (USB-2) hcd structure is
      released before the shared (USB-3) hcd, the core will try to do a
      double-free of the common bandwidth_mutex.
      
      The problem was described in graphical form by Chung-Geol Kim, who
      first reported it:
      
      =================================================
           At *remove USB(3.0) Storage
           sequence <1> --> <5> ((Problem Case))
      =================================================
                                        VOLD
      ------------------------------------|------------
                                       (uevent)
                                  ________|_________
                                 |<1>               |
                                 |dwc3_otg_sm_work  |
                                 |usb_put_hcd       |
                                 |peer_hcd(kref=2)|
                                 |__________________|
                                  ________|_________
                                 |<2>               |
                                 |New USB BUS #2    |
                                 |                  |
                                 |peer_hcd(kref=1)  |
                                 |                  |
                               --(Link)-bandXX_mutex|
                               | |__________________|
                               |
          ___________________  |
         |<3>                | |
         |dwc3_otg_sm_work   | |
         |usb_put_hcd        | |
         |primary_hcd(kref=1)| |
         |___________________| |
          _________|_________  |
         |<4>                | |
         |New USB BUS #1     | |
         |hcd_release        | |
         |primary_hcd(kref=0)| |
         |                   | |
         |bandXX_mutex(free) |<-
         |___________________|
                                     (( VOLD ))
                                  ______|___________
                                 |<5>               |
                                 |      SCSI        |
                                 |usb_put_hcd       |
                                 |peer_hcd(kref=0)  |
                                 |*hcd_release      |
                                 |bandXX_mutex(free*)|<- double free
                                 |__________________|
      
      =================================================
      
      This happens because hcd_release() frees the bandwidth_mutex whenever
      it sees a primary hcd being released (which is not a very good idea
      in any case), but in the course of releasing the primary hcd, it
      changes the pointers in the shared hcd in such a way that the shared
      hcd will appear to be primary when it gets released.
      
      This patch fixes the problem by changing hcd_release() so that it
      deallocates the bandwidth_mutex only when the _last_ hcd structure
      referencing it is released.  The patch also removes an unnecessary
      test, so that when an hcd is released, both the shared_hcd and
      primary_hcd pointers in the hcd's peer will be cleared.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-by: NChung-Geol Kim <chunggeol.kim@samsung.com>
      Tested-by: NChung-Geol Kim <chunggeol.kim@samsung.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ab2a4bf8
  6. 02 6月, 2016 2 次提交
  7. 04 5月, 2016 2 次提交
    • K
      USB: usbfs: fix potential infoleak in devio · 681fef83
      Kangjie Lu 提交于
      The stack object “ci” has a total size of 8 bytes. Its last 3 bytes
      are padding bytes which are not initialized and leaked to userland
      via “copy_to_user”.
      Signed-off-by: NKangjie Lu <kjlu@gatech.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      681fef83
    • A
      USB: leave LPM alone if possible when binding/unbinding interface drivers · 6fb650d4
      Alan Stern 提交于
      When a USB driver is bound to an interface (either through probing or
      by claiming it) or is unbound from an interface, the USB core always
      disables Link Power Management during the transition and then
      re-enables it afterward.  The reason is because the driver might want
      to prevent hub-initiated link power transitions, in which case the HCD
      would have to recalculate the various LPM parameters.  This
      recalculation takes place when LPM is re-enabled and the new
      parameters are sent to the device and its parent hub.
      
      However, if the driver does not want to prevent hub-initiated link
      power transitions then none of this work is necessary.  The parameters
      don't need to be recalculated, and LPM doesn't need to be disabled and
      re-enabled.
      
      It turns out that disabling and enabling LPM can be time-consuming,
      enough so that it interferes with user programs that want to claim and
      release interfaces rapidly via usbfs.  Since the usbfs kernel driver
      doesn't set the disable_hub_initiated_lpm flag, we can speed things up
      and get the user programs to work by leaving LPM alone whenever the
      flag isn't set.
      
      And while we're improving the way disable_hub_initiated_lpm gets used,
      let's also fix its kerneldoc.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Tested-by: NMatthew Giassa <matthew@giassa.net>
      CC: Mathias Nyman <mathias.nyman@intel.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6fb650d4
  8. 02 5月, 2016 1 次提交
  9. 29 4月, 2016 4 次提交
    • P
      usb: core: move root hub's device node assignment after it is added to bus · dc5878ab
      Peter Chen 提交于
      When the root hub device is added to the bus, it tries to get pins
      information from pinctrl (see pinctrl_bind_pins, at really_probe), if
      the pin information is described at DT, it will show below error since
      the root hub's device node is the same with controller's, but controller's
      pin has already been requested when it is added to platform bus.
      
      	imx6q-pinctrl 20e0000.iomuxc: pin MX6Q_PAD_GPIO_1 already
             	requested by 2184000.usb; cannot claim for usb1
      	imx6q-pinctrl 20e0000.iomuxc: pin-137 (usb1) status -22
      	imx6q-pinctrl 20e0000.iomuxc: could not request pin 137
             	(MX6Q_PAD_GPIO_1) from group usbotggrp-3 on device 20e0000.iomuxc
      	usb usb1: Error applying setting, reverse things back
      
      To fix this issue, we move the root hub's device node assignment (equals
      to contrller's) after device is added to bus, we only need to know root
      hub's device node information after the device under root hub is created,
      so this movement will not affect current function.
      Signed-off-by: NPeter Chen <peter.chen@nxp.com>
      Reported-by: NLars Steubesand <lars.steubesand@philips.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dc5878ab
    • C
      usb: core: hub: hub_port_init lock controller instead of bus · feb26ac3
      Chris Bainbridge 提交于
      The XHCI controller presents two USB buses to the system - one for USB2
      and one for USB3. The hub init code (hub_port_init) is reentrant but
      only locks one bus per thread, leading to a race condition failure when
      two threads attempt to simultaneously initialise a USB2 and USB3 device:
      
      [    8.034843] xhci_hcd 0000:00:14.0: Timeout while waiting for setup device command
      [   13.183701] usb 3-3: device descriptor read/all, error -110
      
      On a test system this failure occurred on 6% of all boots.
      
      The call traces at the point of failure are:
      
      Call Trace:
       [<ffffffff81b9bab7>] schedule+0x37/0x90
       [<ffffffff817da7cd>] usb_kill_urb+0x8d/0xd0
       [<ffffffff8111e5e0>] ? wake_up_atomic_t+0x30/0x30
       [<ffffffff817dafbe>] usb_start_wait_urb+0xbe/0x150
       [<ffffffff817db10c>] usb_control_msg+0xbc/0xf0
       [<ffffffff817d07de>] hub_port_init+0x51e/0xb70
       [<ffffffff817d4697>] hub_event+0x817/0x1570
       [<ffffffff810f3e6f>] process_one_work+0x1ff/0x620
       [<ffffffff810f3dcf>] ? process_one_work+0x15f/0x620
       [<ffffffff810f4684>] worker_thread+0x64/0x4b0
       [<ffffffff810f4620>] ? rescuer_thread+0x390/0x390
       [<ffffffff810fa7f5>] kthread+0x105/0x120
       [<ffffffff810fa6f0>] ? kthread_create_on_node+0x200/0x200
       [<ffffffff81ba183f>] ret_from_fork+0x3f/0x70
       [<ffffffff810fa6f0>] ? kthread_create_on_node+0x200/0x200
      
      Call Trace:
       [<ffffffff817fd36d>] xhci_setup_device+0x53d/0xa40
       [<ffffffff817fd87e>] xhci_address_device+0xe/0x10
       [<ffffffff817d047f>] hub_port_init+0x1bf/0xb70
       [<ffffffff811247ed>] ? trace_hardirqs_on+0xd/0x10
       [<ffffffff817d4697>] hub_event+0x817/0x1570
       [<ffffffff810f3e6f>] process_one_work+0x1ff/0x620
       [<ffffffff810f3dcf>] ? process_one_work+0x15f/0x620
       [<ffffffff810f4684>] worker_thread+0x64/0x4b0
       [<ffffffff810f4620>] ? rescuer_thread+0x390/0x390
       [<ffffffff810fa7f5>] kthread+0x105/0x120
       [<ffffffff810fa6f0>] ? kthread_create_on_node+0x200/0x200
       [<ffffffff81ba183f>] ret_from_fork+0x3f/0x70
       [<ffffffff810fa6f0>] ? kthread_create_on_node+0x200/0x200
      
      Which results from the two call chains:
      
      hub_port_init
       usb_get_device_descriptor
        usb_get_descriptor
         usb_control_msg
          usb_internal_control_msg
           usb_start_wait_urb
            usb_submit_urb / wait_for_completion_timeout / usb_kill_urb
      
      hub_port_init
       hub_set_address
        xhci_address_device
         xhci_setup_device
      
      Mathias Nyman explains the current behaviour violates the XHCI spec:
      
       hub_port_reset() will end up moving the corresponding xhci device slot
       to default state.
      
       As hub_port_reset() is called several times in hub_port_init() it
       sounds reasonable that we could end up with two threads having their
       xhci device slots in default state at the same time, which according to
       xhci 4.5.3 specs still is a big no no:
      
       "Note: Software shall not transition more than one Device Slot to the
        Default State at a time"
      
       So both threads fail at their next task after this.
       One fails to read the descriptor, and the other fails addressing the
       device.
      
      Fix this in hub_port_init by locking the USB controller (instead of an
      individual bus) to prevent simultaneous initialisation of both buses.
      
      Fixes: 638139eb ("usb: hub: allow to process more usb hub events in parallel")
      Link: https://lkml.org/lkml/2016/2/8/312
      Link: https://lkml.org/lkml/2016/2/4/748Signed-off-by: NChris Bainbridge <chris.bainbridge@gmail.com>
      Cc: stable <stable@vger.kernel.org>
      Acked-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      feb26ac3
    • M
      usb: devio: declare usbdev_vm_ops as static · 10871c13
      Michele Curti 提交于
      usbdev_vm_ops is used in devio.c only, so declare it as static
      Signed-off-by: NMichele Curti <michele.curti@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      10871c13
    • C
      usb: core: buffer: avoid NULL pointer dereferrence · f5e6253f
      Chunfeng Yun 提交于
      NULL pointer dereferrence will happen when class driver
      wants to allocate zero length buffer and pool_max[0]
      can't be used, so simply returns NULL in the case.
      Signed-off-by: NChunfeng Yun <chunfeng.yun@mediatek.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f5e6253f
  10. 27 4月, 2016 3 次提交
  11. 14 4月, 2016 1 次提交
  12. 31 3月, 2016 1 次提交
    • M
      usb: fix regression in SuperSpeed endpoint descriptor parsing · 59b9023c
      Mathias Nyman 提交于
      commit b37d83a6 ("usb: Parse the new USB 3.1 SuperSpeedPlus Isoc
      endpoint companion descriptor") caused a regression in 4.6-rc1 and fails
      to parse SuperSpeed endpoint companion descriptors.
      
      The new SuperSpeedPlus Isoc endpoint companion parsing code incorrectly
      decreased the the remaining buffer size before comparing the size with the
      expected length of the descriptor.
      
      This lead to possible failure in reading the SuperSpeed endpoint companion
      descriptor of the last endpoint, displaying a message like:
      
      "No SuperSpeed endpoint companion for config 1 interface 0 altsetting 0
       ep 129: using minimum values"
      
      Fix it by decreasing the size after comparing it.
      Also finish all the SS endpoint companion parsing before calling SSP isoc
      endpoint parsing function.
      
      Fixes: b37d83a6Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      59b9023c
  13. 19 3月, 2016 2 次提交
    • O
      USB: usb_driver_claim_interface: add sanity checking · 0b818e39
      Oliver Neukum 提交于
      Attacks that trick drivers into passing a NULL pointer
      to usb_driver_claim_interface() using forged descriptors are
      known. This thwarts them by sanity checking.
      Signed-off-by: NOliver Neukum <ONeukum@suse.com>
      CC: stable@vger.kernel.org
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0b818e39
    • N
      usb/core: usb_alloc_dev(): fix setting of ->portnum · 7222c832
      Nicolai Stange 提交于
      With commit 69bec725 ("USB: core: let USB device know device node"),
      the port1 argument of usb_alloc_dev() gets overwritten as follows:
      
        ... usb_alloc_dev(..., unsigned port1)
        {
          ...
          if (!parent->parent) {
            port1 = usb_hcd_find_raw_port_number(..., port1);
          }
          ...
        }
      
      Later on, this now overwritten port1 gets assigned to ->portnum:
      
        dev->portnum = port1;
      
      However, since xhci_find_raw_port_number() isn't idempotent, the
      aforementioned commit causes a number of KASAN splats like the following:
      
        BUG: KASAN: slab-out-of-bounds in xhci_find_raw_port_number+0x98/0x170
                                             at addr ffff8801d9311670
        Read of size 8 by task kworker/2:1/87
        [...]
        Workqueue: usb_hub_wq hub_event
         0000000000000188 000000005814b877 ffff8800cba17588 ffffffff8191447e
         0000000041b58ab3 ffffffff82a03209 ffffffff819143a2 ffffffff82a252f4
         ffff8801d93115e0 0000000000000188 ffff8801d9311628 ffff8800cba17588
        Call Trace:
         [<ffffffff8191447e>] dump_stack+0xdc/0x15e
         [<ffffffff819143a2>] ? _atomic_dec_and_lock+0xa2/0xa2
         [<ffffffff814e2cd1>] ? print_section+0x61/0xb0
         [<ffffffff814e4939>] print_trailer+0x179/0x2c0
         [<ffffffff814f0d84>] object_err+0x34/0x40
         [<ffffffff814f4388>] kasan_report_error+0x2f8/0x8b0
         [<ffffffff814eb91e>] ? __slab_alloc+0x5e/0x90
         [<ffffffff812178c0>] ? __lock_is_held+0x90/0x130
         [<ffffffff814f5091>] kasan_report+0x71/0xa0
         [<ffffffff814ec082>] ? kmem_cache_alloc_trace+0x212/0x560
         [<ffffffff81d99468>] ? xhci_find_raw_port_number+0x98/0x170
         [<ffffffff814f33d4>] __asan_load8+0x64/0x70
         [<ffffffff81d99468>] xhci_find_raw_port_number+0x98/0x170
         [<ffffffff81db0105>] xhci_setup_addressable_virt_dev+0x235/0xa10
         [<ffffffff81d9ea51>] xhci_setup_device+0x3c1/0x1430
         [<ffffffff8121cddd>] ? trace_hardirqs_on+0xd/0x10
         [<ffffffff81d9fac0>] ? xhci_setup_device+0x1430/0x1430
         [<ffffffff81d9fad3>] xhci_address_device+0x13/0x20
         [<ffffffff81d2081a>] hub_port_init+0x55a/0x1550
         [<ffffffff81d28705>] hub_event+0xef5/0x24d0
         [<ffffffff81d27810>] ? hub_port_debounce+0x2f0/0x2f0
         [<ffffffff8195e1ee>] ? debug_object_deactivate+0x1be/0x270
         [<ffffffff81210203>] ? print_rt_rq+0x53/0x2d0
         [<ffffffff8121657d>] ? trace_hardirqs_off+0xd/0x10
         [<ffffffff8226acfb>] ? _raw_spin_unlock_irqrestore+0x5b/0x60
         [<ffffffff81250000>] ? irq_domain_set_hwirq_and_chip+0x30/0xb0
         [<ffffffff81256339>] ? debug_lockdep_rcu_enabled+0x39/0x40
         [<ffffffff812178c0>] ? __lock_is_held+0x90/0x130
         [<ffffffff81196877>] process_one_work+0x567/0xec0
        [...]
      
      Afterwards, xhci reports some functional errors:
      
        xhci_hcd 0000:00:14.0: ERROR: unexpected setup address command completion
                                      code 0x11.
        xhci_hcd 0000:00:14.0: ERROR: unexpected setup address command completion
                                      code 0x11.
        usb 4-3: device not accepting address 2, error -22
      
      Fix this by not overwriting the port1 argument in usb_alloc_dev(), but
      storing the raw port number as required by OF in an additional variable,
      raw_port.
      
      Fixes: 69bec725 ("USB: core: let USB device know device node")
      Signed-off-by: NNicolai Stange <nicstange@gmail.com>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7222c832
  14. 06 3月, 2016 2 次提交
    • P
      USB: core: let USB device know device node · 69bec725
      Peter Chen 提交于
      Although most of USB devices are hot-plug's, there are still some devices
      are hard wired on the board, eg, for HSIC and SSIC interface USB devices.
      If these kinds of USB devices are multiple functions, and they can supply
      other interfaces like i2c, gpios for other devices, we may need to
      describe these at device tree.
      
      In this commit, it uses "reg" in dts as physical port number to match
      the phyiscal port number decided by USB core, if they are the same,
      then the device node is for the device we are creating for USB core.
      Signed-off-by: NPeter Chen <peter.chen@freescale.com>
      Acked-by: NPhilipp Zabel <p.zabel@pengutronix.de>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Acked-by: NRob Herring <robh@kernel.org>
      Acked-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69bec725
    • R
      usb: devio: Add ioctl to disallow detaching kernel USB drivers. · d883f52e
      Reilly Grant 提交于
      The new USBDEVFS_DROP_PRIVILEGES ioctl allows a process to voluntarily
      relinquish the ability to issue other ioctls that may interfere with
      other processes and drivers that have claimed an interface on the
      device.
      
      This commit also includes a simple utility to be able to test the
      ioctl, located at Documentation/usb/usbdevfs-drop-permissions.c
      
      Example (with qemu-kvm's input device):
      
          $ lsusb
          ...
          Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
      
          $ usb-devices
          ...
          C:  #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
          I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=02 Driver=usbhid
      
          $ sudo ./usbdevfs-drop-permissions /dev/bus/usb/001/002
          OK: privileges dropped!
          Available options:
          [0] Exit now
          [1] Reset device. Should fail if device is in use
          [2] Claim 4 interfaces. Should succeed where not in use
          [3] Narrow interface permission mask
          Which option shall I run?: 1
          ERROR: USBDEVFS_RESET failed! (1 - Operation not permitted)
          Which test shall I run next?: 2
          ERROR claiming if 0 (1 - Operation not permitted)
          ERROR claiming if 1 (1 - Operation not permitted)
          ERROR claiming if 2 (1 - Operation not permitted)
          ERROR claiming if 3 (1 - Operation not permitted)
          Which test shall I run next?: 0
      
      After unbinding usbhid:
      
          $ usb-devices
          ...
          I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=02 Driver=(none)
      
          $ sudo ./usbdevfs-drop-permissions /dev/bus/usb/001/002
          ...
          Which option shall I run?: 2
          OK: claimed if 0
          ERROR claiming if 1 (1 - Operation not permitted)
          ERROR claiming if 2 (1 - Operation not permitted)
          ERROR claiming if 3 (1 - Operation not permitted)
          Which test shall I run next?: 1
          OK: USBDEVFS_RESET succeeded
          Which test shall I run next?: 0
      
      After unbinding usbhid and restricting the mask:
      
          $ sudo ./usbdevfs-drop-permissions /dev/bus/usb/001/002
          ...
          Which option shall I run?: 3
          Insert new mask: 0
          OK: privileges dropped!
          Which test shall I run next?: 2
          ERROR claiming if 0 (1 - Operation not permitted)
          ERROR claiming if 1 (1 - Operation not permitted)
          ERROR claiming if 2 (1 - Operation not permitted)
          ERROR claiming if 3 (1 - Operation not permitted)
      Signed-off-by: NReilly Grant <reillyg@chromium.org>
      Acked-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NEmilio López <emilio.lopez@collabora.co.uk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d883f52e
  15. 04 3月, 2016 1 次提交
  16. 21 2月, 2016 2 次提交
  17. 15 2月, 2016 4 次提交
  18. 10 2月, 2016 1 次提交
  19. 07 2月, 2016 1 次提交