From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
To: oe-linux-nfc@lists.linux.dev
Cc: johan@kernel.org, david@ixit.cz, kuba@kernel.org,
netdev@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v5 4/5] nfc: nci: drop stale rx_data_reassembly on errors, timeout, and close
Date: Fri, 27 Nov 2026 21:40:28 +0800 [thread overview]
Message-ID: <20261127134029.1813-5-luob87709@gmail.com> (raw)
In-Reply-To: <20261127134029.1813-1-luob87709@gmail.com>
When an NCI data exchange receives a partial NCI_PBF_CONT fragment into
ndev->rx_data_reassembly and then terminates due to a data-status error,
CORE_INTERFACE_ERROR_NTF, data-exchange timeout, or device close, the
buffered fragment is left behind. On subsequent packets or after a
close/reopen cycle (including listen/target mode, where
NCI_DATA_EXCHANGE is never set), stale bytes are prepended to later
responses or leaked until device free.
Drop and clear ndev->rx_data_reassembly on all four paths:
- In nci_add_rx_data_frag() when a nonzero data status is received.
- Unconditionally in nci_core_conn_intf_error_ntf_packet() before the
NCI_DATA_EXCHANGE check, matching nci_rf_deactivate_ntf_packet() so
target mode is covered too.
- In nci_rx_work() when handling a data-exchange timeout.
- In nci_close_device() after flush_workqueue(ndev->rx_wq) on both
close paths, guarded by req_lock and !NCI_UP.
Found by static call-chain audit and code inspection.
Fixes: 6a2968aaf50c ("NFC: basic NCI protocol implementation")
Fixes: 004161cb52ac ("NFC: Handle error during NCI data exchange")
Fixes: c4bf98b220cb ("NFC: Add NCI data exchange timer")
Fixes: 98ff416f97c5 ("NFC: nci: Add status byte management in case of error.")
Cc: stable@vger.kernel.org
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
net/nfc/nci/core.c | 15 +++++++++++++--
net/nfc/nci/data.c | 2 ++
net/nfc/nci/ntf.c | 4 ++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index efd4e5e..f832251 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -582,7 +582,7 @@ static int nci_close_device(struct nci_dev *ndev)
ndev->cur_conn_id,
-ENODEV);
mutex_unlock(&ndev->req_lock);
- return 0;
+ goto flush_rx;
}
/* Drop RX and TX queues */
@@ -622,9 +622,17 @@ static int nci_close_device(struct nci_dev *ndev)
mutex_unlock(&ndev->req_lock);
+flush_rx:
/* rx_work may take req_lock via nci_deactivate_target */
flush_workqueue(ndev->rx_wq);
+ mutex_lock(&ndev->req_lock);
+ if (!test_bit(NCI_UP, &ndev->flags)) {
+ kfree_skb(ndev->rx_data_reassembly);
+ ndev->rx_data_reassembly = NULL;
+ }
+ mutex_unlock(&ndev->req_lock);
+
return 0;
}
@@ -1607,10 +1615,13 @@ static void nci_rx_work(struct work_struct *work)
/* check if a data exchange timeout has occurred */
if (test_bit(NCI_DATA_EXCHANGE_TO, &ndev->flags)) {
/* complete the data exchange transaction, if exists */
- if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
+ if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags)) {
+ kfree_skb(ndev->rx_data_reassembly);
+ ndev->rx_data_reassembly = NULL;
nci_data_exchange_complete(ndev, NULL,
ndev->cur_conn_id,
-ETIMEDOUT);
+ }
clear_bit(NCI_DATA_EXCHANGE_TO, &ndev->flags);
}
diff --git a/net/nfc/nci/data.c b/net/nfc/nci/data.c
index 4253ede..3bbebb9 100644
--- a/net/nfc/nci/data.c
+++ b/net/nfc/nci/data.c
@@ -220,6 +220,8 @@ static void nci_add_rx_data_frag(struct nci_dev *ndev,
if (status) {
err = status;
+ kfree_skb(ndev->rx_data_reassembly);
+ ndev->rx_data_reassembly = NULL;
goto exit;
}
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index f5c9a8a..3ca1009 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -132,6 +132,10 @@ static int nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev,
pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id);
+ /* drop partial rx data packet */
+ kfree_skb(ndev->rx_data_reassembly);
+ ndev->rx_data_reassembly = NULL;
+
/* complete the data exchange transaction, if exists */
if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
nci_data_exchange_complete(ndev, NULL, ntf->conn_id, -EIO);
--
2.51.0.windows.1
next prev parent reply other threads:[~2026-11-27 13:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 13:40 [PATCH v5 0/5] net/nfc: fix skb ownership, reassembly cleanup, and NCI status errors Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:40 ` [PATCH v5 1/5] net/nfc: fix skb ownership on data exchange errors Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:40 ` [PATCH v5 2/5] nfc: pn533: clear resp after queueing to avoid double free Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:40 ` [PATCH v5 3/5] nfc: digital: complete DEP data exchange on terminal errors Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 13:40 ` Bin Luo (University of Electronic Science and Technology of China) [this message]
2026-11-27 13:40 ` [PATCH v5 5/5] nfc: preserve NCI data status error codes Bin Luo (University of Electronic Science and Technology of China)
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=20261127134029.1813-5-luob87709@gmail.com \
--to=luob87709@gmail.com \
--cc=david@ixit.cz \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--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