[PATCH v4 0/2] nfc: nci: uart: fix write_work teardown UAF (+ nfcmrvl drv_data)

From: Shubham Antil

Date: Tue Oct 06 2026 - 07:55:53 EST


This series fixes a use-after-free in the NFC NCI UART line-discipline
teardown and a NULL dereference in the Marvell NFC UART driver that the
same change surfaces.

nci_uart_tty_close() frees the tx skbs and purges the tx queue before it
cancels the write worker, while the NCI device is still registered. The
worker can therefore be re-queued -- by a tty hangup, or by the NCI core
still sending through the driver -- and run against freed memory. The
fix follows the Bluetooth hci_uart ldisc: gate the worker on a readiness
bit under a percpu_rwsem and drain it under the write lock on close.

Enabling the worker that way means it must be enabled before the device
is registered, since the Marvell driver may transmit (firmware download)
from within registration. That exposes a pre-existing NULL dereference:
nfcmrvl publishes nu->drv_data only after nfcmrvl_nci_register_dev()
returns, so a transmit during registration reaches
nfcmrvl_nci_uart_tx_start() with a NULL nu->drv_data.

1/2 nfcmrvl: publish nu->drv_data before nci_register_device(), so a
transmit during registration does not hit a NULL nu->drv_data.
2/2 nci: uart: the teardown use-after-free fix; NCI_UART_READY and the
module reference are taken before ops.open(), with shared error
labels and the tx_wakeup trylock comment aligned with hci_uart.

Both are runtime-tested together under KASAN: the unfixed tree crashes
within the first iterations (slab-use-after-free in nci_uart_write_work),
the series survives 56000+ register/hangup iterations cleanly.

Shubham Antil (2):
nfc: nfcmrvl: set drv_data before registering the nci device
nfc: nci: uart: fix use-after-free of write_work on ldisc teardown

drivers/nfc/nfcmrvl/main.c | 17 ++++++++
drivers/nfc/nfcmrvl/uart.c | 3 --
include/net/nfc/nci_core.h | 2 +
net/nfc/nci/uart.c | 80 +++++++++++++++++++++++++++++++-------
4 files changed, 85 insertions(+), 17 deletions(-)

--
2.43.0