Netdev List
 help / color / mirror / Atom feed
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 1/5] net/nfc: fix skb ownership on data exchange errors
Date: Sat, 28 Nov 2026 14:13:38 +0000	[thread overview]
Message-ID: <179587521832.3135.10557167189631525290@kernel.org> (raw)
In-Reply-To: <20261127134029.1813-2-luob87709@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

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).

- [Medium] The patch adds `skb_queue_purge(&hdev->rx_hcp_frags)` to
  `nfc_hci_failure()` in net/nfc/hci/core.c.
- [Low] net/nfc: Fixes trailers cite file-rename commits instead of bug
  introductions

--

net/nfc: fix skb ownership on data exchange errors

This commit documents that a data_exchange_cb_t callback owns any
non-NULL skb it receives, whatever the err value. It updates the rawsock,
LLCP, HCI, NCI-HCI, loopback, microread, pn544 and st21nfca callbacks to
free or consume the skb on error paths. It also makes HCI/NCI-HCI fragment
reassembly splice rx_hcp_frags onto a local list under the queue lock, and
purges partial fragments on error.

> diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
> index ba6f0310ffd7c..1b43f1e854071 100644
> --- a/net/nfc/hci/core.c
> +++ b/net/nfc/hci/core.c

[ ... ]

> @@ -833,6 +832,7 @@ static int hci_se_io(struct nfc_dev *nfc_dev, u32 se_idx,
>  
>  static void nfc_hci_failure(struct nfc_hci_dev *hdev, int err)
>  {
> +	skb_queue_purge(&hdev->rx_hcp_frags);
>  	mutex_lock(&hdev->msg_tx_mutex);

[Severity: Medium]
Can this purge drop the first fragments of a message that is still being
reassembled, and cause the last fragment to be misparsed?

nfc_hci_failure() is not only reached from the reassembly path. It is also
reached from msg_rx_work through nfc_hci_event_received():

net/nfc/hci/core.c:nfc_hci_event_received() {
    ...
	default:
		pr_info("Discarded unknown event %x to gate %x\n", event, gate);
		r = -EINVAL;
		break;
	}
    ...
exit_noskb:
	if (r)
		nfc_hci_driver_failure(hdev, r);
}

It is also reached from nfc_hci_llc_failure() and from drivers that call
the exported nfc_hci_driver_failure().

In the no-pending-command case, nfc_driver_failure() only calls
nfc_targets_found(dev, NULL, 0), so the link keeps receiving frames after
this.

Consider a message larger than the LLC payload. nfc_hci_recv_from_llc() has
queued the first fragments on rx_hcp_frags. Then, before the last fragment
arrives, msg_rx_work handles an unknown event. The resulting call chain
empties rx_hcp_frags:

nfc_hci_event_received()->nfc_hci_driver_failure()->nfc_hci_failure()

The window is the whole gap between fragment arrivals, so no tight race
seems to be needed.

> @@ -873,12 +876,19 @@ static void nfc_hci_recv_from_llc(struct nfc_hci_dev *hdev, struct sk_buff *skb)
>  	}
>  
>  	/* it's the last fragment. Does it need re-aggregation? */
> -	if (skb_queue_len(&hdev->rx_hcp_frags)) {
> +	__skb_queue_head_init(&frags);
> +	spin_lock_irqsave(&hdev->rx_hcp_frags.lock, flags);
> +	if (!skb_queue_empty(&hdev->rx_hcp_frags)) {
> +		__skb_queue_tail(&hdev->rx_hcp_frags, skb);
> +		skb_queue_splice_init(&hdev->rx_hcp_frags, &frags);
> +	}
> +	spin_unlock_irqrestore(&hdev->rx_hcp_frags.lock, flags);
> +
> +	if (!skb_queue_empty(&frags)) {

[ ... ]

> -		skb_queue_purge(&hdev->rx_hcp_frags);
> +		__skb_queue_purge(&frags);
>  	} else {
>  		packet->header &= NFC_HCI_FRAGMENT;
>  		hcp_skb = skb;

When the last fragment arrives after such a purge, the queue is empty. It
then takes this else branch and is handled as a complete HCP message.

The byte after the packet header is continuation payload, not a message
header. HCP_MSG_GET_TYPE() and HCP_MSG_GET_CMD() would then decode
payload bytes as the type and instruction.

The tail fragment would then either complete the pending command with the
wrong data and status, or be queued to msg_rx_queue as a bogus command or
event.

The splice under rx_hcp_frags.lock keeps skb_queue_walk() memory-safe. It
does not record that a reassembly was in progress, though. Is the commit
message right that this makes concurrent error purges safe?

Before this patch, rx_hcp_frags was only purged by the reassembly context
itself and by nfc_hci_unregister_device(). This cross-context reset appears
to be new.

Would it be better to purge partial fragments only from the reassembly path
in nfc_hci_recv_from_llc()? Another option is to track the reassembly state
so that an orphaned last fragment is dropped instead of dispatched.

[ ... ]

> diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
> --- a/net/nfc/llcp_core.c
> +++ b/net/nfc/llcp_core.c
> @@ -1636,8 +1636,10 @@ void nfc_llcp_recv(void *data, struct sk_buff *skb, int err)
>  {
>  	struct nfc_llcp_local *local = (struct nfc_llcp_local *) data;
>  
> -	if (err < 0) {
> +	if (err) {
>  		pr_err("LLCP PDU receive err %d\n", err);
> +		if (skb)
> +			kfree_skb(skb);
>  		return;
>  	}
>  

[Severity: Low]
Three of the Fixes: tags seem to point at commits that only moved or
renamed files. They do not point at the commits that introduced the
code being fixed.

30cc4587659e ("NFC: Move LLCP code to the NFC top level diirectory")
only renamed net/nfc/llcp/llcp.c to net/nfc/llcp_core.c, and did not
touch nfc_llcp_recv(). That function was added by d646960f7986 ("NFC:
Initial LLCP support"). It started taking the skb directly, without
skb_get(), in 1727cf937401 ("NFC: llcp: Fix Rx memory leak").

1c54795da05a ("NFC: st21nfca: Align st21nfca driver with other nfc
driver") only renamed st21nfca.c to core.c and st21nfca_dep.c to
dep.c. st21nfca_hci_data_exchange_cb() was added by 7974728094d3
("NFC: st21nfca: Add ISO15693 Reader/Writer support"). The dep.c
callbacks are already covered by the 1892bf844ea0 tag.

97f18414af39 ("NFC: Separate pn544 hci driver in HW dependant and
independant parts") moved pn544_hci_data_exchange_cb() unchanged from
drivers/nfc/pn544_hci.c to drivers/nfc/pn544/pn544.c. The function
itself came from f3e8fb552789, which is already listed. That makes
this tag look redundant.

This has no effect at runtime. However, the stable tooling uses these
tags to decide how far back the fix should go, and rename commits make
that range harder to work out. Could you replace them with the commits
that introduced the code, and drop the ones already covered by another
tag?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127134029.1813-1-luob87709%40gmail.com

  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 [this message]
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
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=179587521832.3135.10557167189631525290@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