Skip to content

Commit 6608358

Browse files
committed
nfc: nci: complete pending data exchange on device close
In nci_close_device(), complete any pending data exchange before closing. The data exchange callback (e.g. rawsock_data_exchange_complete) holds a socket reference. NIPA occasionally hits this leak: unreferenced object 0xff1100000f435000 (size 2048): comm "nci_dev", pid 3954, jiffies 4295441245 hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 27 00 01 40 00 00 00 00 00 00 00 00 00 00 00 00 '..@............ backtrace (crc ec2b3c5): __kmalloc_noprof+0x4db/0x730 sk_prot_alloc.isra.0+0xe4/0x1d0 sk_alloc+0x36/0x760 rawsock_create+0xd1/0x540 nfc_sock_create+0x11f/0x280 __sock_create+0x22d/0x630 __sys_socket+0x115/0x1d0 __x64_sys_socket+0x72/0xd0 do_syscall_64+0x117/0xfc0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 Fixes: 38f04c6 ("NFC: protect nci_data_exchange transactions") Reviewed-by: Joe Damato <joe@dama.to> Link: https://patch.msgid.link/20260303162346.2071888-4-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent d42449d commit 6608358

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

net/nfc/nci/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ static int nci_close_device(struct nci_dev *ndev)
567567
flush_workqueue(ndev->cmd_wq);
568568
timer_delete_sync(&ndev->cmd_timer);
569569
timer_delete_sync(&ndev->data_timer);
570+
if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
571+
nci_data_exchange_complete(ndev, NULL,
572+
ndev->cur_conn_id,
573+
-ENODEV);
570574
mutex_unlock(&ndev->req_lock);
571575
return 0;
572576
}
@@ -598,6 +602,11 @@ static int nci_close_device(struct nci_dev *ndev)
598602
flush_workqueue(ndev->cmd_wq);
599603

600604
timer_delete_sync(&ndev->cmd_timer);
605+
timer_delete_sync(&ndev->data_timer);
606+
607+
if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
608+
nci_data_exchange_complete(ndev, NULL, ndev->cur_conn_id,
609+
-ENODEV);
601610

602611
/* Clear flags except NCI_UNREG */
603612
ndev->flags &= BIT(NCI_UNREG);

0 commit comments

Comments
 (0)