Skip to contentSkip to conversation

nfc: nfcmrvl: fix null pointer dereference in nfcmrvl_bulk_complete

PATCH In review Joshua Crofts 1 participant 2 messages Aug 31 – Sep 8 NFC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfc: nfcmrvl: fix null pointer dereference in nfcmrvl_bulk_complete

A race condition in the current implementation can cause a null pointer dereference. When nfcmrvl_nci_register_dev() calls nci_register_device(), the NCI device is immediately exposed to userspace. If userspace brings up the device before probe() finishes assigning drv_data->priv, submitted bulk URBs can complete while priv is still NULL.

Additionally, nfcmrvl_bulk_complete() incorrectly checked NFCMRVL_NCI_RUNNING on drv_data->flags instead of drv_data->priv->flags.

Fix this by adding a NULL check and testing NFCMRVL_NCI_RUNNING on drv_data->priv->flags before processing the completed URB.

Fixes f26e30cc6b50 ("NFC: nfcmrvl: Initial commit for Marvell NFC driver")
Reported-by [email protected]
---
 drivers/nfc/nfcmrvl/usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/nfcmrvl/usb.c +1 -1
index c7f2afe00b93..c22d783718fe 100644
@@ -61,7 +61,7 @@ static void nfcmrvl_bulk_complete(struct urb *urb)
 	dev_dbg(&drv_data->udev->dev, "urb %p status %d count %d\n",
 		urb, urb->status, urb->actual_length);
 
-	if (!test_bit(NFCMRVL_NCI_RUNNING, &drv_data->flags))
+	if (!drv_data->priv || !test_bit(NFCMRVL_NCI_RUNNING, &drv_data->priv->flags))
 		return;
 
 	if (!urb->status) {
Signature · 1 line
2.47.3
#1 lore raw
Quoted 26 lines · On Mon, 31 Aug 2026 10:41:10 +0000 Joshua Crofts <[email protected]>…

A race condition in the current implementation can cause a null pointer dereference. When nfcmrvl_nci_register_dev() calls nci_register_device(), the NCI device is immediately exposed to userspace. If userspace brings up the device before probe() finishes assigning drv_data->priv, submitted bulk URBs can complete while priv is still NULL.

Additionally, nfcmrvl_bulk_complete() incorrectly checked NFCMRVL_NCI_RUNNING on drv_data->flags instead of drv_data->priv->flags.

Fix this by adding a NULL check and testing NFCMRVL_NCI_RUNNING on drv_data->priv->flags before processing the completed URB.

Fixes f26e30cc6b50 ("NFC: nfcmrvl: Initial commit for Marvell NFC driver")
Reported-by [email protected]
---
 drivers/nfc/nfcmrvl/usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/nfcmrvl/usb.c +0 -0
index c7f2afe00b93..c22d783718fe 100644

drivers/nfc/nfcmrvl/usb.c static void nfcmrvl_bulk_complete(struct urb *urb) · line 67

Quoted 8 lines
drivers/nfc/nfcmrvl/usb.c +1 -1
@@ -61,7 +61,7 @@ static void nfcmrvl_bulk_complete(struct urb *urb)
 	dev_dbg(&drv_data->udev->dev, "urb %p status %d count %d\n",
 		urb, urb->status, urb->actual_length);
 
-	if (!test_bit(NFCMRVL_NCI_RUNNING, &drv_data->flags))
+	if (!drv_data->priv || !test_bit(NFCMRVL_NCI_RUNNING, &drv_data->priv->flags))
 		return;
 
 	if (!urb->status) {

Hi David,

gentle ping on this patch.

Signature · 2 lines
Kind regards,
Joshua Crofts