Netdev List
 help / color / mirror / Atom feed
From: Bin Luo via B4 Relay <devnull+luob87709.gmail.com@kernel.org>
To: David Heidelberg <david@ixit.cz>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,  Simon Horman <horms@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
	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	[thread overview]
Message-ID: <20261204060656.503-2-luob87709@gmail.com> (raw)
In-Reply-To: <20261204060656.503-1-luob87709@gmail.com>

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




  reply	other threads:[~2026-12-04  6:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  6:06 [PATCH net v2 0/3] nfc: fix LLCP, nfcsim, and digital device teardown ordering Bin Luo via B4 Relay
2026-12-04  6:06 ` Bin Luo via B4 Relay [this message]
2026-12-04  6:06 ` [PATCH net v2 2/3] nfc: nfcsim: stop link and works before unregistering digital device Bin Luo via B4 Relay
2026-12-04  6:06 ` [PATCH net v2 3/3] nfc: digital: stop works and drain commands before nfc_remove_device() Bin Luo via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204060656.503-2-luob87709@gmail.com \
    --to=devnull+luob87709.gmail.com@kernel.org \
    --cc=davem@davemloft.net \
    --cc=david@ixit.cz \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=krzk@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luob87709@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=oe-linux-nfc@lists.linux.dev \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox