๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23887

Re: [PATCH v5 1/5] net/nfc: fix skb ownership on data exchange errors

#23887
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 14:13
174 lines
14255 bytes
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
Technical Details
Message-ID: <179587521832.3135.10557167189631525290@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373150-linux-kernel-netdev=dewy.ru
References: <20261127134029.1813-2-luob87709@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373150-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v5 1/5] net/nfc: fix skb ownership on data exchange errors
Date: Sat, 28 Nov 2026 14:13:38 +0000
Organization: Usenet Network
Message-ID: <179587521832.3135.10557167189631525290@kernel.org>
References: <20261127134029.1813-2-luob87709@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="963201"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1://YDPIifddKqYe0qJ100tv3BDMU= sha256:sNin8Wk2u8kEWgCXHJ+kCCqcGwePSzaBgEp8KCYTRTc=
	sha1:koia+bqQ1eA2LmJ3FOKozLl54sg= sha256:sFHpU3g9x4HzztQlgpcibTYo9UAkWKYksV4sN9YHBgU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 650B8125F7D; Sat, 28 Nov 2026 17:13:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 5tfpTPjn_A1a;
	Sat, 28 Nov 2026 17:13:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373150-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 85001125F76; Sat, 28 Nov 2026 17:13:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id E2476602BBC; Sat, 28 Nov 2026 14:13:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795875220;
	b=ZjTMn9cxqrvjVcPH0naZebN6c+ZT5u/kKLjeBsz0X8ktfY+eTqiRYnCYHCmzoQisuSG/
	 AWimwj+auOle8Go0W3JawhM59NhL0wb/AXsBPgR2kjans/pceyKFlmLCrIyhMFYC1EB7n
	 H08qEqxSNYMvWg0fh+LI33SHCCqIJNShoTmaIZSGmX1tQtW3QRKbqemyBTlAeZSH+wpFj
	 1GkLi1keiI+bSBS0YLlQflM5tYbvCZ8mDHgyjdBCqA9O8qN72ZEuXznQKLBc9gzifBL/U
	 3A8sO1tRLRZIm3lYJtVAaQjNyi57pEo87KXBZ0r4JZRB85+9dbjy1pwfRASVs/jHlUA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795875220;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=4yN/GfDemWaVUfkwJzvu8EdIMFv74s+rOsCzvToeLYA=;
	b=VxgMXiM7lArOCWowyO+uNnZ8woV557Ooa33qi0pTHlN2mrC06TH7EUQMMfbgvJ4Y0GpW
	 resVc2OE0UyfK9N5h1rMlvlC+Akcib4zNtYNyBOW1uvaG5lacOyeKN7iy2oU2oAjKBxME
	 RAYhx9eSsgsZ3Uv6AjU7SUKge2bGmBY5KlgmqSNl6dXuku1yWRfqnh7ccI1YpJeKtlchG
	 slesL45NQwejeEz/joXkRxoMOvOQVylUxHKHVIwgm1UAANTrkS9hnKZNPXrjb69VqS4qz
	 Goa86qtZpo+2VmlGHI5zrArBjIGwYIedFU9sMW2BEYg55lPw48tIpXFP7Cigc2fYuQg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="CZ/U4g68";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 78A7D606A32C;
	Sat, 28 Nov 2026 14:13:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CZ/U4g68
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795875219;
	b=18vHYGndcrLb3jdhWlFkV2hZAbB/FOLL3HrlwqYPSFtCjqtBCadDL/6gZJqAiUzEFVvb
	 Hj7rOEDIKENjl/xEWyMY47jdP3xBIy4GqmWzNu6M+7BN68xTAOixVq4sjueVnW60qoG+0
	 mxiLcZsvYaTbwofK4bEBv892XVMNdCIqqtSFYXYk3bzxhpHsLxC3bu0E5kjskImNjx7F8
	 aFqvdlnGDnGav0kqc4Hi6N6MQKvngvPSDxAanGQ8Y+oOW5IKjxOsDqArjhqTQnoQl3em0
	 l+SOxqnUz/tqtktK9MC+zGvKMUwHJET3DsNCQtec1c/V0jur7xQbNCutcYFgwwd54IA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795875219;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=4yN/GfDemWaVUfkwJzvu8EdIMFv74s+rOsCzvToeLYA=;
	b=mLKDcvl+5FRUzyh1ncdJwl68XRDMIOGtzsBzg326W0ZiFT1iWwWi6yCiz8jQevLTukN6
	 OF9iE7j8g4blW1w3kKRi1FXSQimDkxqgdkUbuI6SqdgdSPhfkG/6qqQgGu89r/y5Oe3mu
	 nuRWEWSOGR7kspk3hMjbxVwbXc11baIcuUmzDppc5BZkzWw4NnUccIt9K2ALSKgTqKFCl
	 ZtTK1mhEzSj4I5CXel436Oqp2YoeFE3rEGtqu+4nETqTvK0P4+ZpDLvmW/DDbE1ndVSDF
	 nWg8OeOMAZ6Kvhn8CrTFqo1Pjq4sGWJS1yQnA54PrfdnLRms4Ftl6hDzBu/A8aEXZcw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="CZ/U4g68";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E89606A31C;
	Sat, 28 Nov 2026 14:13:39 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7D241F000C1;
	Sat, 28 Nov 2026 14:13:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795875219;
	bh=4yN/GfDemWaVUfkwJzvu8EdIMFv74s+rOsCzvToeLYA=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=CZ/U4g68Ho+12lkYFTfe+UFxTLDMoJyRaXWPhPfJJbZQlnc4gaKZVQ7OvGfsbjlOm
	 wa8KzRmIk22nGrM2gthaGT6Qc+uVEDHyViB3yRg74b8mguBk5i8s/XIVmCKsXfB/HV
	 uhaPNPg+XqAACfDnlGHOB8eTZZKUpwqsNK5g6mHx9yQLEHb1ol+039gdBlvV6OEdPx
	 v1hXSP+LpNuH+UIpAFc8ZAc3eK3tlCu7C4zvyODASacxkzuaBGyZObq8xX88Leie6N
	 IIm58aCXbv7cnO9sGcs2Lz1gJK0ymaND65AOna5sceuoQo+xHS/yzMD0/4TF1FlXpH
	 R1ojWjYlYUUVw==
X-Cc: oe-linux-nfc@lists.linux.dev, johan@kernel.org, david@ixit.cz,
 kuba@kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <20261127134029.1813-2-luob87709@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list