android_kernel_msm-6.1_noth.../drivers
Wesley Cheng 986fffb590 UPSTREAM: usb: gadget: f_fs: Fix race between aio_cancel() and AIO request complete
FFS based applications can utilize the aio_cancel() callback to dequeue
pending USB requests submitted to the UDC.  There is a scenario where the
FFS application issues an AIO cancel call, while the UDC is handling a
soft disconnect.  For a DWC3 based implementation, the callstack looks
like the following:

    DWC3 Gadget                               FFS Application
dwc3_gadget_soft_disconnect()              ...
  --> dwc3_stop_active_transfers()
    --> dwc3_gadget_giveback(-ESHUTDOWN)
      --> ffs_epfile_async_io_complete()   ffs_aio_cancel()
        --> usb_ep_free_request()            --> usb_ep_dequeue()

There is currently no locking implemented between the AIO completion
handler and AIO cancel, so the issue occurs if the completion routine is
running in parallel to an AIO cancel call coming from the FFS application.
As the completion call frees the USB request (io_data->req) the FFS
application is also referencing it for the usb_ep_dequeue() call.  This can
lead to accessing a stale/hanging pointer.

commit b566d38857fc ("usb: gadget: f_fs: use io_data->status consistently")
relocated the usb_ep_free_request() into ffs_epfile_async_io_complete().
However, in order to properly implement locking to mitigate this issue, the
spinlock can't be added to ffs_epfile_async_io_complete(), as
usb_ep_dequeue() (if successfully dequeuing a USB request) will call the
function driver's completion handler in the same context.  Hence, leading
into a deadlock.

Fix this issue by moving the usb_ep_free_request() back to
ffs_user_copy_worker(), and ensuring that it explicitly sets io_data->req
to NULL after freeing it within the ffs->eps_lock.  This resolves the race
condition above, as the ffs_aio_cancel() routine will not continue
attempting to dequeue a request that has already been freed, or the
ffs_user_copy_work() not freeing the USB request until the AIO cancel is
done referencing it.

