android_kernel_xiaomi_sm8450/drivers/usb/cdns3
Frank Li 1e204a8e9e usb: cdns3: fix memory double free when handle zero packet
commit 5fd9e45f1ebcd57181358af28506e8a661a260b3 upstream.

829  if (request->complete) {
830          spin_unlock(&priv_dev->lock);
831          usb_gadget_giveback_request(&priv_ep->endpoint,
832                                    request);
833          spin_lock(&priv_dev->lock);
834  }
835
836  if (request->buf == priv_dev->zlp_buf)
837      cdns3_gadget_ep_free_request(&priv_ep->endpoint, request);

Driver append an additional zero packet request when queue a packet, which
length mod max packet size is 0. When transfer complete, run to line 831,
usb_gadget_giveback_request() will free this requestion. 836 condition is
true, so cdns3_gadget_ep_free_request() free this request again.

Log:

[ 1920.140696][  T150] BUG: KFENCE: use-after-free read in cdns3_gadget_giveback+0x134/0x2c0 [cdns3]
[ 1920.140696][  T150]
[ 1920.151837][  T150] Use-after-free read at 0x000000003d1cd10b (in kfence-#36):
[ 1920.159082][  T150]  cdns3_gadget_giveback+0x134/0x2c0 [cdns3]
[ 1920.164988][  T150]  cdns3_transfer_completed+0x438/0x5f8 [cdns3]

Add check at line 829, skip call usb_gadget_giveback_request() if it is
additional zero length packet request. Needn't call
usb_gadget_giveback_request() because it is allocated in this driver.

Cc: stable@vger.kernel.org
Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Reviewed-by: Roger Quadros <rogerq@kernel.org>
Acked-by: Peter Chen <peter.chen@kernel.org>
Link: https://lore.kernel.org/r/20240202154217.661867-2-Frank.Li@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-03-01 13:16:49 +01:00
..
cdns3-imx.c usb: cdns3: imx: fix can't create core device the second time issue 2021-01-27 11:55:17 +01:00
cdns3-pci-wrap.c usb: cdns3: Fix issue with using incorrect PCI device function 2023-04-05 11:23:40 +02:00
cdns3-ti.c USB: Replace HTTP links with HTTPS ones 2020-07-21 13:41:57 +02:00
core.c Revert "usb: common: usb-conn-gpio: Set last role to unknown before initial detection" 2023-07-27 08:44:06 +02:00
core.h usb: cdns3: Add support for DRD CDNSP 2022-12-02 17:40:03 +01:00
debug.h usb: cdns3: fix spelling mistake and rework grammar in text 2020-01-24 09:41:27 +01:00
drd.c usb: cdns3: Add support for DRD CDNSP 2022-12-02 17:40:03 +01:00
drd.h usb: cdns3: Add support for DRD CDNSP 2022-12-02 17:40:03 +01:00
ep0.c usb: cdns3: Fixes for sparse warnings 2024-02-23 08:41:50 +01:00
gadget-export.h
gadget.c usb: cdns3: fix memory double free when handle zero packet 2024-03-01 13:16:49 +01:00
gadget.h usb: cdns3: fix iso transfer error when mult is not zero 2024-02-23 08:41:51 +01:00
host-export.h usb: cdns3: host: add .suspend_quirk for xhci-plat.c 2021-03-11 14:17:25 +01:00
host.c usb: cdns3: fix NULL pointer dereference on no platform data 2021-03-11 14:17:26 +01:00
Kconfig usb: cdns3: add NXP imx8qm glue layer 2020-01-15 10:39:22 +01:00
Makefile usb: cdns3: add NXP imx8qm glue layer 2020-01-15 10:39:22 +01:00
trace.c
trace.h usb: cdns3: trace: fix some endian issues 2020-07-09 10:13:07 +03:00