linux/drivers
Al Viro 2005aabe94 functionfs: use spinlock for FFS_DEACTIVATED/FFS_CLOSING transitions
When all files are closed, functionfs needs ffs_data_reset() to be
done before any further opens are allowed.

During that time we have ffs->state set to FFS_CLOSING; that makes
->open() fail with -EBUSY.  Once ffs_data_reset() is done, it
switches state (to FFS_READ_DESCRIPTORS) indicating that opening
that thing is allowed again.  There's a couple of additional twists:
	* mounting with -o no_disconnect delays ffs_data_reset()
from doing that at the final ->release() to the first subsequent
open().  That's indicated by ffs->state set to FFS_DEACTIVATED;
if open() sees that, it immediately switches to FFS_CLOSING and
proceeds with doing ffs_data_reset() before returning to userland.
	* a couple of usb callbacks need to force the delayed
transition; unfortunately, they are done in locking environment
that does not allow blocking and ffs_data_reset() can block.
As the result, if these callbacks see FFS_DEACTIVATED, they change
state to FFS_CLOSING and use schedule_work() to get ffs_data_reset()
executed asynchronously.

Unfortunately, the locking is rather insufficient.  A fix attempted
in e5bf5ee266 ("functionfs: fix the open/removal races") had closed
a bunch of UAF, but it didn't do anything to the callbacks, lacked
barriers in transition from FFS_CLOSING to FFS_READ_DESCRIPTORS
_and_ it had been too heavy-handed in open()/open() serialization -
I've used ffs->mutex for that, and it's being held over actual IO on
ep0, complete with copy_from_user(), etc.

Even more unfortunately, the userland side is apparently racy enough
to have the resulting timing changes (no failures, just a delayed
return of open(2)) disrupt the things quite badly.  Userland bugs
or not, it's a clear regression that needs to be dealt with.

Solution is to use a spinlock for serializing these state checks and
transitions - unlike ffs->mutex it can be taken in these callbacks
and it doesn't disrupt the timings in open().

We could introduce a new spinlock, but it's easier to use the one
that is already there (ffs->eps_lock) instead - the locking
environment is safe for it in all affected places.

Since now it is held over all places that alter or check the
open count (ffs->opened), there's no need to keep that atomic_t -
int would serve just fine and it's simpler that way.