This fix depends on
  commit b566d38857fc ("usb: gadget: f_fs: use io_data->status
  consistently")

Fixes: 2e4c7553cd ("usb: gadget: f_fs: add aio support")
Cc: stable <stable@kernel.org>	# b566d38857fc ("usb: gadget: f_fs: use io_data->status consistently")
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Link: https://lore.kernel.org/r/20240409014059.6740-1-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 334976932
(cherry picked from commit 24729b307eefcd7c476065cd7351c1a018082c19)
Change-Id: I56f6b9d24c239e73edff94e1f9f33ab41a9bd37b
Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
2024-06-05 14:41:37 +05:30
..
accessibility
acpi BACKPORT: iommu: Have __iommu_probe_device() check for already probed devices 2024-06-03 17:16:48 +00:00
amba ANDROID: Build some tegra configs as vendor module 2024-05-31 04:40:23 +00:00
android ANDROID: binder: fix KMI-break due to alloc->lock 2024-05-29 20:51:37 +00:00
ata Merge 6.1.65 into android14-6.1-lts 2023-12-20 13:31:28 +00:00
atm Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
auxdisplay auxdisplay: hd44780: move cursor home after clear display command 2023-12-08 08:51:16 +01:00
base Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
bcma
block Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
bluetooth Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
bus Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
cdrom
char This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
clk Merge tag 'android14-6.1.78_r00' into branch android14-6.1 2024-05-30 15:23:39 +00:00
clocksource Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
comedi
connector
counter
cpufreq This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
cpuidle
crypto Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
cxl Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
dax
dca
devfreq This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
dio
dma Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
dma-buf Merge "Merge tag 'android14-6.1.68_r00' into branch 'android14-6.1'" into android14-6.1 2024-01-24 17:34:59 +00:00
edac Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
eisa
extcon
firewire Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
firmware This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
fpga
fsi
gnss
gpio ANDROID: Build some tegra configs as vendor module 2024-05-31 04:40:23 +00:00
gpu Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
greybus
hid Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
hsi
hte
hv
hwmon Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
hwspinlock
hwtracing FROMGIT: coresight: etm4x: Fix access to resource selector registers 2024-04-26 12:54:24 -07:00
i2c ANDROID: Build some tegra configs as vendor module 2024-05-31 04:40:23 +00:00
i3c i3c: master: cdns: Update maximum prescaler value for i2c clock 2024-02-05 20:12:58 +00:00
idle
iio Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
infiniband Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
input Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
interconnect Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
iommu BACKPORT: iommu: Have __iommu_probe_device() check for already probed devices 2024-06-03 17:16:48 +00:00
ipack
irqchip BACKPORT: irqchip/gic-v3: Work around affinity issues on ASR8601 2024-01-26 10:14:07 +00:00
isdn
leds Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
macintosh
mailbox Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
mcb mcb: fix error handling for different scenarios when parsing 2023-11-28 17:07:13 +00:00
md Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
media Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
memory
memstick
message
mfd Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
misc Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
mmc This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
most
mtd Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
mux
net Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
nfc
ntb
nubus
nvdimm
nvme Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
nvmem
of Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
opp OPP: Pass rounded rate to _set_opp() 2024-01-31 16:16:58 -08:00
parisc parisc/power: Fix power soft-off button emulation on qemu 2024-01-31 16:16:59 -08:00
parport Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
pci Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
pcmcia pcmcia: ds: fix possible name leak in error path in pcmcia_device_add() 2023-11-20 11:52:13 +01:00
peci
perf
phy Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
pinctrl Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
platform Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
pnp PNP: ACPI: fix fortify warning 2024-02-05 20:12:47 +00:00
power Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
powercap ANDROID: idle_inject: Export function symbols 2024-01-25 19:43:25 +00:00
pps
ps3
ptp ptp: annotate data-race around q->head and q->tail 2023-11-28 17:07:05 +00:00
pwm Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
rapidio
ras
regulator regulator: ti-abb: don't use devm_platform_ioremap_resource_byname for shared interrupt register 2024-02-05 20:13:00 +00:00
remoteproc
reset Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
rpmsg rpmsg: virtio: Free driver_override when rpmsg_remove() 2024-01-31 16:16:59 -08:00
rtc rtc: Extend timeout for waiting for UIP to clear to 1s 2024-01-31 16:17:01 -08:00
s390 Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
sbus
scsi Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
sh
siox
slimbus
soc Merge tag 'android14-6.1.78_r00' into branch android14-6.1 2024-05-30 15:23:39 +00:00
soundwire Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
spi This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
spmi Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
ssb
staging Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
target Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
tc
tee tee: optee: Fix supplicant based device enumeration 2023-12-13 18:39:12 +01:00
thermal This is the 6.1.76 stable release 2024-04-16 15:01:11 +00:00
thunderbolt Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
tty ANDROID: Build some tegra configs as vendor module 2024-05-31 04:40:23 +00:00
ufs UPSTREAM: scsi: ufs: core: Fix racing issue between ufshcd_mcq_abort() and ISR 2024-02-26 17:25:00 +00:00
uio Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
usb UPSTREAM: usb: gadget: f_fs: Fix race between aio_cancel() and AIO request complete 2024-06-05 14:41:37 +05:30
vdpa Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
vfio
vhost Merge 6.1.78 into android14-6.1-lts 2024-04-19 12:19:39 +00:00
video Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
virt ANDROID: virt: gunyah: Move send_lock around req and reply 2024-03-21 14:48:00 +00:00
virtio UPSTREAM: virtio: Add support for no-reset virtio PCI PM 2024-02-14 00:31:36 +00:00
vlynq
w1
watchdog Reapply "Merge tag 'android14-6.1.75_r00' into android14-6.1" 2024-04-02 19:49:12 +00:00
xen Merge 6.1.77 into android14-6.1-lts 2024-04-17 08:34:35 +00:00
zorro
Kconfig
Makefile