linux/drivers
Duoming Zhou 9cb83d4be0 wifi: brcmfmac: fix use-after-free when rescheduling brcmf_btcoex_info work
The brcmf_btcoex_detach() only shuts down the btcoex timer, if the
flag timer_on is false. However, the brcmf_btcoex_timerfunc(), which
runs as timer handler, sets timer_on to false. This creates critical
race conditions:

1.If brcmf_btcoex_detach() is called while brcmf_btcoex_timerfunc()
is executing, it may observe timer_on as false and skip the call to
timer_shutdown_sync().

2.The brcmf_btcoex_timerfunc() may then reschedule the brcmf_btcoex_info
worker after the cancel_work_sync() has been executed, resulting in
use-after-free bugs.

The use-after-free bugs occur in two distinct scenarios, depending on
the timing of when the brcmf_btcoex_info struct is freed relative to
the execution of its worker thread.

Scenario 1: Freed before the worker is scheduled

The brcmf_btcoex_info is deallocated before the worker is scheduled.
A race condition can occur when schedule_work(&bt_local->work) is
called after the target memory has been freed. The sequence of events
is detailed below:

CPU0                           | CPU1
brcmf_btcoex_detach            | brcmf_btcoex_timerfunc
                               |   bt_local->timer_on = false;
  if (cfg->btcoex->timer_on)   |
    ...                        |
  cancel_work_sync();          |
  ...                          |
  kfree(cfg->btcoex); // FREE  |
                               |   schedule_work(&bt_local->work); // USE

Scenario 2: Freed after the worker is scheduled

The brcmf_btcoex_info is freed after the worker has been scheduled
but before or during its execution. In this case, statements within
the brcmf_btcoex_handler() — such as the container_of macro and
subsequent dereferences of the brcmf_btcoex_info object will cause
a use-after-free access. The following timeline illustrates this
scenario:

CPU0                            | CPU1
brcmf_btcoex_detach             | brcmf_btcoex_timerfunc
                                |   bt_local->timer_on = false;
  if (cfg->btcoex->timer_on)    |
    ...                         |
  cancel_work_sync();           |
  ...                           |   schedule_work(); // Reschedule
                                |
  kfree(cfg->btcoex); // FREE   |   brcmf_btcoex_handler() // Worker
  /*                            |     btci = container_of(....); // USE
   The kfree() above could      |     ...
   also occur at any point      |     btci-> // USE
   during the worker's execution|
   */                           |

To resolve the race conditions, drop the conditional check and call
timer_shutdown_sync() directly. It can deactivate the timer reliably,
regardless of its current state. Once stopped, the timer_on state is
then set to false.

Fixes: 61730d4dff ("brcmfmac: support critical protocol API for DHCP")
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://patch.msgid.link/20250822050839.4413-1-duoming@zju.edu.cn
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
2025-08-26 13:46:18 +02:00
..
accel YAUAFFix due to dma_buf_fd() misuse 2025-08-12 12:10:33 -07:00
accessibility
acpi Merge branches 'acpi-ec' and 'acpi-processor' 2025-08-14 13:09:27 +02:00
amba
android
ata ata: libata-scsi: Fix CDL control 2025-08-14 18:58:12 +09:00
atm
auxdisplay
base
bcma
block ublk: check for unprivileged daemon on each I/O fetch 2025-08-11 07:57:48 -06:00
bluetooth Bluetooth: btnxpuart: Uses threaded IRQ for host wakeup handling 2025-08-15 10:13:26 -04:00
bus
cache
cdrom
cdx
char
clk
clocksource
comedi
connector
counter
cpufreq cpufreq: intel_pstate: Support Clearwater Forest OOB mode 2025-08-11 21:49:47 +02:00
cpuidle cpuidle: governors: menu: Avoid using invalid recent intervals data 2025-08-11 21:46:14 +02:00
crypto
cxl
dax
dca
devfreq
dio
dma
dma-buf
dpll
edac
eisa
extcon
firewire
firmware EFI updates for v6.17 2025-08-09 18:10:01 +03:00
fpga
fsi
fwctl
gnss
gpio gpio: mlxbf3: use platform_get_irq_optional() 2025-08-12 15:40:28 +02:00
gpu - Some more xe_migrate_access_memory fixes (Auld) 2025-08-15 09:50:26 +10:00
greybus
hid
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle intel_idle: Allow loading ACPI tables for any family 2025-08-11 21:43:26 +02:00
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md block-6.17-20250808 2025-08-09 08:47:28 +03:00
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net wifi: brcmfmac: fix use-after-free when rescheduling brcmf_btcoex_info work 2025-08-26 13:46:18 +02:00
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci PCI: vmd: Remove MSI-X check on child devices 2025-08-12 13:45:01 -05:00
pcmcia
peci
perf
phy
pinctrl
platform
pmdomain
pnp
power
powercap
pps
ps3
ptp ptp: prevent possible ABBA deadlock in ptp_clock_freerun() 2025-08-12 14:17:35 -07:00
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi Merge branch '6.17/scsi-queue' into 6.17/scsi-fixes 2025-08-12 21:36:18 -04:00
sh
siox
slimbus
soc soc/tegra: pmc: Ensure power-domains are in a known state 2025-08-11 12:24:43 +02:00
soundwire
spi spi: Fixes for v6.17 2025-08-09 08:43:24 +03:00
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty module: Rename EXPORT_SYMBOL_GPL_FOR_MODULES to EXPORT_SYMBOL_FOR_MODULES 2025-08-11 16:16:36 +02:00
ufs Merge branch '6.17/scsi-queue' into 6.17/scsi-fixes 2025-08-12 21:36:18 -04:00
uio
usb
vdpa
vfio
vhost
video
virt virt: sev-guest: Satisfy linear mapping requirement in get_derived_key() 2025-08-15 17:05:39 +02:00
virtio
w1
watchdog
xen
zorro
Kconfig
Makefile