From: Bin Luo (University of Electronic Science and Technology of China) <luob…@gmail.com> 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: stab…@vger.kernel.org Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob…@gmail.com> --- 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