From: "Bin Luo (University of Electronic Science and Technology of China)" <luob…@gmail.com> rawsock_destruct() currently calls nfc_deactivate_target(), which acquires device_lock(&dev->dev) and, for NCI devices, invokes nci_request(ndev, nci_rf_deactivate_req, ..., NCI_RF_DEACTIVATE_TIMEOUT) to synchronously wait up to 30 seconds for an RF_DEACTIVATE_RSP/NTF exchange processed on ndev->rx_wq. When rawsock_release() drops its reference while an nfc_data_exchange() is still in flight, rawsock_data_exchange_complete() drops the final socket reference directly from ndev->rx_wq (inside nci_rx_work()). That invokes rawsock_destruct() -> nfc_deactivate_target() -> nci_request() on ndev->rx_wq itself, causing ndev->rx_wq to block for the full 30-second NCI_RF_DEACTIVATE_TIMEOUT waiting on a response that only ndev->rx_wq can process: nci: __nci_request: wait_for_completion_interruptible_timeout failed 0 Move nfc_deactivate_target() into rawsock_release() (process context, after cancelling tx_work) so deactivation never runs inside sk_destruct from an asynchronous completion context. Keep nfc_put_device() in rawsock_destruct() so the nfc_dev reference stays valid until any in-flight completion drops its socket reference. Discovered by AI-assisted code review and reproduced in QEMU KVM on an unmodified kernel using /dev/virtual_nci without delay injection (an AF_NFC SOCK_SEQPACKET socket sends one frame and closes concurrently with the NCI data response). Tested against the reproducer across 3 x 200 iterations in QEMU KVM (KASAN, LOCKDEP, DEBUG_OBJECTS) with zero timeouts, and against tools/testing/selftests/nci/nci_dev (8/8 passed). Fixes: 23b7869c0fd0 ("NFC: add the NFC socket raw protocol") Cc: stab…@vger.kernel.org Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob…@gmail.com> --- Changes in v2: - Resend cleanly via b4 web relay (v1 patch was line-wrapped by Gmail) and include both dependent rawsock patches as a threaded series. net/nfc/rawsock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c index 291f509..e2a9a2b 100644 --- a/net/nfc/rawsock.c +++ b/net/nfc/rawsock.c @@ -78,6 +78,10 @@ static int rawsock_release(struct socket *sock) __rawsock_write_queue_purge(sk); spin_unlock_bh(&sk->sk_write_queue.lock); cancel_work_sync(&nfc_rawsock(sk)->tx_work); + + nfc_deactivate_target(nfc_rawsock(sk)->dev, + nfc_rawsock(sk)->target_idx, + NFC_TARGET_MODE_IDLE); } sock_orphan(sk); @@ -332,12 +336,8 @@ static void rawsock_destruct(struct sock *sk) { pr_debug("sk=%p\n", sk); - if (sk->sk_state == TCP_ESTABLISHED) { - nfc_deactivate_target(nfc_rawsock(sk)->dev, - nfc_rawsock(sk)->target_idx, - NFC_TARGET_MODE_IDLE); + if (sk->sk_state == TCP_ESTABLISHED) nfc_put_device(nfc_rawsock(sk)->dev); - } skb_queue_purge(&sk->sk_receive_queue);
-- 2.43.0