linux-stable/drivers/usb/dwc2
Heiko Stuebner 750829e193 usb: dwc2: Fix endpoint direction check in ep_from_windex
commit f670e9f9c8 upstream.

dwc2_hsotg_process_req_status uses ep_from_windex() to retrieve
the endpoint for the index provided in the wIndex request param.

In a test-case with a rndis gadget running and sending a malformed
packet to it like:
    dev.ctrl_transfer(
        0x82,      # bmRequestType
        0x00,       # bRequest
        0x0000,     # wValue
        0x0001,     # wIndex
        0x00       # wLength
    )
it is possible to cause a crash:

[  217.533022] dwc2 ff300000.usb: dwc2_hsotg_process_req_status: USB_REQ_GET_STATUS
[  217.559003] Unable to handle kernel read from unreadable memory at virtual address 0000000000000088
...
[  218.313189] Call trace:
[  218.330217]  ep_from_windex+0x3c/0x54
[  218.348565]  usb_gadget_giveback_request+0x10/0x20
[  218.368056]  dwc2_hsotg_complete_request+0x144/0x184

This happens because ep_from_windex wants to compare the endpoint
direction even if index_to_ep() didn't return an endpoint due to
the direction not matching.

The fix is easy insofar that the actual direction check is already
happening when calling index_to_ep() which will return NULL if there
is no endpoint for the targeted direction, so the offending check
can go away completely.

Fixes: c6f5c050e2 ("usb: dwc2: gadget: add bi-directional endpoint support")
Cc: stable@vger.kernel.org
Reported-by: Gerhard Klostermeier <gerhard.klostermeier@syss.de>
Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
Link: https://lore.kernel.org/r/20210127103919.58215-1-heiko@sntech.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-02-10 09:29:10 +01:00
..
core.c usb: dwc2: Update Core Reset programming flow. 2020-05-25 11:09:44 +03:00
core.h usb: dwc2: override PHY input signals with usb role switch support 2020-10-02 13:29:13 +03:00
core_intr.c usb: dwc2: gadget: move gadget resume after the core is in L0 state 2020-05-25 11:09:39 +03:00
debug.h USB: dwc2: Use the correct style for SPDX License Identifier 2020-05-05 10:58:50 +03:00
debugfs.c USB: ch9: add "USB_" prefix in front of TEST defines 2020-06-24 15:01:24 +02:00
drd.c usb: dwc2: override PHY input signals with usb role switch support 2020-10-02 13:29:13 +03:00
gadget.c usb: dwc2: Fix endpoint direction check in ep_from_windex 2021-02-10 09:29:10 +01:00
hcd.c usb: dwc2: use well defined macros for power_down 2020-06-18 10:13:16 +02:00
hcd.h USB: dwc2: Use the correct style for SPDX License Identifier 2020-05-05 10:58:50 +03:00
hcd_ddma.c
hcd_intr.c usb: dwc2: host: Fix wMaxPacketSize handling (fix webcam regression) 2019-06-06 13:51:41 +03:00
hcd_queue.c usb: dwc2: host: Fix wMaxPacketSize handling (fix webcam regression) 2019-06-06 13:51:41 +03:00
hw.h usb: dwc2: Update Core Reset programming flow. 2020-05-25 11:09:44 +03:00
Kconfig usb: dwc2: override PHY input signals with usb role switch support 2020-10-02 13:29:13 +03:00
Makefile usb: dwc2: override PHY input signals with usb role switch support 2020-10-02 13:29:13 +03:00
params.c usb: dwc2: don't use ID/Vbus detection if usb-role-switch on STM32MP15 SoCs 2020-10-02 13:29:13 +03:00
pci.c
platform.c usb: dwc2: Avoid leaving the error_debugfs label unused 2020-10-27 11:33:53 +02:00