1. 15 Mar, 2022 4 commits
    • Alan Stern's avatar
      usb: gadget: Fix use-after-free bug by not setting udc->dev.driver · 16b1941e
      Alan Stern authored
      The syzbot fuzzer found a use-after-free bug:
      
      BUG: KASAN: use-after-free in dev_uevent+0x712/0x780 drivers/base/core.c:2320
      Read of size 8 at addr ffff88802b934098 by task udevd/3689
      
      CPU: 2 PID: 3689 Comm: udevd Not tainted 5.17.0-rc4-syzkaller-00229-g4f12b742 #0
      Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
      Call Trace:
       <TASK>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
       print_address_description.constprop.0.cold+0x8d/0x303 mm/kasan/report.c:255
       __kasan_report mm/kasan/report.c:442 [inline]
       kasan_report.cold+0x83/0xdf mm/kasan/report.c:459
       dev_uevent+0x712/0x780 drivers/base/core.c:2320
       uevent_show+0x1b8/0x380 drivers/base/core.c:2391
       dev_attr_show+0x4b/0x90 drivers/base/core.c:2094
      
      Although the bug manifested in the driver core, the real cause was a
      race with the gadget core.  dev_uevent() does:
      
      	if (dev->driver)
      		add_uevent_var(env, "DRIVER=%s", dev->driver->name);
      
      and between the test and the dereference of dev->driver, the gadget
      core sets dev->driver to NULL.
      
      The race wouldn't occur if the gadget core registered its devices on
      a real bus, using the standard synchronization techniques of the
      driver core.  However, it's not necessary to make such a large change
      in order to fix this bug; all we need to do is make sure that
      udc->dev.driver is always NULL.
      
      In fact, there is no reason for udc->dev.driver ever to be set to
      anything, let alone to the value it currently gets: the address of the
      gadget's driver.  After all, a gadget driver only knows how to manage
      a gadget, not how to manage a UDC.
      
      This patch simply removes the statements in the gadget core that touch
      udc->dev.driver.
      
      Fixes: 2ccea03a ("usb: gadget: introduce UDC Class")
      CC: <stable@vger.kernel.org>
      Reported-and-tested-by: syzbot+348b571beb5eeb70a582@syzkaller.appspotmail.com
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/YiQgukfFFbBnwJ/9@rowland.harvard.eduSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      16b1941e
    • Alan Stern's avatar
      usb: usbtmc: Fix bug in pipe direction for control transfers · e9b667a8
      Alan Stern authored
      The syzbot fuzzer reported a minor bug in the usbtmc driver:
      
      usb 5-1: BOGUS control dir, pipe 80001e80 doesn't match bRequestType 0
      WARNING: CPU: 0 PID: 3813 at drivers/usb/core/urb.c:412
      usb_submit_urb+0x13a5/0x1970 drivers/usb/core/urb.c:410
      Modules linked in:
      CPU: 0 PID: 3813 Comm: syz-executor122 Not tainted
      5.17.0-rc5-syzkaller-00306-g2293be58 #0
      ...
      Call Trace:
       <TASK>
       usb_start_wait_urb+0x113/0x530 drivers/usb/core/message.c:58
       usb_internal_control_msg drivers/usb/core/message.c:102 [inline]
       usb_control_msg+0x2a5/0x4b0 drivers/usb/core/message.c:153
       usbtmc_ioctl_request drivers/usb/class/usbtmc.c:1947 [inline]
      
      The problem is that usbtmc_ioctl_request() uses usb_rcvctrlpipe() for
      all of its transfers, whether they are in or out.  It's easy to fix.
      
      CC: <stable@vger.kernel.org>
      Reported-and-tested-by: syzbot+a48e3d1a875240cab5de@syzkaller.appspotmail.com
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/YiEsYTPEE6lOCOA5@rowland.harvard.eduSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e9b667a8
    • H. Nikolaus Schaller's avatar
      partially Revert "usb: musb: Set the DT node on the child device" · 23907106
      H. Nikolaus Schaller authored
      This reverts the omap2430 changes of
      
      commit cf081d00 ("usb: musb: Set the DT node on the child device")
      
      Since v5.17-rc1, musb is broken on the gta04 and openpandora devices
      (omap3530/dm3730). BeagleBone Black (am335x) seems to work.
      
      Symptoms of this bug are
      
      a) main symptom
      
      [   21.336517] using random host ethernet address
      [   21.341430] using host ethernet address: 32:70:05:18:ff:78
      [   21.341461] using self ethernet address: 46:10:3a:b3:af:d9
      [   21.358184] usb0: HOST MAC 32:70:05:18:ff:78
      [   21.376678] usb0: MAC 46:10:3a:b3:af:d9
      [   21.388305] using random self ethernet address
      [   21.393371] using random host ethernet address
      [   21.398162] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
      [   21.421081] g_ether gadget: g_ether ready
      [   21.492156] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   21.691345] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   21.803192] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   21.819427] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   22.124450] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   22.168518] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   22.179382] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.213592] musb-hdrc musb-hdrc.1.auto: pm runtime get failed in musb_gadget_queue
      [   23.221832] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.227905] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.239440] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.401000] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.407073] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.426361] musb-hdrc musb-hdrc.1.auto: Could not enable: -22
      [   23.734466] musb-hdrc musb-hdrc.1.auto: pm runtime get failed in musb_gadget_queue
      [   23.742462] musb-hdrc musb-hdrc.1.auto: pm runtime get failed in musb_gadget_queue
      [   23.750396] musb-hdrc musb-hdrc.1.auto: pm runtime get failed in musb_gadget_queue
      ... (repeats with high frequency)
      
      This stops if the USB cable is unplugged and restarts if it is plugged in again.
      
      b) also found in the log
      
      [    6.498107] ------------[ cut here ]------------
      [    6.502960] WARNING: CPU: 0 PID: 868 at arch/arm/mach-omap2/omap_hwmod.c:1885 _enable+0x50/0x234
      [    6.512207] omap_hwmod: usb_otg_hs: enabled state can only be entered from initialized, idle, or disabled state
      [    6.522766] Modules linked in: omap2430(+) bmp280_i2c bmp280 itg3200 at24 tsc2007 leds_tca6507 bma180 hmc5843_i2c hmc5843_core industrialio_triggered_buffer lis3lv02d_i2c kfifo_buf lis3lv02d phy_twl4030_usb snd_soc_omap_mcbsp snd_soc_ti_sdma musb_hdrc snd_soc_twl4030 gnss_sirf twl4030_vibra twl4030_madc twl4030_charger twl4030_pwrbutton gnss industrialio ehci_omap omapdrm drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops drm drm_panel_orientation_quirks cec
      [    6.566436] CPU: 0 PID: 868 Comm: udevd Not tainted 5.16.0-rc5-letux+ #8251
      [    6.573730] Hardware name: Generic OMAP36xx (Flattened Device Tree)
      [    6.580322] [<c010ed30>] (unwind_backtrace) from [<c010a1d0>] (show_stack+0x10/0x14)
      [    6.588470] [<c010a1d0>] (show_stack) from [<c0897c14>] (dump_stack_lvl+0x40/0x4c)
      [    6.596405] [<c0897c14>] (dump_stack_lvl) from [<c0130cc4>] (__warn+0xb4/0xdc)
      [    6.604003] [<c0130cc4>] (__warn) from [<c0130d5c>] (warn_slowpath_fmt+0x70/0x9c)
      [    6.611846] [<c0130d5c>] (warn_slowpath_fmt) from [<c011f4d4>] (_enable+0x50/0x234)
      [    6.619903] [<c011f4d4>] (_enable) from [<c012081c>] (omap_hwmod_enable+0x28/0x40)
      [    6.627838] [<c012081c>] (omap_hwmod_enable) from [<c0120ff4>] (omap_device_enable+0x4c/0x78)
      [    6.636779] [<c0120ff4>] (omap_device_enable) from [<c0121030>] (_od_runtime_resume+0x10/0x3c)
      [    6.645812] [<c0121030>] (_od_runtime_resume) from [<c05c688c>] (__rpm_callback+0x3c/0xf4)
      [    6.654510] [<c05c688c>] (__rpm_callback) from [<c05c6994>] (rpm_callback+0x50/0x54)
      [    6.662628] [<c05c6994>] (rpm_callback) from [<c05c66b0>] (rpm_resume+0x448/0x4e4)
      [    6.670593] [<c05c66b0>] (rpm_resume) from [<c05c6784>] (__pm_runtime_resume+0x38/0x50)
      [    6.678985] [<c05c6784>] (__pm_runtime_resume) from [<bf14ab20>] (musb_init_controller+0x350/0xa5c [musb_hdrc])
      [    6.689727] [<bf14ab20>] (musb_init_controller [musb_hdrc]) from [<c05bccb8>] (platform_probe+0x58/0xa8)
      [    6.699737] [<c05bccb8>] (platform_probe) from [<c05badf0>] (really_probe+0x170/0x2fc)
      [    6.708068] [<c05badf0>] (really_probe) from [<c05bb040>] (__driver_probe_device+0xc4/0xd8)
      [    6.716827] [<c05bb040>] (__driver_probe_device) from [<c05bb084>] (driver_probe_device+0x30/0xac)
      [    6.726226] [<c05bb084>] (driver_probe_device) from [<c05bb3d0>] (__device_attach_driver+0x94/0xb4)
      [    6.735717] [<c05bb3d0>] (__device_attach_driver) from [<c05b93f8>] (bus_for_each_drv+0xa0/0xb4)
      [    6.744934] [<c05b93f8>] (bus_for_each_drv) from [<c05bb248>] (__device_attach+0xc0/0x134)
      [    6.753631] [<c05bb248>] (__device_attach) from [<c05b9fcc>] (bus_probe_device+0x28/0x80)
      [    6.762207] [<c05b9fcc>] (bus_probe_device) from [<c05b7e40>] (device_add+0x5fc/0x788)
      [    6.770507] [<c05b7e40>] (device_add) from [<c05bd240>] (platform_device_add+0x70/0x1bc)
      [    6.779022] [<c05bd240>] (platform_device_add) from [<bf177830>] (omap2430_probe+0x260/0x2d4 [omap2430])
      [    6.789001] [<bf177830>] (omap2430_probe [omap2430]) from [<c05bccb8>] (platform_probe+0x58/0xa8)
      [    6.798309] [<c05bccb8>] (platform_probe) from [<c05badf0>] (really_probe+0x170/0x2fc)
      [    6.806610] [<c05badf0>] (really_probe) from [<c05bb040>] (__driver_probe_device+0xc4/0xd8)
      [    6.815399] [<c05bb040>] (__driver_probe_device) from [<c05bb084>] (driver_probe_device+0x30/0xac)
      [    6.824798] [<c05bb084>] (driver_probe_device) from [<c05bb4b4>] (__driver_attach+0xc4/0xd8)
      [    6.833648] [<c05bb4b4>] (__driver_attach) from [<c05b9308>] (bus_for_each_dev+0x64/0xa0)
      [    6.842224] [<c05b9308>] (bus_for_each_dev) from [<c05ba248>] (bus_add_driver+0x148/0x1a4)
      [    6.850891] [<c05ba248>] (bus_add_driver) from [<c05bbd1c>] (driver_register+0xb4/0xf8)
      [    6.859313] [<c05bbd1c>] (driver_register) from [<c0101f54>] (do_one_initcall+0x90/0x1c8)
      [    6.867889] [<c0101f54>] (do_one_initcall) from [<c0893968>] (do_init_module+0x4c/0x204)
      [    6.876373] [<c0893968>] (do_init_module) from [<c01b4c30>] (load_module+0x13f0/0x1928)
      [    6.884796] [<c01b4c30>] (load_module) from [<c01b53a0>] (sys_finit_module+0xa0/0xc0)
      [    6.893005] [<c01b53a0>] (sys_finit_module) from [<c0100080>] (ret_fast_syscall+0x0/0x54)
      [    6.901580] Exception stack(0xc2807fa8 to 0xc2807ff0)
      [    6.906890] 7fa0:                   b6e517d4 00052068 00000006 b6e509f8 00000000 b6e5131c
      [    6.915466] 7fc0: b6e517d4 00052068 cd718000 0000017b 00020000 00037f78 00050048 00063368
      [    6.924011] 7fe0: bed8fef0 bed8fee0 b6e4ac4b b6f55a42
      [    6.929321] ---[ end trace d715ff121b58763c ]---
      
      c) git bisect result on testing for "musb-hdrc" in the console log:
      
      cf081d00 is the first bad commit
      commit cf081d00
      Author: Rob Herring <robh@kernel.org>
      Date:   Wed Dec 15 17:07:57 2021 -0600
      
        usb: musb: Set the DT node on the child device
      
        The musb glue drivers just copy the glue resources to the musb child device.
        Instead, set the musb child device's DT node pointer to the parent device's
        node so that platform_get_irq_byname() can find the resources in the DT.
        This removes the need for statically populating the IRQ resources from the
        DT which has been deprecated for some time.
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
        Link: https://lore.kernel.org/r/20211215230756.2009115-3-robh@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      drivers/usb/musb/am35x.c    | 2 ++
      drivers/usb/musb/da8xx.c    | 2 ++
      drivers/usb/musb/jz4740.c   | 1 +
      drivers/usb/musb/mediatek.c | 2 ++
      drivers/usb/musb/omap2430.c | 1 +
      drivers/usb/musb/ux500.c    | 1 +
      6 files changed, 9 insertions(+)
      
      Reverting this patch makes musb work again as before.
      
      Fixes: cf081d00 ("usb: musb: Set the DT node on the child device")
      Cc: Rob Herring <robh@kernel.org>
      Signed-off-by: default avatarH. Nikolaus Schaller <hns@goldelico.com>
      Link: https://lore.kernel.org/r/f62f5fc11f9ecae7e57f3fd66939e051bd3b11fc.1646744166.git.hns@goldelico.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      23907106
    • Dan Carpenter's avatar
      usb: gadget: rndis: prevent integer overflow in rndis_set_response() · 65f3324f
      Dan Carpenter authored
      If "BufOffset" is very large the "BufOffset + 8" operation can have an
      integer overflow.
      
      Cc: stable@kernel.org
      Fixes: 38ea1eac ("usb: gadget: rndis: check size of RNDIS_MSG_SET command")
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Link: https://lore.kernel.org/r/20220301080424.GA17208@kiliSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      65f3324f
  2. 27 Feb, 2022 4 commits
  3. 26 Feb, 2022 22 commits
  4. 25 Feb, 2022 10 commits