nfc_hci_msg_tx_work() hands each frame to nfc_llc_xmit_from_hci() and
only frees it if that fails: on success the LLC engine owns it. SHDLC
queues the frame and frees it once it is acked, but LLC nop passes it
straight to the driver's xmit, and the phy write operations of its
users (the MEI phy of pn544 and microread) copy the data out and leave
the skb alone, so every frame sent to the controller is leaked.
This was found by LLM-assisted code review and confirmed with a
test-only module that registers st21nfca with LLC nop on a virtual phy
and a userspace controller emulator: 20 device up/down cycles leaked
598 skbuff_head_cache objects, and none with this patch.
Free the frame in llc_nop_xmit_from_hci() once the driver has sent it.
Fixes: 8af00d48dc92 ("NFC: Add a nop (passthrough) llc module to llc core")
Cc: <redacted>
Signed-off-by: Joas Antonio dos Santos <redacted>
Assisted-by: Yaga Agent HackerSec Claude:claude-opus-5-5
---
net/nfc/hci/llc_nop.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/net/nfc/hci/llc_nop.c b/net/nfc/hci/llc_nop.c
index f9c826a13..1603e435b 100644
--- a/net/nfc/hci/llc_nop.c
+++ b/net/nfc/hci/llc_nop.c
@@ -67,8 +67,17 @@ static void llc_nop_rcv_from_drv(struct nfc_llc *llc, struct sk_buff *skb)
static int llc_nop_xmit_from_hci(struct nfc_llc *llc, struct sk_buff *skb)
{
struct llc_nop *llc_nop = nfc_llc_get_data(llc);
+ int r;
- return llc_nop->xmit_to_drv(llc_nop->hdev, skb);
+ /* The driver does not take ownership of the frame (the phy write
+ * operations copy it out), and nfc_hci_msg_tx_work() only frees it
+ * on error, so it is ours to free once it has been sent.
+ */
+ r = llc_nop->xmit_to_drv(llc_nop->hdev, skb);
+ if (r == 0)
+ consume_skb(skb);
+
+ return r;
}
static const struct nfc_llc_ops llc_nop_ops = {--
2.43.0