[PATCH] nfc: st-nci: Free received NDLC supervisor frames

From: raoxu

Date: Thu Nov 12 2026 - 08:10:04 EST


From: Xu Rao <raoxu@xxxxxxxxxxxxx>

llt_ndlc_rcv_queue() dequeues each received skb and handles supervisor
frames locally. The ACK, NACK and WAIT cases neither release that RX skb
nor transfer ownership to another queue. ACK also overwrites the RX skb
pointer with the TX skb dequeued from ack_pending_q and frees only the
latter.

Consequently, normal acknowledged traffic leaks one received skb per ACK,
and NACK or WAIT responses leak their receive buffers as well. The leaked
buffers are no longer on rcv_q, so device removal cannot reclaim them.
Unknown supervisor codes already release their RX skb, and data frames
transfer ownership to the NCI core.

Use a separate pointer for the acknowledged TX skb and free the RX skb
after the supervisor switch. Move the existing default-case free to this
common path so every supervisor frame is released exactly once, without
changing acknowledgment, retransmission or timer handling.

Fixes: 35630df68d60 ("NFC: st21nfcb: Add driver for STMicroelectronics ST21NFCB NFC chip")
Signed-off-by: Xu Rao <raoxu@xxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
drivers/nfc/st-nci/ndlc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nfc/st-nci/ndlc.c b/drivers/nfc/st-nci/ndlc.c
index be4808859cfa..7164e7c3aabd 100644
--- a/drivers/nfc/st-nci/ndlc.c
+++ b/drivers/nfc/st-nci/ndlc.c
@@ -146,7 +146,7 @@ static void llt_ndlc_requeue_data_pending(struct llt_ndlc *ndlc)

static void llt_ndlc_rcv_queue(struct llt_ndlc *ndlc)
{
- struct sk_buff *skb;
+ struct sk_buff *skb, *pending_skb;
u8 pcb;
unsigned long time_sent;

@@ -159,8 +159,8 @@ static void llt_ndlc_rcv_queue(struct llt_ndlc *ndlc)
if ((pcb & PCB_TYPE_MASK) == PCB_TYPE_SUPERVISOR) {
switch (pcb & PCB_SYNC_MASK) {
case PCB_SYNC_ACK:
- skb = skb_dequeue(&ndlc->ack_pending_q);
- kfree_skb(skb);
+ pending_skb = skb_dequeue(&ndlc->ack_pending_q);
+ kfree_skb(pending_skb);
timer_delete_sync(&ndlc->t1_timer);
timer_delete_sync(&ndlc->t2_timer);
ndlc->t2_active = false;
@@ -182,9 +182,9 @@ static void llt_ndlc_rcv_queue(struct llt_ndlc *ndlc)
msecs_to_jiffies(NDLC_TIMER_T1_WAIT));
break;
default:
- kfree_skb(skb);
break;
}
+ kfree_skb(skb);
} else if ((pcb & PCB_TYPE_MASK) == PCB_TYPE_DATAFRAME) {
nci_recv_frame(ndlc->ndev, skb);
} else {
--
2.50.1