13 Jan, 2021

40 commits

  • commit c2407cf7d22d0c0d94cf20342b3b8f06f1d904e7 upstream.

    Ever since commit 2a9127fcf229 ("mm: rewrite wait_on_page_bit_common()
    logic") we've had some very occasional reports of BUG_ON(PageWriteback)
    in write_cache_pages(), which we thought we already fixed in commit
    073861ed77b6 ("mm: fix VM_BUG_ON(PageTail) and BUG_ON(PageWriteback)").

    But syzbot just reported another one, even with that commit in place.

    And it turns out that there's a simpler way to trigger the BUG_ON() than
    the one Hugh found with page re-use. It all boils down to the fact that
    the page writeback is ostensibly serialized by the page lock, but that
    isn't actually really true.

    Yes, the people _setting_ writeback all do so under the page lock, but
    the actual clearing of the bit - and waking up any waiters - happens
    without any page lock.

    This gives us this fairly simple race condition:

    CPU1 = end previous writeback
    CPU2 = start new writeback under page lock
    CPU3 = write_cache_pages()

    CPU1 CPU2 CPU3
    ---- ---- ----

    end_page_writeback()
    test_clear_page_writeback(page)
    ... delayed...

    lock_page();
    set_page_writeback()
    unlock_page()

    lock_page()
    wait_on_page_writeback();

    wake_up_page(page, PG_writeback);
    .. wakes up CPU3 ..

    BUG_ON(PageWriteback(page));

    where the BUG_ON() happens because we woke up the PG_writeback bit
    becasue of the _previous_ writeback, but a new one had already been
    started because the clearing of the bit wasn't actually atomic wrt the
    actual wakeup or serialized by the page lock.

    The reason this didn't use to happen was that the old logic in waiting
    on a page bit would just loop if it ever saw the bit set again.

    The nice proper fix would probably be to get rid of the whole "wait for
    writeback to clear, and then set it" logic in the writeback path, and
    replace it with an atomic "wait-to-set" (ie the same as we have for page
    locking: we set the page lock bit with a single "lock_page()", not with
    "wait for lock bit to clear and then set it").

    However, out current model for writeback is that the waiting for the
    writeback bit is done by the generic VFS code (ie write_cache_pages()),
    but the actual setting of the writeback bit is done much later by the
    filesystem ".writepages()" function.

    IOW, to make the writeback bit have that same kind of "wait-to-set"
    behavior as we have for page locking, we'd have to change our roughly
    ~50 different writeback functions. Painful.

    Instead, just make "wait_on_page_writeback()" loop on the very unlikely
    situation that the PG_writeback bit is still set, basically re-instating
    the old behavior. This is very non-optimal in case of contention, but
    since we only ever set the bit under the page lock, that situation is
    controlled.

    Reported-by: syzbot+2fc0712f8f8b8b8fa0ef@syzkaller.appspotmail.com
    Fixes: 2a9127fcf229 ("mm: rewrite wait_on_page_bit_common() logic")
    Acked-by: Hugh Dickins
    Cc: Andrew Morton
    Cc: Matthew Wilcox
    Cc: stable@kernel.org
    Signed-off-by: Linus Torvalds
    Signed-off-by: Greg Kroah-Hartman

    Linus Torvalds
     
  • commit 84e261553e6f919bf0b4d65244599ab2b41f1da5 upstream.

    hwmon, specifically hwmon_num_channel_attrs, expects the config
    array in the hwmon_channel_info structure to be terminated by
    a zero entry. amd_energy does not honor this convention. As
    result, a KASAN warning is possible. Fix this by adding an
    additional entry and setting it to zero.

    Fixes: 8abee9566b7e ("hwmon: Add amd_energy driver to report energy counters")

    Signed-off-by: David Arcari
    Cc: Naveen Krishna Chatradhi
    Cc: Jean Delvare
    Cc: Guenter Roeck
    Cc: linux-kernel@vger.kernel.org
    Cc: stable@vger.kernel.org
    Signed-off-by: David Arcari
    Acked-by: Naveen Krishna Chatradhi
    Link: https://lore.kernel.org/r/20210107144707.6927-1-darcari@redhat.com
    Signed-off-by: Guenter Roeck
    Signed-off-by: Greg Kroah-Hartman

    David Arcari
     
  • Remove an unused variable which was mistakingly left by commit
    37faf5061541 ("USB: serial: keyspan_pda: fix write-wakeup
    use-after-free") and only removed by a later change.

    This is needed to suppress a W=1 warning about the unused variable in
    the stable trees that the build bots triggers.

    Reported-by: kernel test robot
    Signed-off-by: Johan Hovold
    Signed-off-by: Greg Kroah-Hartman

    Johan Hovold
     
  • commit 64e6bbfff52db4bf6785fab9cffab850b2de6870 upstream.

    There is a use-after-free issue, if access udc_name
    in function gadget_dev_desc_UDC_store after another context
    free udc_name in function unregister_gadget.

    Context 1:
    gadget_dev_desc_UDC_store()->unregister_gadget()->
    free udc_name->set udc_name to NULL

    Context 2:
    gadget_dev_desc_UDC_show()-> access udc_name

    Call trace:
    dump_backtrace+0x0/0x340
    show_stack+0x14/0x1c
    dump_stack+0xe4/0x134
    print_address_description+0x78/0x478
    __kasan_report+0x270/0x2ec
    kasan_report+0x10/0x18
    __asan_report_load1_noabort+0x18/0x20
    string+0xf4/0x138
    vsnprintf+0x428/0x14d0
    sprintf+0xe4/0x12c
    gadget_dev_desc_UDC_show+0x54/0x64
    configfs_read_file+0x210/0x3a0
    __vfs_read+0xf0/0x49c
    vfs_read+0x130/0x2b4
    SyS_read+0x114/0x208
    el0_svc_naked+0x34/0x38

    Add mutex_lock to protect this kind of scenario.

    Signed-off-by: Eddie Hung
    Signed-off-by: Macpaul Lin
    Reviewed-by: Peter Chen
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/1609239215-21819-1-git-send-email-macpaul.lin@mediatek.com
    Signed-off-by: Greg Kroah-Hartman

    Eddie Hung
     
  • commit 6cd0fe91387917be48e91385a572a69dfac2f3f7 upstream.

    When binding the ConfigFS gadget to a UDC, the functions in each
    configuration are added in list order. However, if usb_add_function()
    fails, the failed function is put back on its configuration's
    func_list and purge_configs_funcs() is called to further clean up.

    purge_configs_funcs() iterates over the configurations and functions
    in forward order, calling unbind() on each of the previously added
    functions. But after doing so, each function gets moved to the
    tail of the configuration's func_list. This results in reshuffling
    the original order of the functions within a configuration such
    that the failed function now appears first even though it may have
    originally appeared in the middle or even end of the list. At this
    point if the ConfigFS gadget is attempted to re-bind to the UDC,
    the functions will be added in a different order than intended,
    with the only recourse being to remove and relink the functions all
    over again.

    An example of this as follows:

    ln -s functions/mass_storage.0 configs/c.1
    ln -s functions/ncm.0 configs/c.1
    ln -s functions/ffs.adb configs/c.1 # oops, forgot to start adbd
    echo "" > UDC # fails
    start adbd
    echo "" > UDC # now succeeds, but...
    # bind order is
    # "ADB", mass_storage, ncm

    [30133.118289] configfs-gadget gadget: adding 'Mass Storage Function'/ffffff810af87200 to config 'c'/ffffff817d6a2520
    [30133.119875] configfs-gadget gadget: adding 'cdc_network'/ffffff80f48d1a00 to config 'c'/ffffff817d6a2520
    [30133.119974] using random self ethernet address
    [30133.120002] using random host ethernet address
    [30133.139604] usb0: HOST MAC 3e:27:46:ba:3e:26
    [30133.140015] usb0: MAC 6e:28:7e:42:66:6a
    [30133.140062] configfs-gadget gadget: adding 'Function FS Gadget'/ffffff80f3868438 to config 'c'/ffffff817d6a2520
    [30133.140081] configfs-gadget gadget: adding 'Function FS Gadget'/ffffff80f3868438 --> -19
    [30133.140098] configfs-gadget gadget: unbind function 'Mass Storage Function'/ffffff810af87200
    [30133.140119] configfs-gadget gadget: unbind function 'cdc_network'/ffffff80f48d1a00
    [30133.173201] configfs-gadget a600000.dwc3: failed to start g1: -19
    [30136.661933] init: starting service 'adbd'...
    [30136.700126] read descriptors
    [30136.700413] read strings
    [30138.574484] configfs-gadget gadget: adding 'Function FS Gadget'/ffffff80f3868438 to config 'c'/ffffff817d6a2520
    [30138.575497] configfs-gadget gadget: adding 'Mass Storage Function'/ffffff810af87200 to config 'c'/ffffff817d6a2520
    [30138.575554] configfs-gadget gadget: adding 'cdc_network'/ffffff80f48d1a00 to config 'c'/ffffff817d6a2520
    [30138.575631] using random self ethernet address
    [30138.575660] using random host ethernet address
    [30138.595338] usb0: HOST MAC 2e:cf:43:cd:ca:c8
    [30138.597160] usb0: MAC 6a:f0:9f:ee:82:a0
    [30138.791490] configfs-gadget gadget: super-speed config #1: c

    Fix this by reversing the iteration order of the functions in
    purge_config_funcs() when unbinding them, and adding them back to
    the config's func_list at the head instead of the tail. This
    ensures that we unbind and unwind back to the original list order.

    Fixes: 88af8bbe4ef7 ("usb: gadget: the start of the configfs interface")
    Signed-off-by: Chandana Kishori Chiluveru
    Signed-off-by: Jack Pham
    Reviewed-by: Peter Chen
    Link: https://lore.kernel.org/r/20201229224443.31623-1-jackp@codeaurora.org
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Chandana Kishori Chiluveru
     
  • commit 5cc35c224a80aa5a5a539510ef049faf0d6ed181 upstream.

    There is a spinlock lockup as part of composite_disconnect
    when it tries to acquire cdev->lock as part of usb_gadget_deactivate.
    This is because the usb_gadget_deactivate is called from
    usb_function_deactivate with the same spinlock held.

    This would result in the below call stack and leads to stall.

    rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
    rcu: 3-...0: (1 GPs behind) idle=162/1/0x4000000000000000
    softirq=10819/10819 fqs=2356
    (detected by 2, t=5252 jiffies, g=20129, q=3770)
    Task dump for CPU 3:
    task:uvc-gadget_wlhe state:R running task stack: 0 pid: 674 ppid:
    636 flags:0x00000202
    Call trace:
    __switch_to+0xc0/0x170
    _raw_spin_lock_irqsave+0x84/0xb0
    composite_disconnect+0x28/0x78
    configfs_composite_disconnect+0x68/0x70
    usb_gadget_disconnect+0x10c/0x128
    usb_gadget_deactivate+0xd4/0x108
    usb_function_deactivate+0x6c/0x80
    uvc_function_disconnect+0x20/0x58
    uvc_v4l2_release+0x30/0x88
    v4l2_release+0xbc/0xf0
    __fput+0x7c/0x230
    ____fput+0x14/0x20
    task_work_run+0x88/0x140
    do_notify_resume+0x240/0x6f0
    work_pending+0x8/0x200

    Fix this by doing an unlock on cdev->lock before the usb_gadget_deactivate
    call from usb_function_deactivate.

    The same lockup can happen in the usb_gadget_activate path. Fix that path
    as well.

    Reported-by: Peter Chen
    Link: https://lore.kernel.org/linux-usb/20201102094936.GA29581@b29397-desktop/
    Tested-by: Peter Chen
    Signed-off-by: Sriharsha Allenki
    Cc: stable
    Link: https://lore.kernel.org/r/20201202130220.24926-1-sallenki@codeaurora.org
    Signed-off-by: Greg Kroah-Hartman

    Sriharsha Allenki
     
  • commit c91d3a6bcaa031f551ba29a496a8027b31289464 upstream.

    If usb_otg_descriptor_alloc() failed, it need return ENOMEM.

    Fixes: 578aa8a2b12c ("usb: gadget: acm_ms: allocate and init otg descriptor by otg capabilities")
    Reported-by: Hulk Robot
    Signed-off-by: Yang Yingliang
    Cc: stable
    Link: https://lore.kernel.org/r/20201117092955.4102785-1-yangyingliang@huawei.com
    Signed-off-by: Greg Kroah-Hartman

    Yang Yingliang
     
  • commit 0a88fa221ce911c331bf700d2214c5b2f77414d3 upstream.

    Fix the MTU size issue with RX packet size as the host sends the packet
    with extra bytes containing ethernet header. This causes failure when
    user sets the MTU size to the maximum i.e. 15412. In this case the
    ethernet packet received will be of length 15412 plus the ethernet header
    length. This patch fixes the issue where there is a check that RX packet
    length must not be more than max packet length.

    Fixes: bba787a860fa ("usb: gadget: ether: Allow jumbo frames")
    Signed-off-by: Manish Narani
    Cc: stable
    Link: https://lore.kernel.org/r/1605597215-122027-1-git-send-email-manish.narani@xilinx.com
    Signed-off-by: Greg Kroah-Hartman

    Manish Narani
     
  • commit 2cc332e4ee4febcbb685e2962ad323fe4b3b750a upstream.

    When printer driver is loaded, the printer_func_bind function is called, in
    this function, the interface descriptor be allocated memory, if after that,
    the error occurred, the interface descriptor memory need to be free.

    Reviewed-by: Peter Chen
    Cc:
    Signed-off-by: Zqiang
    Link: https://lore.kernel.org/r/20201210020148.6691-1-qiang.zhang@windriver.com
    Signed-off-by: Greg Kroah-Hartman

    Zqiang
     
  • commit 9389044f27081d6ec77730c36d5bf9a1288bcda2 upstream.

    With commit 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth")
    wMaxPacketSize is computed dynamically but the value is never reset.

    Because of this, the actual maximum packet size can only decrease each time
    the audio gadget is instantiated.

    Reset the endpoint maximum packet size and mark wMaxPacketSize as dynamic
    to solve the problem.

    Fixes: 913e4a90b6f9 ("usb: gadget: f_uac2: finalize wMaxPacketSize according to bandwidth")
    Signed-off-by: Jerome Brunet
    Cc: stable
    Link: https://lore.kernel.org/r/20201221173531.215169-2-jbrunet@baylibre.com
    Signed-off-by: Greg Kroah-Hartman

    Jerome Brunet
     
  • commit c318840fb2a42ce25febc95c4c19357acf1ae5ca upstream.

    The dummy-hcd driver was written under the assumption that all the
    parameters in URBs sent to its root hub would be valid. With URBs
    sent from userspace via usbfs, that assumption can be violated.

    In particular, the driver doesn't fully check the port-feature values
    stored in the wValue entry of Clear-Port-Feature and Set-Port-Feature
    requests. Values that are too large can cause the driver to perform
    an invalid left shift of more than 32 bits. Ironically, two of those
    left shifts are unnecessary, because they implement Set-Port-Feature
    requests that hubs are not required to support, according to section
    11.24.2.13 of the USB-2.0 spec.

    This patch adds the appropriate checks for the port feature selector
    values and removes the unnecessary feature settings. It also rejects
    requests to set the TEST feature or to set or clear the INDICATOR and
    C_OVERCURRENT features, as none of these are relevant to dummy-hcd's
    root-hub emulation.

    CC:
    Reported-and-tested-by: syzbot+5925509f78293baa7331@syzkaller.appspotmail.com
    Signed-off-by: Alan Stern
    Link: https://lore.kernel.org/r/20201230162044.GA727759@rowland.harvard.edu
    Signed-off-by: Greg Kroah-Hartman

    Alan Stern
     
  • commit d7889c2020e08caab0d7e36e947f642d91015bd0 upstream.

    Without crc32 support, this driver fails to link:

    arm-linux-gnueabi-ld: drivers/usb/gadget/function/f_eem.o: in function `eem_unwrap':
    f_eem.c:(.text+0x11cc): undefined reference to `crc32_le'
    arm-linux-gnueabi-ld: drivers/usb/gadget/function/f_ncm.o:f_ncm.c:(.text+0x1e40):
    more undefined references to `crc32_le' follow

    Fixes: 6d3865f9d41f ("usb: gadget: NCM: Add transmit multi-frame.")
    Signed-off-by: Arnd Bergmann
    Cc: stable
    Link: https://lore.kernel.org/r/20210103214224.1996535-1-arnd@kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Arnd Bergmann
     
  • commit c06ccf3ebb7503706ea49fd248e709287ef385a3 upstream.

    The calculation of in_cables and out_cables bitmaps are done with the
    bit shift by the value from the descriptor, which is an arbitrary
    value, and can lead to UBSAN shift-out-of-bounds warnings.

    Fix it by filtering the bad descriptor values with the check of the
    upper bound 0x10 (the cable bitmaps are 16 bits).

    Reported-by: syzbot+92e45ae45543f89e8c88@syzkaller.appspotmail.com
    Cc:
    Link: https://lore.kernel.org/r/20201223174557.10249-1-tiwai@suse.de
    Signed-off-by: Takashi Iwai
    Signed-off-by: Greg Kroah-Hartman

    Takashi Iwai
     
  • commit 020a1f453449294926ca548d8d5ca970926e8dfd upstream.

    Stack-allocated buffers cannot be used for DMA (on all architectures).

    Replace the HP-channel macro with a helper function that allocates a
    dedicated transfer buffer so that it can continue to be used with
    arguments from the stack.

    Note that the buffer is cleared on allocation as usblp_ctrl_msg()
    returns success also on short transfers (the buffer is only used for
    debugging).

    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold
    Link: https://lore.kernel.org/r/20210104145302.2087-1-johan@kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Johan Hovold
     
  • commit 372c93131998c0622304bed118322d2a04489e63 upstream.

    Make sure to always cancel the control URB in write() so that it can be
    reused after a timeout or spurious CMD_ACK.

    Currently any further write requests after a timeout would fail after
    triggering a WARN() in usb_submit_urb() when attempting to submit the
    already active URB.

    Reported-by: syzbot+e87ebe0f7913f71f2ea5@syzkaller.appspotmail.com
    Fixes: 6bc235a2e24a ("USB: add driver for Meywa-Denki & Kayac YUREX")
    Cc: stable # 2.6.37
    Signed-off-by: Johan Hovold
    Signed-off-by: Greg Kroah-Hartman

    Johan Hovold
     
  • commit d6c1ddd938d84a1adef7e19e8efc10e1b4df5034 upstream.

    New modem using ff/ff/30 for QCDM, ff/00/00 for AT and NMEA,
    and ff/ff/ff for RMNET/QMI.

    T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=5000 MxCh= 0
    D: Ver= 3.20 Cls=ef(misc ) Sub=02 Prot=01 MxPS= 9 #Cfgs= 1
    P: Vendor=2c7c ProdID=0620 Rev= 4.09
    S: Manufacturer=Quectel
    S: Product=EM160R-GL
    S: SerialNumber=e31cedc1
    C:* #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=896mA
    I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=30 Driver=(none)
    E: Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    E: Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    I:* If#= 1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
    E: Ad=83(I) Atr=03(Int.) MxPS= 10 Ivl=32ms
    E: Ad=82(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    E: Ad=02(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    I:* If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
    E: Ad=85(I) Atr=03(Int.) MxPS= 10 Ivl=32ms
    E: Ad=84(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    E: Ad=03(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    I:* If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=(none)
    E: Ad=87(I) Atr=03(Int.) MxPS= 10 Ivl=32ms
    E: Ad=86(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    E: Ad=04(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    I:* If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
    E: Ad=88(I) Atr=03(Int.) MxPS= 8 Ivl=32ms
    E: Ad=8e(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
    E: Ad=0f(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms

    Cc: stable@vger.kernel.org
    Signed-off-by: Bjørn Mork
    [ johan: add model comment ]
    Signed-off-by: Johan Hovold
    Signed-off-by: Greg Kroah-Hartman

    Bjørn Mork
     
  • commit 0e2d6795e8dbe91c2f5473564c6b25d11df3778b upstream.

    Add a device-id entry for the LongSung M5710 module.

    T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=480 MxCh= 0
    D: Ver= 2.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1
    P: Vendor=2df3 ProdID=9d03 Rev= 1.00
    S: Manufacturer=Marvell
    S: Product=Mobile Composite Device Bus
    S: SerialNumber=
    C:* #Ifs= 5 Cfg#= 1 Atr=c0 MxPwr=500mA
    A: FirstIf#= 0 IfCount= 2 Cls=e0(wlcon) Sub=01 Prot=03
    I:* If#= 0 Alt= 0 #EPs= 1 Cls=e0(wlcon) Sub=01 Prot=03 Driver=rndis_host
    E: Ad=87(I) Atr=03(Int.) MxPS= 64 Ivl=4096ms
    I:* If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=rndis_host
    E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=0c(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I:* If#= 2 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=0b(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I:* If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=89(I) Atr=03(Int.) MxPS= 64 Ivl=4096ms
    E: Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=0f(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    I:* If#= 5 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
    E: Ad=88(I) Atr=03(Int.) MxPS= 64 Ivl=4096ms
    E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
    E: Ad=0a(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms

    Signed-off-by: Daniel Palmer
    https://lore.kernel.org/r/20201227031716.1343300-1-daniel@0x0f.com
    [ johan: drop id defines, only bind to vendor class ]
    Cc: stable@vger.kernel.org
    Signed-off-by: Johan Hovold
    Signed-off-by: Greg Kroah-Hartman

    Daniel Palmer
     
  • commit 54d0a3ab80f49f19ee916def62fe067596833403 upstream.

    Stack-allocated buffers cannot be used for DMA (on all architectures) so
    allocate the flush command buffer using kmalloc().

    Fixes: 60a8fc017103 ("USB: add iuu_phoenix driver")
    Cc: stable # 2.6.25
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: Johan Hovold
    Signed-off-by: Greg Kroah-Hartman

    Johan Hovold
     
  • commit 96ebc9c871d8a28fb22aa758dd9188a4732df482 upstream.

    Here's another variant PNY Pro Elite USB 3.1 Gen 2 portable SSD that
    hangs and doesn't respond to ATA_1x pass-through commands. If it doesn't
    support these commands, it should respond properly to the host. Add it
    to the unusual uas list to be able to move forward with other
    operations.

    Cc: stable@vger.kernel.org
    Reviewed-by: Hans de Goede
    Acked-by: Oliver Neukum
    Signed-off-by: Thinh Nguyen
    Link: https://lore.kernel.org/r/2edc7af892d0913bf06f5b35e49ec463f03d5ed8.1609819418.git.Thinh.Nguyen@synopsys.com
    Signed-off-by: Greg Kroah-Hartman

    Thinh Nguyen
     
  • commit 718bf42b119de652ebcc93655a1f33a9c0d04b3c upstream.

    Fix shift out-of-bounds in vhci_hcd.c:

    UBSAN: shift-out-of-bounds in ../drivers/usb/usbip/vhci_hcd.c:399:41
    shift exponent 768 is too large for 32-bit type 'int'

    Fixes: 03cd00d538a6 ("usbip: vhci-hcd: Set the vhci structure up to work")
    Signed-off-by: Randy Dunlap
    Reported-by: syzbot+297d20e437b79283bf6d@syzkaller.appspotmail.com
    Cc: Yuyang Du
    Cc: Shuah Khan
    Cc: Greg Kroah-Hartman
    Cc: linux-usb@vger.kernel.org
    Cc: stable
    Link: https://lore.kernel.org/r/20201229071309.18418-1-rdunlap@infradead.org
    Signed-off-by: Greg Kroah-Hartman

    Randy Dunlap
     
  • commit 5d5323a6f3625f101dbfa94ba3ef7706cce38760 upstream.

    The commit 0472bf06c6fd ("xhci: Prevent U1/U2 link pm states if exit
    latency is too long") was constraining the xhci code not to allow U1/U2
    sleep states if the latency to wake up from the U-states reached the
    service interval of an periodic endpoint. This fix was not taking into
    account that in case the quirk XHCI_INTEL_HOST is set, the wakeup time
    will be calculated and configured differently.

    It checks for u1_params.mel/u2_params.mel as a limit. But the code could
    decide to write another MEL into the hardware. This leads to broken
    cases where not enough bandwidth is available for other devices:

    usb 1-2: can't set config #1, error -28

    This patch is fixing that case by checking for timeout_ns after the
    wakeup time was calculated depending on the quirks.

    Fixes: 0472bf06c6fd ("xhci: Prevent U1/U2 link pm states if exit latency is too long")
    Signed-off-by: Michael Grzeschik
    Cc: stable
    Link: https://lore.kernel.org/r/20201215193147.11738-1-m.grzeschik@pengutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Michael Grzeschik
     
  • commit 83a43ff80a566de8718dfc6565545a0080ec1fb5 upstream.

    if of_find_device_by_node() succeed, usbmisc_get_init_data() doesn't have
    a corresponding put_device(). Thus add put_device() to fix the exception
    handling for this function implementation.

    Fixes: ef12da914ed6 ("usb: chipidea: imx: properly check for usbmisc")
    Signed-off-by: Yu Kuai
    Cc: stable
    Link: https://lore.kernel.org/r/20201117011430.642589-1-yukuai3@huawei.com
    Signed-off-by: Greg Kroah-Hartman

    Yu Kuai
     
  • commit e5f4ca3fce90a37b23a77bfcc86800d484a80514 upstream.

    First of all the commit e0082698b689 ("usb: dwc3: ulpi: conditionally
    resume ULPI PHY") introduced the Suspend USB2.0 HS/FS/LS PHY regression,
    as by design of the fix any attempt to read/write from/to the PHY control
    registers will completely disable the PHY suspension, which consequently
    will increase the USB bus power consumption. Secondly the fix won't work
    well for the very first attempt of the ULPI PHY control registers IO,
    because after disabling the USB2.0 PHY suspension functionality it will
    still take some time for the bus to resume from the sleep state if one has
    been reached before it. So the very first PHY register read/write
    operation will take more time than the busy-loop provides and the IO
    timeout error might be returned anyway.

    Here we suggest to fix the denoted problems in the following way. First of
    all let's not disable the Suspend USB2.0 HS/FS/LS PHY functionality so to
    make the controller and the USB2.0 bus more power efficient. Secondly
    instead of that we'll extend the PHY IO op wait procedure with 1 - 1.2 ms
    sleep if the PHY suspension is enabled (1ms should be enough as by LPM
    specification it is at most how long it takes for the USB2.0 bus to resume
    from L1 (Sleep) state). Finally in case if the USB2.0 PHY suspension
    functionality has been disabled on the DWC USB3 controller setup procedure
    we'll compensate the USB bus resume process latency by extending the
    busy-loop attempts counter.

    Fixes: e0082698b689 ("usb: dwc3: ulpi: conditionally resume ULPI PHY")
    Acked-by: Heikki Krogerus
    Signed-off-by: Serge Semin
    Link: https://lore.kernel.org/r/20201210085008.13264-4-Sergey.Semin@baikalelectronics.ru
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Serge Semin
     
  • commit fca3f138105727c3a22edda32d02f91ce1bf11c9 upstream.

    Originally the procedure of the ULPI transaction finish detection has been
    developed as a simple busy-loop with just decrementing counter and no
    delays. It's wrong since on different systems the loop will take a
    different time to complete. So if the system bus and CPU are fast enough
    to overtake the ULPI bus and the companion PHY reaction, then we'll get to
    take a false timeout error. Fix this by converting the busy-loop procedure
    to take the standard bus speed, address value and the registers access
    mode into account for the busy-loop delay calculation.

    Here is the way the fix works. It's known that the ULPI bus is clocked
    with 60MHz signal. In accordance with [1] the ULPI bus protocol is created
    so to spend 5 and 6 clock periods for immediate register write and read
    operations respectively, and 6 and 7 clock periods - for the extended
    register writes and reads. Based on that we can easily pre-calculate the
    time which will be needed for the controller to perform a requested IO
    operation. Note we'll still preserve the attempts counter in case if the
    DWC USB3 controller has got some internals delays.

    [1] UTMI+ Low Pin Interface (ULPI) Specification, Revision 1.1,
    October 20, 2004, pp. 30 - 36.

    Fixes: 88bc9d194ff6 ("usb: dwc3: add ULPI interface support")
    Acked-by: Heikki Krogerus
    Signed-off-by: Serge Semin
    Link: https://lore.kernel.org/r/20201210085008.13264-3-Sergey.Semin@baikalelectronics.ru
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Serge Semin
     
  • commit ce722da66d3e9384aa2de9d33d584ee154e5e157 upstream.

    In accordance with [1] the DWC_usb3 core sets the GUSB2PHYACCn.VStsDone
    bit when the PHY vendor control access is done and clears it when the
    application initiates a new transaction. The doc doesn't say anything
    about the GUSB2PHYACCn.VStsBsy flag serving for the same purpose. Moreover
    we've discovered that the VStsBsy flag can be cleared before the VStsDone
    bit. So using the former as a signal of the PHY control registers
    completion might be dangerous. Let's have the VStsDone flag utilized
    instead then.

    [1] Synopsys DesignWare Cores SuperSpeed USB 3.0 xHCI Host Controller
    Databook, 2.70a, December 2013, p.388

    Fixes: 88bc9d194ff6 ("usb: dwc3: add ULPI interface support")
    Acked-by: Heikki Krogerus
    Signed-off-by: Serge Semin
    Link: https://lore.kernel.org/r/20201210085008.13264-2-Sergey.Semin@baikalelectronics.ru
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Serge Semin
     
  • commit a5c7682aaaa10e42928d73de1c9e1e02d2b14c2e upstream.

    If an active transfer is dequeued, then the endpoint is freed to start a
    new transfer. Make sure to clear the endpoint's transfer wait flag for
    this case.

    Fixes: e0d19563eb6c ("usb: dwc3: gadget: Wait for transfer completion")
    Cc: stable@vger.kernel.org
    Acked-by: Felipe Balbi
    Signed-off-by: Thinh Nguyen
    Link: https://lore.kernel.org/r/b81cd5b5281cfbfdadb002c4bcf5c9be7c017cfd.1609828485.git.Thinh.Nguyen@synopsys.com
    Signed-off-by: Greg Kroah-Hartman

    Thinh Nguyen
     
  • commit a1383b3537a7bea1c213baa7878ccc4ecf4413b5 upstream.

    usb_gadget_deactivate/usb_gadget_activate does not execute the UDC start
    operation, which may leave EP0 disabled and event IRQs disabled when
    re-activating the function. Move the enabling/disabling of USB EP0 and
    device event IRQs to be performed in the pullup routine.

    Fixes: ae7e86108b12 ("usb: dwc3: Stop active transfers before halting the controller")
    Tested-by: Michael Tretter
    Cc: stable
    Reported-by: Michael Tretter
    Signed-off-by: Wesley Cheng
    Link: https://lore.kernel.org/r/1609282837-21666-1-git-send-email-wcheng@codeaurora.org
    Signed-off-by: Greg Kroah-Hartman

    Wesley Cheng
     
  • commit a5ada3dfe6a20f41f91448b9034a1ef8da3dc87d upstream.

    dwc3_meson_g12a_probe() does not invoke clk_bulk_disable_unprepare()
    on one error handling path. This patch fixes that.

    Fixes: 347052e3bf1b ("usb: dwc3: meson-g12a: fix USB2 PHY initialization on G12A and A1 SoCs")
    Reported-by: Hulk Robot
    Signed-off-by: Zheng Zengkai
    Cc: stable
    Reviewed-by: Martin Blumenstingl
    Link: https://lore.kernel.org/r/20201215025459.91794-1-zhengzengkai@huawei.com
    Signed-off-by: Greg Kroah-Hartman

    Zheng Zengkai
     
  • commit 0f041b8592daaaea46e91a8ebb3b47e6e0171fd8 upstream.

    Warm reboot scenarios some times type C Mux driver gets Mux configuration
    request as HPD=1,IRQ=1. In that scenario typeC Mux driver need to configure
    Mux as follows as per IOM requirement:
    (1). Confgiure Mux HPD = 1, IRQ = 0
    (2). Configure Mux with HPD = 1, IRQ = 1

    IOM expects TypeC Mux configuration as follows:
    (1). HPD=1, IRQ=0
    (2). HPD=1, IRQ=1
    if IOM gets mux config request (2) without configuring (1), it will ignore
    the request. The impact of this is there is no DP_alt mode display.

    Fixes: 43d596e32276 ("usb: typec: intel_pmc_mux: Check the port status before connect")
    Cc: stable@vger.kernel.org
    Reviewed-by: Heikki Krogerus
    Signed-off-by: Madhusudanarao Amara
    Link: https://lore.kernel.org/r/20201216140918.49197-1-madhusudanarao.amara@intel.com
    Signed-off-by: Greg Kroah-Hartman

    Madhusudanarao Amara
     
  • commit 5e5ff0b4b6bcb4d17b7a26ec8bcfc7dd4651684f upstream.

    syzbot is reporting UAF at usb_submit_urb() [1], for
    service_outstanding_interrupt() is not checking WDM_DISCONNECTING
    before calling usb_submit_urb(). Close the race by doing same checks
    wdm_read() does upon retry.

    Also, while wdm_read() checks WDM_DISCONNECTING with desc->rlock held,
    service_interrupt_work() does not hold desc->rlock. Thus, it is possible
    that usb_submit_urb() is called from service_outstanding_interrupt() from
    service_interrupt_work() after WDM_DISCONNECTING was set and kill_urbs()
    from wdm_disconnect() completed. Thus, move kill_urbs() in
    wdm_disconnect() to after cancel_work_sync() (which makes sure that
    service_interrupt_work() is no longer running) completed.

    Although it seems to be safe to dereference desc->intf->dev in
    service_outstanding_interrupt() even if WDM_DISCONNECTING was already set
    because desc->rlock or cancel_work_sync() prevents wdm_disconnect() from
    reaching list_del() before service_outstanding_interrupt() completes,
    let's not emit error message if WDM_DISCONNECTING is set by
    wdm_disconnect() while usb_submit_urb() is in progress.

    [1] https://syzkaller.appspot.com/bug?extid=9e04e2df4a32fb661daf

    Reported-by: syzbot
    Signed-off-by: Tetsuo Handa
    Cc: stable
    Link: https://lore.kernel.org/r/620e2ee0-b9a3-dbda-a25b-a93e0ed03ec5@i-love.sakura.ne.jp
    Signed-off-by: Greg Kroah-Hartman

    Tetsuo Handa
     
  • commit 0ffc76539e6e8d28114f95ac25c167c37b5191b3 upstream.

    This device is supported by the IR Toy driver.

    Reported-by: Georgi Bakalski
    Signed-off-by: Sean Young
    Acked-by: Oliver Neukum
    Cc: stable
    Link: https://lore.kernel.org/r/20201227134502.4548-2-sean@mess.org
    Signed-off-by: Greg Kroah-Hartman

    Sean Young
     
  • commit e2459108b5a0604c4b472cae2b3cb8d3444c77fb upstream.

    Enable Super speed plus in configfs to support USB3.1 Gen2.
    This ensures that when a USB gadget is plugged in, it is
    enumerated as Gen 2 and connected at 10 Gbps if the host and
    cable are capable of it.

    Many in-tree gadget functions (fs, midi, acm, ncm, mass_storage,
    etc.) already have SuperSpeed Plus support.

    Tested: plugged gadget into Linux host and saw:
    [284907.385986] usb 8-2: new SuperSpeedPlus Gen 2 USB device number 3 using xhci_hcd

    Tested-by: Lorenzo Colitti
    Acked-by: Felipe Balbi
    Signed-off-by: taehyun.cho
    Signed-off-by: Lorenzo Colitti
    Link: https://lore.kernel.org/r/20210106154625.2801030-1-lorenzo@google.com
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    taehyun.cho
     
  • commit d887d6104adeb94d1b926936ea21f07367f0ff9f upstream.

    If an error occurs after calling 'mtk_hsdma_init()', it must be undone by
    a corresponding call to 'mtk_hsdma_uninit()' as already done in the
    remove function.

    Fixes: 0853c7a53eb3 ("staging: mt7621-dma: ralink: add rt2880 dma engine")
    Signed-off-by: Christophe JAILLET
    Cc: stable
    Link: https://lore.kernel.org/r/20201213153513.138723-1-christophe.jaillet@wanadoo.fr
    Signed-off-by: Greg Kroah-Hartman

    Christophe JAILLET
     
  • commit cab36da4bf1a35739b091b73714a39a1bbd02b05 upstream.

    Return -EFAULT on error instead of the number of bytes remaining to be
    copied.

    Fixes: bac42fb21259 ("comedi: get rid of compat_alloc_user_space() mess in COMEDI_CMD{,TEST} compat")
    Signed-off-by: Dan Carpenter
    Cc: stable
    Link: https://lore.kernel.org/r/X8c3pfwFy2jpy4BP@mwanda
    Signed-off-by: Greg Kroah-Hartman

    Dan Carpenter
     
  • commit 3ce47d95b7346dcafd9bed3556a8d072cb2b8571 upstream.

    Commit eff8728fe698 ("vmlinux.lds.h: Add PGO and AutoFDO input
    sections") added ".text.unlikely.*" and ".text.hot.*" due to an LLVM
    change [1].

    After another LLVM change [2], these sections are seen in some PowerPC
    builds, where there is a orphan section warning then build failure:

    $ make -skj"$(nproc)" \
    ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- LLVM=1 O=out \
    distclean powernv_defconfig zImage.epapr
    ld.lld: warning: kernel/built-in.a(panic.o):(.text.unlikely.) is being placed in '.text.unlikely.'
    ...
    ld.lld: warning: address (0xc000000000009314) of section .text is not a multiple of alignment (256)
    ...
    ERROR: start_text address is c000000000009400, should be c000000000008000
    ERROR: try to enable LD_HEAD_STUB_CATCH config option
    ERROR: see comments in arch/powerpc/tools/head_check.sh
    ...

    Explicitly handle these sections like in the main linker script so
    there is no more build failure.

    [1]: https://reviews.llvm.org/D79600
    [2]: https://reviews.llvm.org/D92493

    Fixes: 83a092cf95f2 ("powerpc: Link warning for orphan sections")
    Cc: stable@vger.kernel.org
    Signed-off-by: Nathan Chancellor
    Signed-off-by: Michael Ellerman
    Link: https://github.com/ClangBuiltLinux/linux/issues/1218
    Link: https://lore.kernel.org/r/20210104205952.1399409-1-natechancellor@gmail.com
    Signed-off-by: Greg Kroah-Hartman

    Nathan Chancellor
     
  • commit f93274ef0fe972c120c96b3207f8fce376231a60 upstream.

    The function derive_pub_key() should be calling memzero_explicit()
    instead of memset() in case the complier decides to optimize away the
    call to memset() because it "knows" no one is going to touch the memory
    anymore.

    Cc: stable
    Reported-by: Ilil Blum Shem-Tov
    Tested-by: Ilil Blum Shem-Tov
    Link: https://lore.kernel.org/r/X8ns4AfwjKudpyfe@kroah.com
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     
  • commit 0aa171e9b267ce7c52d3a3df7bc9c1fc0203dec5 upstream.

    Pavel reports that commit 17858b140bf4 ("crypto: ecdh - avoid unaligned
    accesses in ecdh_set_secret()") fixes one problem but introduces another:
    the unconditional memcpy() introduced by that commit may overflow the
    target buffer if the source data is invalid, which could be the result of
    intentional tampering.

    So check params.key_size explicitly against the size of the target buffer
    before validating the key further.

    Fixes: 17858b140bf4 ("crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()")
    Reported-by: Pavel Machek
    Cc:
    Signed-off-by: Ard Biesheuvel
    Signed-off-by: Herbert Xu
    Signed-off-by: Greg Kroah-Hartman

    Ard Biesheuvel
     
  • [ Upstream commit 52abca64fd9410ea6c9a3a74eab25663b403d7da ]

    blk_queue_enter() accepts BLK_MQ_REQ_PM requests independent of the runtime
    power management state. Now that SCSI domain validation no longer depends
    on this behavior, modify the behavior of blk_queue_enter() as follows:

    - Do not accept any requests while suspended.

    - Only process power management requests while suspending or resuming.

    Submitting BLK_MQ_REQ_PM requests to a device that is runtime suspended
    causes runtime-suspended devices not to resume as they should. The request
    which should cause a runtime resume instead gets issued directly, without
    resuming the device first. Of course the device can't handle it properly,
    the I/O fails, and the device remains suspended.

    The problem is fixed by checking that the queue's runtime-PM status isn't
    RPM_SUSPENDED before allowing a request to be issued, and queuing a
    runtime-resume request if it is. In particular, the inline
    blk_pm_request_resume() routine is renamed blk_pm_resume_queue() and the
    code is unified by merging the surrounding checks into the routine. If the
    queue isn't set up for runtime PM, or there currently is no restriction on
    allowed requests, the request is allowed. Likewise if the BLK_MQ_REQ_PM
    flag is set and the status isn't RPM_SUSPENDED. Otherwise a runtime resume
    is queued and the request is blocked until conditions are more suitable.

    [ bvanassche: modified commit message and removed Cc: stable because
    without the previous patches from this series this patch would break
    parallel SCSI domain validation + introduced queue_rpm_status() ]

    Link: https://lore.kernel.org/r/20201209052951.16136-9-bvanassche@acm.org
    Cc: Jens Axboe
    Cc: Christoph Hellwig
    Cc: Hannes Reinecke
    Cc: Can Guo
    Cc: Stanley Chu
    Cc: Ming Lei
    Cc: Rafael J. Wysocki
    Reported-and-tested-by: Martin Kepplinger
    Reviewed-by: Hannes Reinecke
    Reviewed-by: Can Guo
    Signed-off-by: Alan Stern
    Signed-off-by: Bart Van Assche
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin

    Alan Stern
     
  • [ Upstream commit a4d34da715e3cb7e0741fe603dcd511bed067e00 ]

    Remove flag RQF_PREEMPT and BLK_MQ_REQ_PREEMPT since these are no longer
    used by any kernel code.

    Link: https://lore.kernel.org/r/20201209052951.16136-8-bvanassche@acm.org
    Cc: Can Guo
    Cc: Stanley Chu
    Cc: Alan Stern
    Cc: Ming Lei
    Cc: Rafael J. Wysocki
    Cc: Martin Kepplinger
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Hannes Reinecke
    Reviewed-by: Jens Axboe
    Reviewed-by: Can Guo
    Signed-off-by: Bart Van Assche
    Signed-off-by: Martin K. Petersen
    Signed-off-by: Sasha Levin

    Bart Van Assche
     
  • commit 5c3b5796866f85354a5ce76a28f8ffba0dcefc7e upstream.

    There have been multiple revisions of the patch fix the h5->rx_skb
    leak. Accidentally the first revision (which is buggy) and v5 have
    both been merged:

    v1 commit 70f259a3f427 ("Bluetooth: hci_h5: close serdev device and free
    hu in h5_close");
    v5 commit 855af2d74c87 ("Bluetooth: hci_h5: fix memory leak in h5_close")

    The correct v5 makes changes slightly higher up in the h5_close()
    function, which allowed both versions to get merged without conflict.

    The changes from v1 unconditionally frees the h5 data struct, this
    is wrong because in the serdev enumeration case the memory is
    allocated in h5_serdev_probe() like this:

    h5 = devm_kzalloc(dev, sizeof(*h5), GFP_KERNEL);

    So its lifetime is tied to the lifetime of the driver being bound
    to the serdev and it is automatically freed when the driver gets
    unbound. In the serdev case the same h5 struct is re-used over
    h5_close() and h5_open() calls and thus MUST not be free-ed in
    h5_close().

    The serdev_device_close() added to h5_close() is incorrect in the
    same way, serdev_device_close() is called on driver unbound too and
    also MUST no be called from h5_close().

    This reverts the changes made by merging v1 of the patch, so that
    just the changes of the correct v5 remain.

    Cc: Anant Thazhemadam
    Signed-off-by: Hans de Goede
    Signed-off-by: Marcel Holtmann
    Signed-off-by: Greg Kroah-Hartman

    Hans de Goede