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=1796554338; b=TmFTIVyR6A3PdvTyiO6z9cqvaCcjpuzZmWfHfdPXxAHTn4j17hAtdSVJxXnO5fdfKwnj PpDR7QHIsTjiLb/Ruxqi14lTrvEufTFrL8hYPfdNFIlpqwdZsJoXXsZ/K6LwgOIsVMe3O JhMQLFzm+3W3nsyTKi7BYQRgjzis25QXhvVc0iAQE1J7DgfEh0pYZi5mVyezESBTwgPVM qWOa8hdSQ6zklYpXk9FDNXJ81ZX/jwFf76dKysbvlXGJRR7W3RUv2WJ619LduLXFIVoBR ZXmzU0nTVYvoHm23gZyf/OzQe0ElF7nI5CiATN9cyEbHYobcJXIsXhgffUc/xa6tB+A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796554338; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: MIME-Version:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=utUXguI5MLxza2P8VVfhhQRiJGGgUfOYtFWZ39D0Si0=; b=32SHjzA09woUG0o6DInVzoEMTo/76gP+ZmAftXlT2S6ts5ymCSOaIg1JZ2lRQzS2LNUl eAJWKRHcmD5Y7H/YCemTEukqm40ruKMBKnvA+iiFb2FWXbtoOEXCXu1CAnrStnNodmcsP Uui4ame2XjdYVK6aI+nd2kRW6xDYuW7DJZGfTJD6GIRdOJuoNx3cxvLEhxndVMIUTF673 tSZibliw7umC0hoei2ZCyX0fCCIWvsxZrelxhPqD8z7WujhhiSPQySBHwLERt5pCC9chp qpCOyFP1j2q6tvoXglgJQxkXeEu/nabLpB8Io1EU+iX56mr3++p6K6dYqUouQcCQm1g== 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=Ej1aruda; 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 C6715606A339; Sun, 6 Dec 2026 10:52:18 +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=Ej1aruda 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=1796554338; b=iy8j+4rdHxjmW1WHQfkoNvBTBTcuRNXBwBVqb2f7xhvAbSXN84bClSpCHh8hrgikPVfC M/cQ4zSkFY8y7P76CaRcY/atQGMLpm2s02S1eUB7KHzeat/xmVFMaT51r+rRl0KsvL0HB 7jog0vgZ4edFQYmvx2RVKbbWoddIOVno8BmbuRTW5Oc+TWlqYLPzY4bhMUJFhILbPrBLO keT/jqQQXuQNHKdrpMWcM53ZY90J6sK3sxa77BcfhyIB86/oCpgYmwywQRPSEAkMDHoKK h/S6bxiTlGzwExNLcFobb7Q+g3ImoGEzz3yBNGZl7PWq7im4P1QBBxiMABSvsxuubWA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796554338; h=DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: MIME-Version:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=utUXguI5MLxza2P8VVfhhQRiJGGgUfOYtFWZ39D0Si0=; b=zi9nNNQMsC0MGzKcy0ae59ZJiwCjelRHoXc3YixhRX5MS8miLvA61+JFMcMPIVqRepaR WEEDCxDfqwKZIcrM0lPYUGX+2xSFFt56OhVp4hBYJfs0GQB85NEvHolFvtufiEkOibJW5 5Qv0F6v/qO30xQOG59KaXDN7xQqUaWugYIXvTTVPyRfEZu6EhyyOPHH/2i82xPXAPip/+ nWILblmewo1CLJiUYGjDfLjNInTYCMaG0H5WLN9fvtg1rpMpF/Eo2wqwrPzeFs3JMyF+j CLTeAlAjxHOEMTcdfd+Qrh9bRm3rbZBwyLaIaAE1bHZ476Pchbf1E1Nh+mlsPkjNEOw== 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 538C31F00A12; Sun, 6 Dec 2026 10:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796554338; bh=utUXguI5MLxza2P8VVfhhQRiJGGgUfOYtFWZ39D0Si0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=Ej1arudaPdpzIn6bdfJPyYIjNN5fAiL4sN3utnqFE0r9Yy766DfZFWdxRjTCssanB 8w6//030S6FciT0bhE9U9ZzqmKJhdpw9mCRKSZSy9Eq+VHxVvtyW0c/eI7M5u1na4G ZIX4gynlohhBKfmXhsI5JaRwNPNE3lkh7q+qOQCMxAxId1DsfVXp9oT13soOff3Xd7 3uUw49gIyTlbf+xIgu4ADaP2kkFPmEUyYIZp8y3KnA/N1gvROO2JZVFi0trCyufohK Hm2KIh8oEGHmnNBZPNUmDwFTczEfbIfzGQxXn0KuQOVFX9PmS3zp87dJZz+uwGPIq9 r+S8aPrt+//zg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id D97745071F; Sun, 6 Dec 2026 10:52:16 +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 v3 1/3] nfc: llcp: fix work and timer teardown order in local_cleanup() Date: Sun, 06 Dec 2026 10:52:15 -0000 Message-ID: <20261206105215.479-2-luob87709@gmail.com> In-Reply-To: <20261206105215.479-1-luob87709@gmail.com> References: <20261206105215.479-1-luob87709@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailing-List: linux-kernel@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=1796554335; l=3162; i=luob87709@gmail.com; h=from:subject:message-id; bh=MgpPNH4ogi6cexPWFH7C7z6SZW/cygGWIPRNok1UxJQ=; b=r+aRU9jXURDbuMazvEYG9wQREP2WFyS9/WmryYXgcNpHj4PXEjeUjAIViH92rK7XCEYTj0utf 9O0MZomrESACIjfmVmA6UO8Bbpyq95bjZpnE1VOTvvAPE79aWfKZvP1 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 Reply-To: luob87709@gmail.com From: Bin Luo 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. 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: d646960f7986 ("NFC: Initial LLCP support") Fixes: 40213fa8513c ("NFC: llcp: Add cleanup support for unreplied SNL requests") Cc: stable@vger.kernel.org Signed-off-by: Bin Luo --- Changes in v3: - Fix first Fixes tag to d646960f7986 ("NFC: Initial LLCP support"). - Normalize From:/Signed-off-by: author metadata. Changes in v2: - Resend cleanly via b4 web relay 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