From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796364420; b=VnNXDcdjrm5qbyIJjf7GnJQXAHZgg4J8FuBThYFhVJceZsQLpgHQ9BpPUlbZSh5TOu/3 Y6i03rRNu2LjdGGFsoJMt78BHK66AUWfhxEi0FGr005TxKnchJZs7dZyAg5G2JEJLdscR iiUpu4gmHm7B+/qKlzYhlqoDQgWk9vp0jR2uNORZ12tqOUYuXDKjxj4VTaeTTyx5jEtLJ I/1IROA561ktHxHVDx4p7TMrpvWBt/jDspjf3zTmW5XyEYBX9TjuYk7i9mzUUnygpJryY k3+1zQos3z9WQAbunea6ttXqdlEFDxANNgVYloePNAwwZvT3X2g06kIUqOLNlofgFwQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364420; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:MIME-Version:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=4ziHQweia89o63HYuzZPmRIKEYctsq8wsfokkcnhmzo=; b=Z9DHY+NXvVHFz3FeMatfbKcxfKe3lb+CG6n/8YhWAO0VtUpgmlRRX6/GwHNsBH8T0Djq O/CqeUueLBHqMsBfDUcRBypeY2/rUw+v3w3A1KQrMOLX+Q+dy71URulKQUA3N2sFDd4AL ossTV237mRDPzBlSl/PW9idH6Qk2j+RNgiDIhU8KlU/ykrq7ZI+I2jTXhxxFwEV3o4l3I F6ah8sGJDWzObLf+Iz4gxAvhhDhV3UuXmaBeSWoJFQjzVp2xGu2AC7dFUKIhKoXwpE0s1 zkfNuaRxzXsbSHuQqOUgMsaC+O6lfU9fOm1D8AM62pMIFvt8DUcus6ybPRUCzN3GGNA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hMvinVfm; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C573B60A3837; Fri, 4 Dec 2026 06:07:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hMvinVfm Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796364420; b=SfX5jn09nlYM595bNXbeqCQSEO0Dc/KyWT07Yj5AY+tGFbYgsID6hZ2PKY490ffVAlXp WsbElpK9TGANp3nw2dD82KsqbBczctjuG+U+Mfqru3Ufob6srUbpKoz/ejrKf4hu1rMyq Ap3Btd+IQuU6l7sJeBYXBfV7wc2Kh0ThqCyZtomKJz4Rn/maXzrtTpbi3f88JR+Fw4vps Xr0rTv9+xBzS8i4F7dj8dPdEiY/pKNQD8ue5jo7mlntiGs570QSZGYuEtbuIjMhT+WaV5 GalTTyy+rUZ5UcYW0kGwEfv06gEBVcJoyn1xqdLuBhjs/9oELFWv3j2je59lU/lyDHw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796364420; h=DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:MIME-Version:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=4ziHQweia89o63HYuzZPmRIKEYctsq8wsfokkcnhmzo=; b=HLs7iXoDk3EqtehPXeA7/53+PaAwe5Mkb+3xPOg5s1HpeQAUxnb13R15cRKihSRbm3Iv mQ8fBqB4z6TGagmrjo2lXrfSaokBPjWxET0KCFZxzYj75X8PBzJxQkDa15LGcJ/R0sN6R G7k6NKZ0HetOvcD15n8kb2T/RLaM0Jb6u5DybLXCrmkfSW5cOluLsd3AXHyWetW/jDP8l 2FswwRwCOXwOJLv2rVcXwC6nS5UIFySnE2P05jjrJHmc0q1ckB7ZE2oc+OQYOD6JdWoWe /FzyhtBFJ5taTIrRofHBWbnNYUMQiHMuBiO6vF7nu/bEaqOTKsie9F1l8Pma2kbm7og== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 9AC811F00A0C; Fri, 4 Dec 2026 06:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796364420; bh=4ziHQweia89o63HYuzZPmRIKEYctsq8wsfokkcnhmzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=hMvinVfm9hQ/UJzWiI6jjWgY9p0dCgHxYsWnYb0/uim64vJtlhBg7KGvBSIswuUVN BHF0uboUD2adTbglf6Cgss1L79myag+Tx6iaOTSkP0JmqoDnyf8lECpCFW/cJPyqVz j1isokrkPX/xsHci+xaCGy5iOoxtqMn3dWJj/a4mFM5IavFLyL4fwmzDG4nflLxQH2 t6ih0DNCGubNy5KV+qFUezAXeDqBt6Bc4vrs+gPHRHwWo4tb5dAjHFARQ4PExx1N1w qk6iDYiGg6Y+2e6bK4XqcuoJt1KZZsroRjoKuZRHIWxMu5WrRCC/PYp9eHwiSTIgMC RiPOGZ27FJPug== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 306E24D949; Fri, 4 Dec 2026 06:06:59 +0000 (UTC) From: Bin Luo via B4 Relay To: David Heidelberg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: Krzysztof Kozlowski , oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH net v2 1/3] nfc: llcp: fix work and timer teardown order in local_cleanup() Date: Fri, 04 Dec 2026 14:06:57 +0800 Message-ID: <20261204060656.503-2-luob87709@gmail.com> In-Reply-To: <20261204060656.503-1-luob87709@gmail.com> References: <20261204060656.503-1-luob87709@gmail.com> Content-Type: text/plain; charset="utf-8" X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796364416; l=3278; i=luob87709@gmail.com; h=from:subject:message-id; bh=ZLZsHjgUOmRAroXpyM8Oszbb/I4R1G8ceQRsyOuF3Cc=; b=+PJptIMl3TRooEd6KDFH7WyQhjyQyCtKwUMqzBugoomJebOtihCD9ZR7d85Kte8lt+BgWc3b6 Iirz1UDLMeSBar8G+x4nnfm5rzPI/gze33vaHcpoLT02KRco3CfdV2f X-Developer-Key: i=luob87709@gmail.com; a=ed25519; pk=qac/JyfPpjPD91IsbcZY5AvHG2LdM5meIPeVzh4kuN0= X-Endpoint-Received: by B4 Relay for luob87709@gmail.com/default with auth_id=1739 X-Original-From: "Bin Luo (University of Electronic Science and Technology of China)" Reply-To: luob87709@gmail.com Content-Transfer-Encoding: 7bit From: "Bin Luo (University of Electronic Science and Technology of China)" In net/nfc/llcp_core.c, the LLCP worker and timer dependency chains are: 1. rx_work -> schedules tx_work -> arms link_timer -> schedules timeout_work 2. sdreq_timer <-> sdreq_timeout_work (mutually re-arming when pending_sdreqs is non-empty) However, local_cleanup() currently deletes link_timer before cancelling tx_work, purges tx_queue before cancelling tx_work (which can put an skb back via skb_queue_head() when !llcp_sock->remote_ready), and cancels tx_work before cancelling rx_work. Likewise, it calls timer_delete_sync(&local->sdreq_timer) before cancelling sdreq_timeout_work, which can re-arm sdreq_timer via mod_timer(). As a result, an in-flight rx_work can re-queue tx_work after cancel_work_sync(&local->tx_work), tx_work can re-arm link_timer after timer_delete_sync(&local->link_timer) or leave a re-queued skb in tx_queue, and sdreq_timeout_work can re-arm sdreq_timer after timer_delete_sync(&local->sdreq_timer), leaving active works, timers, or leaked skbs on struct nfc_llcp_local when local_release_work() frees it. Tear down the work items and timers in producer-to-consumer order using disable_work_sync() and timer_shutdown_sync(), which permanently prevent re-queuing and re-arming once local_cleanup() begins, and purge tx_queue after tx_work is disabled. Discovered by static analysis and AI-assisted code review; not triggered standalone without delay injection, and regression-tested in QEMU KVM (KASAN, LOCKDEP, DEBUG_OBJECTS_TIMERS, DEBUG_OBJECTS_WORK) across 200 nfcsim module load/unload cycles with active LLCP links and against tools/testing/selftests/nci/nci_dev (8/8 passed). Fixes: c7aa12252f51 ("NFC: Take a reference on the LLCP local pointer when creating a socket") Fixes: 40213fa8513c ("NFC: llcp: Add cleanup support for unreplied SNL requests") Cc: stable@vger.kernel.org Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) --- Changes in v2: - Resend cleanly via b4 web relay (v1 patch was line-wrapped by Gmail) and include all three NFC teardown fixes as a threaded series. net/nfc/llcp_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index 74bf817..32530a2 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -173,15 +173,15 @@ static struct nfc_llcp_local *nfc_llcp_local_get(struct nfc_llcp_local *local) static void local_cleanup(struct nfc_llcp_local *local) { nfc_llcp_socket_release(local, false, ENXIO); - timer_delete_sync(&local->link_timer); + disable_work_sync(&local->rx_work); + disable_work_sync(&local->tx_work); skb_queue_purge(&local->tx_queue); - cancel_work_sync(&local->tx_work); - cancel_work_sync(&local->rx_work); - cancel_work_sync(&local->timeout_work); + timer_shutdown_sync(&local->link_timer); + disable_work_sync(&local->timeout_work); kfree_skb(local->rx_pending); local->rx_pending = NULL; - timer_delete_sync(&local->sdreq_timer); - cancel_work_sync(&local->sdreq_timeout_work); + timer_shutdown_sync(&local->sdreq_timer); + disable_work_sync(&local->sdreq_timeout_work); nfc_llcp_free_sdp_tlv_list(&local->pending_sdreqs); } -- 2.43.0