1. 10 7月, 2020 1 次提交
  2. 18 6月, 2020 1 次提交
  3. 25 5月, 2020 1 次提交
    • P
      usb: gadget: Fix issue with config_ep_by_speed function · 5d363120
      Pawel Laszczak 提交于
      This patch adds new config_ep_by_speed_and_alt function which
      extends the config_ep_by_speed about alt parameter.
      This additional parameter allows to find proper usb_ss_ep_comp_descriptor.
      
      Problem has appeared during testing f_tcm (BOT/UAS) driver function.
      
      f_tcm function for SS use array of headers for both  BOT/UAS alternate
      setting:
      
      static struct usb_descriptor_header *uasp_ss_function_desc[] = {
              (struct usb_descriptor_header *) &bot_intf_desc,
              (struct usb_descriptor_header *) &uasp_ss_bi_desc,
              (struct usb_descriptor_header *) &bot_bi_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_ss_bo_desc,
              (struct usb_descriptor_header *) &bot_bo_ep_comp_desc,
      
              (struct usb_descriptor_header *) &uasp_intf_desc,
              (struct usb_descriptor_header *) &uasp_ss_bi_desc,
              (struct usb_descriptor_header *) &uasp_bi_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_bi_pipe_desc,
              (struct usb_descriptor_header *) &uasp_ss_bo_desc,
              (struct usb_descriptor_header *) &uasp_bo_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_bo_pipe_desc,
              (struct usb_descriptor_header *) &uasp_ss_status_desc,
              (struct usb_descriptor_header *) &uasp_status_in_ep_comp_desc,
              (struct usb_descriptor_header *) &uasp_status_pipe_desc,
              (struct usb_descriptor_header *) &uasp_ss_cmd_desc,
              (struct usb_descriptor_header *) &uasp_cmd_comp_desc,
              (struct usb_descriptor_header *) &uasp_cmd_pipe_desc,
              NULL,
      };
      
      The first 5 descriptors are associated with BOT alternate setting,
      and others are associated with UAS.
      
      During handling UAS alternate setting f_tcm driver invokes
      config_ep_by_speed and this function sets incorrect companion endpoint
      descriptor in usb_ep object.
      
      Instead setting ep->comp_desc to uasp_bi_ep_comp_desc function in this
      case set ep->comp_desc to uasp_ss_bi_desc.
      
      This is due to the fact that it searches endpoint based on endpoint
      address:
      
              for_each_ep_desc(speed_desc, d_spd) {
                      chosen_desc = (struct usb_endpoint_descriptor *)*d_spd;
                      if (chosen_desc->bEndpoitAddress == _ep->address)
                              goto ep_found;
              }
      
      And in result it uses the descriptor from BOT alternate setting
      instead UAS.
      
      Finally, it causes that controller driver during enabling endpoints
      detect that just enabled endpoint for bot.
      Signed-off-by: NJayshri Pawar <jpawar@cadence.com>
      Signed-off-by: NPawel Laszczak <pawell@cadence.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      5d363120
  4. 15 3月, 2020 1 次提交
  5. 11 2月, 2020 2 次提交
    • J
      usb: gadget: composite: Support more than 500mA MaxPower · a2035411
      Jack Pham 提交于
      USB 3.x SuperSpeed peripherals can draw up to 900mA of VBUS power
      when in configured state. However, if a configuration wanting to
      take advantage of this is added with MaxPower greater than 500
      (currently possible if using a ConfigFS gadget) the composite
      driver fails to accommodate this for a couple reasons:
      
       - usb_gadget_vbus_draw() when called from set_config() and
         composite_resume() will be passed the MaxPower value without
         regard for the current connection speed, resulting in a
         violation for USB 2.0 since the max is 500mA.
      
       - the bMaxPower of the configuration descriptor would be
         incorrectly encoded, again if the connection speed is only
         at USB 2.0 or below, likely wrapping around U8_MAX since
         the 2mA multiplier corresponds to a maximum of 510mA.
      
      Fix these by adding checks against the current gadget->speed
      when the c->MaxPower value is used (set_config() and
      composite_resume()) and appropriately limit based on whether
      it is currently at a low-/full-/high- or super-speed connection.
      
      Because 900 is not divisible by 8, with the round-up division
      currently used in encode_bMaxPower() a MaxPower of 900mA will
      result in an encoded value of 0x71. When a host stack (including
      Linux and Windows) enumerates this on a single port root hub, it
      reads this value back and decodes (multiplies by 8) to get 904mA
      which is strictly greater than 900mA that is typically budgeted
      for that port, causing it to reject the configuration. Instead,
      we should be using the round-down behavior of normal integral
      division so that 900 / 8 -> 0x70 or 896mA to stay within range.
      And we might as well change it for the high/full/low case as well
      for consistency.
      
      N.B. USB 3.2 Gen N x 2 allows for up to 1500mA but there doesn't
      seem to be any any peripheral controller supported by Linux that
      does two lane operation, so for now keeping the clamp at 900
      should be fine.
      Signed-off-by: NJack Pham <jackp@codeaurora.org>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      a2035411
    • J
      usb: gadget: composite: Fix bMaxPower for SuperSpeedPlus · c724417b
      Jack Pham 提交于
      SuperSpeedPlus peripherals must report their bMaxPower of the
      configuration descriptor in units of 8mA as per the USB 3.2
      specification. The current switch statement in encode_bMaxPower()
      only checks for USB_SPEED_SUPER but not USB_SPEED_SUPER_PLUS so
      the latter falls back to USB 2.0 encoding which uses 2mA units.
      Replace the switch with a simple if/else.
      
      Fixes: eae5820b ("usb: gadget: composite: Write SuperSpeedPlus config descriptors")
      Signed-off-by: NJack Pham <jackp@codeaurora.org>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      c724417b
  6. 27 10月, 2019 1 次提交
    • C
      usb: gadget: composite: Fix possible double free memory bug · 1c20c89b
      Chandana Kishori Chiluveru 提交于
      composite_dev_cleanup call from the failure of configfs_composite_bind
      frees up the cdev->os_desc_req and cdev->req. If the previous calls of
      bind and unbind is successful these will carry stale values.
      
      Consider the below sequence of function calls:
      configfs_composite_bind()
              composite_dev_prepare()
                      - Allocate cdev->req, cdev->req->buf
              composite_os_desc_req_prepare()
                      - Allocate cdev->os_desc_req, cdev->os_desc_req->buf
      configfs_composite_unbind()
              composite_dev_cleanup()
                      - free the cdev->os_desc_req->buf and cdev->req->buf
      Next composition switch
      configfs_composite_bind()
              - If it fails goto err_comp_cleanup will call the
      	  composite_dev_cleanup() function
              composite_dev_cleanup()
      	        - calls kfree up with the stale values of cdev->req->buf and
      		  cdev->os_desc_req from the previous configfs_composite_bind
      		  call. The free call on these stale values leads to double free.
      
      Hence, Fix this issue by setting request and buffer pointer to NULL after
      kfree.
      Signed-off-by: NChandana Kishori Chiluveru <cchiluve@codeaurora.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      1c20c89b
  7. 22 10月, 2019 1 次提交
  8. 28 8月, 2019 1 次提交
  9. 12 8月, 2019 1 次提交
  10. 18 6月, 2019 1 次提交
  11. 17 7月, 2018 1 次提交
  12. 19 6月, 2018 1 次提交
  13. 15 5月, 2018 1 次提交
  14. 23 3月, 2018 1 次提交
  15. 08 3月, 2018 2 次提交
    • C
      usb: gadget: composite: remove duplicated code in OS desc handling · 636ba13a
      Chris Dickens 提交于
      When the host wants to fetch OS descriptors, it sends two requests. The
      first is only for the header and the second for the full amount
      specified by the header in the first request. The OS descriptor handling
      code is distinguishing the header-only requests based on the wLength of
      the setup packet, but the same code is executed in both cases to
      construct the actual header. Simplify this by always constructing the
      header and then filling out the rest of the request if the wLength is
      greater than the size of the header.
      
      Also remove the duplicate code for queueing the request to ep0 by adding
      a goto label.
      Signed-off-by: NChris Dickens <christopher.a.dickens@gmail.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      636ba13a
    • C
      usb: gadget: composite: fix incorrect handling of OS desc requests · 5d6ae4f0
      Chris Dickens 提交于
      When handling an OS descriptor request, one of the first operations is
      to zero out the request buffer using the wLength from the setup packet.
      There is no bounds checking, so a wLength > 4096 would clobber memory
      adjacent to the request buffer. Fix this by taking the min of wLength
      and the request buffer length prior to the memset. While at it, define
      the buffer length in a header file so that magic numbers don't appear
      throughout the code.
      
      When returning data to the host, the data length should be the min of
      the wLength and the valid data we have to return. Currently we are
      returning wLength, thus requests for a wLength greater than the amount
      of data in the OS descriptor buffer would return invalid (albeit zero'd)
      data following the valid descriptor data. Fix this by counting the
      number of bytes when constructing the data and using this when
      determining the length of the request.
      Signed-off-by: NChris Dickens <christopher.a.dickens@gmail.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      5d6ae4f0
  16. 28 11月, 2017 1 次提交
  17. 07 11月, 2017 1 次提交
  18. 04 11月, 2017 1 次提交
  19. 01 11月, 2017 1 次提交
  20. 11 10月, 2017 1 次提交
    • A
      usb: gadget: composite: Fix use-after-free in usb_composite_overwrite_options · aec17e1e
      Andrew Gabbasov 提交于
      KASAN enabled configuration reports an error
      
          BUG: KASAN: use-after-free in usb_composite_overwrite_options+...
                      [libcomposite] at addr ...
          Read of size 1 by task ...
      
      when some driver is un-bound and then bound again.
      For example, this happens with FunctionFS driver when "ffs-test"
      test application is run several times in a row.
      
      If the driver has empty manufacturer ID string in initial static data,
      it is then replaced with generated string. After driver unbinding
      the generated string is freed, but the driver data still keep that
      pointer. And if the driver is then bound again, that pointer
      is re-used for string emptiness check.
      
      The fix is to clean up the driver string data upon its unbinding
      to drop the pointer to freed memory.
      
      Fixes: cc2683c3 ("usb: gadget: Provide a default implementation of default manufacturer string")
      Cc: stable@vger.kernel.org
      Signed-off-by: NAndrew Gabbasov <andrew_gabbasov@mentor.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      aec17e1e
  21. 06 6月, 2017 1 次提交
  22. 02 6月, 2017 2 次提交
  23. 12 1月, 2017 1 次提交
  24. 02 1月, 2017 1 次提交
    • K
      usb: gadget: composite: Test get_alt() presence instead of set_alt() · 7e4da3fc
      Krzysztof Opasiak 提交于
      By convention (according to doc) if function does not provide
      get_alt() callback composite framework should assume that it has only
      altsetting 0 and should respond with error if host tries to set
      other one.
      
      After commit dd4dff8b ("USB: composite: Fix bug: should test
      set_alt function pointer before use it")
      we started checking set_alt() callback instead of get_alt().
      This check is useless as we check if set_alt() is set inside
      usb_add_function() and fail if it's NULL.
      
      Let's fix this check and move comment about why we check the get
      method instead of set a little bit closer to prevent future false
      fixes.
      
      Fixes: dd4dff8b ("USB: composite: Fix bug: should test set_alt function pointer before use it")
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NKrzysztof Opasiak <k.opasiak@samsung.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      7e4da3fc
  25. 03 11月, 2016 2 次提交
  26. 31 10月, 2016 2 次提交
    • F
      usb: gadget: composite: always set ep->mult to a sensible value · eaa496ff
      Felipe Balbi 提交于
      ep->mult is supposed to be set to Isochronous and
      Interrupt Endapoint's multiplier value. This value
      is computed from different places depending on the
      link speed.
      
      If we're dealing with HighSpeed, then it's part of
      bits [12:11] of wMaxPacketSize. This case wasn't
      taken into consideration before.
      
      While at that, also make sure the ep->mult defaults
      to one so drivers can use it unconditionally and
      assume they'll never multiply ep->maxpacket to zero.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      eaa496ff
    • F
      usb: gadget: composite: correctly initialize ep->maxpacket · e8f29bb7
      Felipe Balbi 提交于
      usb_endpoint_maxp() returns wMaxPacketSize in its
      raw form. Without taking into consideration that it
      also contains other bits reserved for isochronous
      endpoints.
      
      This patch fixes one occasion where this is a
      problem by making sure that we initialize
      ep->maxpacket only with lower 10 bits of the value
      returned by usb_endpoint_maxp(). Note that seperate
      patches will be necessary to audit all call sites of
      usb_endpoint_maxp() and make sure that
      usb_endpoint_maxp() only returns lower 10 bits of
      wMaxPacketSize.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      e8f29bb7
  27. 25 8月, 2016 1 次提交
    • F
      usb: gadget: composite: let USB functions process ctrl reqs in cfg0 · 1a00b457
      Felix Hädicke 提交于
      It can sometimes be necessary for gadget drivers to process non-standard
      control requests, which host devices can send without having sent
      USB_REQ_SET_CONFIGURATION.
      
      Therefore, the req_match() usb_function method is enhanced with the new
      parameter "config0". When a USB configuration is active, this parameter
      is false. When a non-core control request is processed in
      composite_setup(), without an active configuration, req_match() of the
      USB functions of all available configurations which implement this
      function, is called with config0=true. Then the control request gets
      processed by the first usb_function instance whose req_match() returns
      true.
      Signed-off-by: NFelix Hädicke <felixhaedicke@web.de>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      1a00b457
  28. 11 8月, 2016 2 次提交
  29. 31 5月, 2016 1 次提交
    • W
      usb: gadget: composite: don't queue OS desc req if length is invalid · 7e14f47a
      William Wu 提交于
      In OS descriptors handling, if ctrl->bRequestType is
      USB_RECIP_DEVICE and w_index != 0x4 or (w_value >> 8)
      is true, it will not assign a valid value to req->length,
      but use the default value(-EOPNOTSUPP), and queue an
      OS desc request with the invalid req->length. It always
      happens on the platforms which use os_desc (for example:
      rk3366, rk3399), and cause kernel panic as follows
      (use dwc3 driver):
      
      Unable to handle kernel paging request at virtual address ffffffc0f7e00000
      Internal error: Oops: 96000146 [#1] PREEMPT SMP
      PC is at __dma_clean_range+0x18/0x30
      LR is at __swiotlb_map_page+0x50/0x64
      Call trace:
      [<ffffffc0000930f8>] __dma_clean_range+0x18/0x30
      [<ffffffc00062214c>] usb_gadget_map_request+0x134/0x1b0
      [<ffffffc0005c289c>] __dwc3_ep0_do_control_data+0x110/0x14c
      [<ffffffc0005c2d38>] __dwc3_gadget_ep0_queue+0x198/0x1b8
      [<ffffffc0005c2e18>] dwc3_gadget_ep0_queue+0xc0/0xe8
      [<ffffffc00061cfec>] composite_ep0_queue.constprop.14+0x34/0x98
      [<ffffffc00061dfb0>] composite_setup+0xf60/0x100c
      [<ffffffc0006204dc>] android_setup+0xd8/0x138
      [<ffffffc0005c29a4>] dwc3_ep0_delegate_req+0x34/0x50
      [<ffffffc0005c3534>] dwc3_ep0_interrupt+0x5dc/0xb58
      [<ffffffc0005c0c3c>] dwc3_thread_interrupt+0x15c/0xa24
      
      With this patch, the gadget driver will not queue
      a request and return immediately if req->length is
      invalid. And the usb controller driver can handle
      the unsupport request correctly.
      Signed-off-by: NWilliam Wu <william.wu@rock-chips.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      7e14f47a
  30. 28 4月, 2016 1 次提交
  31. 18 4月, 2016 1 次提交
  32. 29 3月, 2016 1 次提交
  33. 04 3月, 2016 2 次提交