Skip to content

Commit 4527025

Browse files
committed
nfc: nci: fix circular locking dependency in nci_close_device
nci_close_device() flushes rx_wq and tx_wq while holding req_lock. This causes a circular locking dependency because nci_rx_work() running on rx_wq can end up taking req_lock too: nci_rx_work -> nci_rx_data_packet -> nci_data_exchange_complete -> __sk_destruct -> rawsock_destruct -> nfc_deactivate_target -> nci_deactivate_target -> nci_request -> mutex_lock(&ndev->req_lock) Move the flush of rx_wq after req_lock has been released. This should safe (I think) because NCI_UP has already been cleared and the transport is closed, so the work will see it and return -ENETDOWN. NIPA has been hitting this running the nci selftest with a debug kernel on roughly 4% of the runs. Fixes: 6a2968a ("NFC: basic NCI protocol implementation") Reviewed-by: Ian Ray <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 57ce3b2 commit 4527025

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

net/nfc/nci/core.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ static int nci_close_device(struct nci_dev *ndev)
579579
skb_queue_purge(&ndev->rx_q);
580580
skb_queue_purge(&ndev->tx_q);
581581

582-
/* Flush RX and TX wq */
583-
flush_workqueue(ndev->rx_wq);
582+
/* Flush TX wq, RX wq flush can't be under the lock */
584583
flush_workqueue(ndev->tx_wq);
585584

586585
/* Reset device */
@@ -592,13 +591,13 @@ static int nci_close_device(struct nci_dev *ndev)
592591
msecs_to_jiffies(NCI_RESET_TIMEOUT));
593592

594593
/* After this point our queues are empty
595-
* and no works are scheduled.
594+
* rx work may be running but will see that NCI_UP was cleared
596595
*/
597596
ndev->ops->close(ndev);
598597

599598
clear_bit(NCI_INIT, &ndev->flags);
600599

601-
/* Flush cmd wq */
600+
/* Flush cmd and tx wq */
602601
flush_workqueue(ndev->cmd_wq);
603602

604603
timer_delete_sync(&ndev->cmd_timer);
@@ -613,6 +612,9 @@ static int nci_close_device(struct nci_dev *ndev)
613612

614613
mutex_unlock(&ndev->req_lock);
615614

615+
/* rx_work may take req_lock via nci_deactivate_target */
616+
flush_workqueue(ndev->rx_wq);
617+
616618
return 0;
617619
}
618620

0 commit comments

Comments
 (0)