Fixes: e5bf5ee266 ("functionfs: fix the open/removal races")
Fixes: 18d6b32fca ("usb: gadget: f_fs: add "no_disconnect" mode") # v4.0
Tested-by: Samuel Wu <wusamuel@google.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2026-02-05 13:53:12 -05:00
..
accel
accessibility
acpi ACPI: PM: s2idle: Add module parameter for LPS0 constraints checking 2026-01-13 23:10:25 +01:00
amba
android rust_binderfs: fix a dentry leak 2026-02-05 13:52:16 -05:00
ata ata: libata: Print features also for ATAPI devices 2026-01-13 22:00:02 +09:00
atm atm: Fix dma_free_coherent() size 2026-01-08 08:47:32 -08:00
auxdisplay
base Driver core fixes for 6.19-rc7 2026-01-24 10:13:22 -08:00
bcma
block block-6.19-20260122 2026-01-23 12:53:56 -08:00
bluetooth
bus
cache
cdrom
cdx
char
clk
clocksource riscv: clocksource: Fix stimecmp update hazard on RV32 2026-01-14 17:42:46 -07:00
comedi comedi: dmm32at: serialize use of paged registers 2026-01-16 16:43:51 +01:00
connector
counter
cpufreq
cpuidle
crypto
cxl cxl: Check for invalid addresses returned from translation functions on errors 2026-01-13 08:30:40 -07:00
dax drivers/dax: add some missing kerneldoc comment fields for struct dev_dax 2026-01-14 22:16:26 -08:00
dca
devfreq
dibs
dio
dma dmaengine: apple-admac: Add "apple,t8103-admac" compatible 2026-01-11 22:12:49 +05:30
dma-buf
dpll dpll: Prevent duplicate registrations 2026-01-22 08:08:42 -08:00
edac
eisa
extcon
firewire
firmware mm: rename cpu_bitmap field to flexible_array 2026-01-19 12:30:00 -08:00
fpga
fsi
fwctl
gnss
gpib
gpio gpio: shared: propagate configuration to pinctrl 2026-01-21 14:06:17 +01:00
gpu Mediatek DRM Fixes - 20260119 2026-01-23 10:13:12 +10:00
greybus
hid hid-for-linus-2026010801 2026-01-08 07:44:48 -08:00
hsi
hte
hv mshv: handle gpa intercepts for arm64 2026-01-15 07:29:14 +00:00
hwmon
hwspinlock
hwtracing intel_th: rename error label 2026-01-16 16:42:41 +01:00
i2c i2c-host-fixes for v6.19-rc7 2026-01-24 12:56:53 +01:00
i3c
idle
iio iio: dac: ad3552r-hs: fix out-of-bound write in ad3552r_hs_write_data_source 2026-01-11 13:25:15 +00:00
infiniband
input Input updates for v6.19-rc6 2026-01-25 09:42:25 -08:00
interconnect interconnect: debugfs: initialize src_node and dst_node to empty strings 2026-01-12 01:58:36 +02:00
iommu IOMMU Fixes for Linux v6.19-rc6 2026-01-23 12:46:12 -08:00
ipack
irqchip irqchip/gic-v3-its: Avoid truncating memory addresses 2026-01-20 10:11:29 +01:00
isdn mISDN: annotate data-race around dev->work 2026-01-20 18:37:41 -08:00
leds leds: led-class: Only Add LED to leds_list when it is fully ready 2026-01-20 16:02:01 +00:00
macintosh
mailbox
mcb
md block-6.19-20260122 2026-01-23 12:53:56 -08:00
media [GIT PULL for v6.19-rc6] media fixes 2026-01-14 08:18:01 -08:00
memory
memstick
message
mfd
misc mei: trace: treat reg parameter as string 2026-01-16 16:43:47 +01:00
mmc mmc: sdhci-of-dwcmshc: Fix DMA 128MB boundary for Eswin EIC7700 2026-01-22 13:26:08 +01:00
most
mtd treewide: Update email address 2026-01-11 06:09:11 -10:00
mux mux: mmio: Fix IS_ERR() vs NULL check in probe() 2026-01-16 16:42:08 +01:00
net Octeontx2-af: Add proper checks for fwdata 2026-01-22 08:09:00 -08:00
nfc Revert "nfc/nci: Add the inconsistency check between the input data length and count" 2026-01-17 18:02:50 -08:00
ntb ntb: transport: Fix uninitialized mutex 2026-01-17 11:57:39 -05:00
nubus
nvdimm
nvme block-6.19-20260116 2026-01-16 20:59:46 -08:00
nvmem
of of: fix reference count leak in of_alias_scan() 2026-01-17 10:20:43 -06:00
opp
parisc
parport
pci pci-v6.19-fixes-4 2026-01-23 13:20:24 -08:00
pcmcia
peci
perf
phy phy: freescale: imx8m-pcie: assert phy reset during power on 2026-01-14 21:44:39 +05:30
pinctrl
platform platform/x86: acer-wmi: Fix missing capability check 2026-01-20 17:10:56 +02:00
pmdomain pmdomain providers: 2026-01-23 13:12:49 -08:00
pnp
power
powercap
pps
ps3
ptp
pwm pwm: max7360: Populate missing .sizeof_wfhw in max7360_pwm_ops 2026-01-19 18:31:05 +01:00
rapidio
ras
regulator regulator: fp9931: Add missing memory allocation check 2026-01-19 14:42:02 +00:00
remoteproc
resctrl arm_mpam: Use non-atomic bitops when modifying feature bitmap 2026-01-16 12:04:20 +00:00
reset
rpmsg
rtc
s390 s390/ap: Fix wrong APQN fill calculation 2026-01-20 14:33:42 +01:00
sbus
scsi scsi: qla2xxx: Sanitize payload size to prevent member overflow 2026-01-16 23:08:11 -05:00
sh
siox
slimbus slimbus: core: clean up of_slim_get_device() 2026-01-16 16:43:05 +01:00
soc soc: renesas: Fix missing dependency on new CONFIG_CACHEMAINT_FOR_DMA 2026-01-15 18:13:33 -07:00
soundwire soundwire fix for 6.19 2026-01-18 12:29:12 -08:00
spi spi: intel-pci: Add support for Nova Lake SPI serial flash 2026-01-15 14:21:29 +00:00
spmi
ssb
staging
target scsi: target: iscsi: Fix use-after-free in iscsit_dec_session_usage_count() 2026-01-16 23:02:15 -05:00
tc
tee
thermal
thunderbolt
tty serial: Fix not set tty->port race condition 2026-01-23 17:23:09 +01:00
ufs
uio uio: pci_sva: correct '-ENODEV' check logic 2026-01-16 16:43:43 +01:00
usb functionfs: use spinlock for FFS_DEACTIVATED/FFS_CLOSING transitions 2026-02-05 13:53:12 -05:00
vdpa
vfio
vhost
video
virt
virtio
w1
watchdog
xen SCSI fixes on 20260125 2026-01-25 12:06:15 -08:00
zorro
Kconfig
Makefile