From: netdev-bot+sashiko@kernel.org
To: luob87709@gmail.com
Cc: oe-linux-nfc@lists.linux.dev, johan@kernel.org, david@ixit.cz,
kuba@kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v5 4/5] nfc: nci: drop stale rx_data_reassembly on errors, timeout, and close
Date: Sat, 28 Nov 2026 14:13:40 +0000 [thread overview]
Message-ID: <179587522029.3135.18031920907160557003@kernel.org> (raw)
In-Reply-To: <20261127134029.1813-5-luob87709@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] nci_close_device() (net/nfc/nci/core.c) now frees
ndev->rx_data_reassembly at lines 629-634, after…
- [Medium] The commit says it stops stale reassembly bytes from surviving
a close/reopen cycle, but it only frees ndev->rx_data_reassembly in…
- [Medium] nci_core_conn_intf_error_ntf_packet()
(net/nfc/nci/ntf.c:135-137) now drops ndev->rx_data_reassembly on…
- [Low] The patch changes the early `return 0` in the already-down branch
of nci_close_device() (net/nfc/nci/core.c:585) to `goto flush_rx`.
- [Low] The From:/Signed-off-by: names do not match.
--
nfc: nci: drop stale rx_data_reassembly on errors, timeout, and close
This patch frees and clears ndev->rx_data_reassembly in four cases where
a data exchange ends: a nonzero data status, CORE_INTERFACE_ERROR_NTF, a
data exchange timeout, and device close. The goal is to stop a partial
NCI_PBF_CONT fragment from being leaked or prepended to later data.
> Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
[Severity: Low]
This isn't a bug, but the author and Signed-off-by names don't match.
The author name is recorded as the bare email address,
"luob87709@gmail.com <luob87709@gmail.com>". The Signed-off-by name is
"Bin Luo (University of Electronic Science and Technology of China)".
checkpatch reports this as FROM_SIGN_OFF_MISMATCH. Could this be resent
with a proper From: header and a plain "Bin Luo <luob87709@gmail.com>"
sign-off? The other patches in this series have the same metadata.
> diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
> index efd4e5e0290d4..f832251589f33 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;
> }
[Severity: Low]
Before this patch, the already-down branch of nci_close_device() returned
here without touching rx_wq. With the goto, it now also runs
flush_workqueue(ndev->rx_wq) and then takes req_lock a second time. This
branch is mostly reached from nci_unregister_device() when the device is
already down.
The commit message says:
- In nci_close_device() after flush_workqueue(ndev->rx_wq) on both
close paths, guarded by req_lock and !NCI_UP.
It doesn't say that the rx_wq flush is new on the down path.
The change looks harmless, because destroy_workqueue() drains rx_wq right
after this during unregister. Could the commit message still mention
this behaviour change, since the patch is tagged for stable?
>
> /* 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);
[Severity: High]
Can this free ndev->rx_data_reassembly while nci_add_rx_data_frag() is
still using it?
Holding req_lock here doesn't keep rx_work out. The chain
nci_rx_work()->nci_rx_data_packet()->nci_add_rx_data_frag() reads,
copies from, frees and reassigns ndev->rx_data_reassembly without ever
taking req_lock.
The flush before this also doesn't stop rx_work from being queued again.
In nci_recv_frame(), the flag test and the queueing are not atomic with
respect to close:
net/nfc/nci/core.c:nci_recv_frame() {
if (!ndev || (!test_bit(NCI_UP, &ndev->flags) &&
!test_bit(NCI_INIT, &ndev->flags))) {
kfree_skb(skb);
return -ENXIO;
}
/* Queue frame for rx worker thread */
skb_queue_tail(&ndev->rx_q, skb);
queue_work(ndev->rx_wq, &ndev->rx_work);
...
}
The normal close path sets NCI_INIT again while
__nci_request(nci_reset_req) runs. Could this sequence happen?
CPU1 (driver rx path)
nci_recv_frame()
passes the NCI_INIT test during the reset request
<preempted>
CPU2
nci_close_device()
clear_bit(NCI_INIT, &ndev->flags);
...
flush_workqueue(ndev->rx_wq);
CPU1
skb_queue_tail(&ndev->rx_q, skb);
queue_work(ndev->rx_wq, &ndev->rx_work);
rf_conn_info survives close, so the requeued rx_work accepts a data
packet on conn 0. It then runs nci_add_rx_data_frag() while CPU2 does
this:
mutex_lock(&ndev->req_lock);
if (!test_bit(NCI_UP, &ndev->flags)) {
kfree_skb(ndev->rx_data_reassembly);
That could result in:
- a use-after-free in the memcpy() from rx_data_reassembly->data
- a double kfree_skb() of rx_data_reassembly
- a fragment stored after the close-time free, which survives into the
next open (the stale data problem this patch is meant to fix)
virtual_ncidev_write() calls nci_recv_frame() without a lock and without
checking vdev->running. That lets userspace on /dev/virtual_nci time
frames against close.
Before this patch, only two places touched this field. One was rx_work,
which is single-threaded. The other was nci_free_device(), which runs
after destroy_workqueue().
[Severity: Medium]
Does this cover a reopen after nci_open_device() fails?
The init failure branch of nci_open_device() purges the queues and calls
ops->close(). It doesn't flush rx_wq or drop rx_data_reassembly:
net/nfc/nci/core.c:nci_open_device() {
...
} else {
/* Init failed, cleanup */
skb_queue_purge(&ndev->cmd_q);
skb_queue_purge(&ndev->rx_q);
skb_queue_purge(&ndev->tx_q);
ndev->ops->close(ndev);
ndev->flags &= BIT(NCI_UNREG);
}
...
}
nci_recv_frame() accepts frames while NCI_INIT is set. rf_conn_info for
conn 0 is created on CORE_INIT_RSP and persists. So nci_add_rx_data_frag()
can store a CONT data fragment that arrives during init.
Suppose a later init step then fails (post_setup, init_complete_req, or a
timeout). dev_up stays false and nfc_dev_down() returns -EALREADY, so
nci_close_device() and this new cleanup never run.
Nothing clears the buffer on the next successful open either. The first
data packet in initiator or target mode would then be reassembled on top
of the stale fragment.
Could the init failure branch flush rx_wq and drop the buffer? Another
option is to drop it once at the start of nci_open_device().
> +
> return 0;
> }
[ ... ]
> diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
> index f5c9a8ab7ec10..3ca1009ecb335 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;
> +
[Severity: Medium]
Should this drop be limited to the connection that owns the partial
message?
CORE_INTERFACE_ERROR_NTF reports an error on one logical connection,
ntf->conn_id. The reassembly buffer is shared by the static RF connection
and the dynamic HCI/NFCEE connections, which use
nci_hci_data_received_cb() as their data_exchange_cb.
Consider this sequence:
1. The NFCC sends a CONT segment on RF conn 0, which is stored in
rx_data_reassembly.
2. The NFCC sends CORE_INTERFACE_ERROR_NTF for a different HCI/NFCEE
connection, and this code frees the RF partial message.
3. The NFCC sends the LAST segment on conn 0.
nci_add_rx_data_frag() finds no reassembly and treats the tail as a
complete frame.
In target mode, the truncated tail is passed on with no error:
net/nfc/nci/data.c:nci_add_rx_data_frag() {
...
if (ndev->nfc_dev->rf_mode == NFC_RF_TARGET) {
/* Data received in Target mode, forward to nfc core */
err = nfc_tm_data_received(ndev->nfc_dev, skb);
...
}
So LLCP would receive a truncated PDU. In initiator mode, the same
notification also clears NCI_DATA_EXCHANGE, so the tail is mostly
dropped rather than delivered.
nci_rf_deactivate_ntf_packet() can drop the buffer unconditionally
because RF deactivation ends the whole RF interface. This notification
is per connection. Could the drop first check ntf->conn_id, for example
against NCI_STATIC_RF_CONN_ID or ndev->cur_conn_id?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127134029.1813-1-luob87709%40gmail.com
next prev parent reply other threads:[~2026-11-28 14:13 UTC|newest]
Thread overview: 10+ 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-28 14:13 ` netdev-bot+sashiko
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-28 14:13 ` netdev-bot+sashiko
2026-11-27 13:40 ` [PATCH v5 4/5] nfc: nci: drop stale rx_data_reassembly on errors, timeout, and close Bin Luo (University of Electronic Science and Technology of China)
2026-11-28 14:13 ` netdev-bot+sashiko [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)
2026-11-28 14:13 ` netdev-bot+sashiko
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=179587522029.3135.18031920907160557003@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=david@ixit.cz \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=luob87709@gmail.com \
--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