๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27268

Re: [PATCH net v2 2/2] nfc: rawsock: move nfc_deactivate_target() to rawsock_release()

#27268
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 06:44
141 lines
13124 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 1 ยท High: 0 ยท Medium: 0 ยท 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).

- [Critical] This patch moves nfc_deactivate_target() out of
  rawsock_destruct() and into rawsock_release() in net/nfc/rawsock.c.
- [Low] The commit's Author field has no real name: `luob87709@gmail.com
  <luob87709@gmail.com>`.

--

nfc: rawsock: move nfc_deactivate_target() to rawsock_release()

This moves the nfc_deactivate_target() call out of rawsock_destruct() and
into rawsock_release(), where it runs after tx_work has been cancelled.
The goal is to stop the synchronous NCI deactivate request from running
on ndev->rx_wq when an in-flight data exchange drops the last socket
reference. nfc_put_device() stays in rawsock_destruct().

> Fixes: 23b7869c0fd0 ("NFC: add the NFC socket raw protocol")
> Cc: stable@vger.kernel.org
> 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 field on this commit is only the bare
address "luob87709@gmail.com <luob87709@gmail.com>". It doesn't match the
name in the Signed-off-by line above, and the SoB name also includes an
affiliation string.

The previous patch in this series, "nfc: rawsock: serialize SEND_SHUTDOWN
and write queue teardown", has the same mismatch. checkpatch reports it as
a From:/Signed-off-by: name mismatch. It may come from the b4 web relay
mentioned in the v2 changelog.

Would a "From: Bin Luo <luob87709@gmail.com>" line in the body, plus a SoB
without the affiliation, record the authorship correctly?

> diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
> index 291f509f07caf..e2a9a2b0bf5f9 100644
> --- a/net/nfc/rawsock.c
> +++ b/net/nfc/rawsock.c
> @@ -78,6 +78,10 @@ static int rawsock_release(struct socket *sock)
>  		__rawsock_write_queue_purge(sk);
>  		spin_unlock_bh(&sk->sk_write_queue.lock);
>  		cancel_work_sync(&nfc_rawsock(sk)->tx_work);
> +
> +		nfc_deactivate_target(nfc_rawsock(sk)->dev,
> +				      nfc_rawsock(sk)->target_idx,
> +				      NFC_TARGET_MODE_IDLE);
>  	}

[Severity: Critical]
Can this deactivation now race with a data exchange from this same socket
that is still in flight?

cancel_work_sync() only waits for rawsock_tx_work() to return. It doesn't
wait for the nfc_data_exchange() that rawsock_tx_work() already
submitted, and that exchange holds its own sock_hold() reference.

Before this patch, rawsock_destruct() could only run after
rawsock_data_exchange_complete() dropped that reference. So deactivation
always happened after the driver was done with the response.

On pn533 the two sides look like this:

close() side:
rawsock_release()
  nfc_deactivate_target()
    device_lock(&dev->dev)
    pn533_deactivate_target()
      skb_queue_purge(&dev->resp_q);

dev->wq side, without device_lock:
pn533_wq_cmd_complete()
  pn533_send_async_complete()
    pn533_data_exchange_complete()
      skb_queue_tail(&dev->resp_q, resp);
      ...
      skb = pn533_build_response(dev);

Suppose the purge runs after skb_queue_tail(). Then resp is already freed
and pn533_build_response() finds resp_q empty and returns NULL. After
that, pn533_data_exchange_complete() does:

	skb = pn533_build_response(dev);
	if (!skb) {
		rc = -ENOMEM;
		goto error;
	}
	...
error:
	dev_kfree_skb(resp);

Doesn't that free resp a second time?

Chained (MI) responses can leave several skbs on resp_q. In that case
pn533_build_response() walks the queue without the queue lock:

	skb_queue_walk_safe(&dev->resp_q, tmp, t) {
		memcpy(skb->data + tmp_len, tmp->data, tmp->len);

Could a concurrent purge turn this into a use-after-free read and a
corrupted list walk?

This also looks reachable without privileges now:

  - rawsock_create() checks CAP_NET_RAW only for SOCK_RAW.
  - nfc_sock_create(), rawsock_connect() and rawsock_sendmsg() don't
    check anything.

Before this patch, deactivating pn533 during an in-flight exchange (pn533
has no check_presence op) needed NFC_CMD_DEACTIVATE_TARGET or
NFC_CMD_ACTIVATE_TARGET. Both are GENL_ADMIN_PERM. A second socket can't
do it either, because nfc_activate_target() returns -EBUSY while a target
is active.

The unlocked resp_q handling in pn533 predates this patch. What's new is
the trigger: an unprivileged SOCK_SEQPACKET socket can send one frame and
then call close() while the response is still being processed on
dev->wq.

Could the in-flight exchange be waited for or aborted before
nfc_deactivate_target() is called here? Another option is to avoid the
destruct-time deactivation some other way that doesn't run it alongside
driver completions.

>  
>  	sock_orphan(sk);

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204060651.488-1-luob87709%40gmail.com
Technical Details
Message-ID: <179645308074.3146.1852550158044237615@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377855-linux-kernel-netdev=dewy.ru
References: <20261204060651.488-3-luob87709@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377855-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/2] nfc: rawsock: move nfc_deactivate_target() to
 rawsock_release()
Date: Sat, 05 Dec 2026 06:44:40 +0000
Organization: Usenet Network
Message-ID: <179645308074.3146.1852550158044237615@kernel.org>
References: <20261204060651.488-3-luob87709@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2970337"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ChZvjLcXHn0zNJ+42k4dK8M4BV8= sha256:qaVLFzJk68/dKQdJUcGvpCVcIYleRWAR+ik3MJEICyM=
	sha1:88NoBi2cfj4LplUajCaIPzbSe38= sha256:Qr2Gh5XMO+RURjjP+mIsuvTRDOEtBCjPhgn285pRAso=
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 61624117D63; Sat,  5 Dec 2026 09:45:01 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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 9rLEJ9Mggmal;
	Sat,  5 Dec 2026 09:44:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377855-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id EA1D5117D1F; Sat,  5 Dec 2026 09:44:49 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 1CA6833165; Sat,  5 Dec 2026 06:44:44 +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=1796453083;
	b=lwEeT7T4eSj8b5K12E1gqOaELlpMaQK7LphVrimjDa6DvYvT2t15vaxXJST8Fy4I1No9
	 xM1uHzCd7/Wwu6hkuhNbyGcPwaYgmpGfTsYTok37A/4fQe1wE5hU9GbOr1jTfdT8txDWO
	 twIBVhyQ4r8PHpwTghncNvFP+0G71GCTk8x3jOf+qbok5oVkIeanCdEzkNxT5DWEP/3+j
	 7437jyEbPitGAfN6t1t1jCjjwBPeRevB5+CqcMH0sOmiF3AKINxZznWNBOGqFcm8+TZDo
	 vqBg26Ie/DJ9JRl44JCcSelkfKh8rlEC9rx8P67QoNtalQ+NGYG71FEj6fowRtHEXdA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796453083;
	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=vnVYEOrEIx+Oc5FKoI3mJ0b3BsLcSoRSPvN12pZWLuI=;
	b=zNenykWaUiCmDW6dlyLyXorG5u1WWmWHtIfGvG3HRrYOtQOnVsYSBU3ltAaSpPdDx47h
	 b4pH8w3KbPqf7XBwooJO7RJC9vGo024sHGyLiLfAa+l+4uTs6fhjTwvV8JSmmOPWt2OcA
	 RieZawQWI6R7fSdtSfj7Jkap6Mb5v5hyLdH9c8iMGbT5bFzsvu1lngBwW967gEu+c1kxE
	 CEREFTXXsotwr774rQtuz+PpTwhhywtloKGKzVLvQ9XCXSrbGoMIWfzCU+Osu98q8b8Bi
	 Olp2W/WnlwjjAr6F7qfriScpN6kJvfO/WpFXY0MN+gjLf065Nw3H0UuvAmy1IMfMhjA==
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=fYv75avu;
	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 E09AC606A33B;
	Sat,  5 Dec 2026 06:44:42 +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=fYv75avu
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=1796453082;
	b=O8s1qLqILnutY5Ekj1RxLgxiLMJJhKBuOy5QT8TuoKO9GRi7VjI11Im+fpbMGtEtvJgD
	 ioFZmpoRpesjFEpuAo6/5cmrsyEdclW0ONdQ+kgOAuEn5rowme9f0p8UsFZJQpS7X0dcE
	 8hsFPJ8tJeCY/kXFv87OtRju4t0iFHqSemCs3HwWCnHWzfMCnsSV7kABGoNxGcgsRpJ4m
	 Df/mVY5TvzL8BjG/z6WveZX5WHIoO5UljTv6a7ehsuLF9zv1KnrUMt7tHUwBIpdguiShV
	 28AtWQ5N6Py6136+SzZxokNIkHgtrCVco6OhvOLu3yfE7p8hFj6O3DjCnZGPKzSXgBg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796453082;
	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=vnVYEOrEIx+Oc5FKoI3mJ0b3BsLcSoRSPvN12pZWLuI=;
	b=tD76LYMFMkciUMSud0shzwwjYB4eQoQW9BqLYI2w6SmqRltPvof8+vXBbMHiGUeXy/M7
	 O26cWz6lWwlx5j160F82FfFqn3twteQ8QVQLeyWSXN/5vovBsC0IuSZSsdrWGOJdz48Ie
	 LTuBRIw+SeTqWBSGjARKtcEqt5q2xUXRRYzIyxjn6xYPq0ANJFgRCuGEH9S3ksXALfK0x
	 Y8zJ3RnZyFwqwh5GDrJzdNwoDHo8A9/ldcmvVYU7IuytJ2+nKgMSFQeqrXRrNKeWIXqd1
	 xBohXNkjHzSrmf7BAEEO3eFxmOJ3JkzLN/x+NVyOR0pci1bd9iC5wQJZQKqs2UrcKjQ==
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=fYv75avu;
	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 0C744606A33A;
	Sat,  5 Dec 2026 06:44:42 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C8221F0092B;
	Sat,  5 Dec 2026 06:44:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796453081;
	bh=vnVYEOrEIx+Oc5FKoI3mJ0b3BsLcSoRSPvN12pZWLuI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=fYv75avu+EOiX3WpdGNR9BVCrtbxzzhOxOQCdSwbDaUANuahG543eQPrFJGgyc3u/
	 BLfjwV+aqfnstOQD8xiQ2gMwB6dXWs6RwWBHX8KL1/vjBmBsfsCxYXzaK0/jyKUQlA
	 aOeI4AM55V4SCG5tFPDVmstSFKUfR2vaFcs18C1HNDdWKA0BVtTYlXYpBh9zPWcDn/
	 OHrMmntRuHuPn8VxLpM6GGg6BdVwcZSitLTI07Obw4s7fVxu901hBYCbr2llxJdAO6
	 jOGdB6SnmwpxS6VjZ20zJVqQPTSN2Eb6Mv6RFj17QQ3uAwZz4x2ZpczYZXsTL2u0mY
	 xHtckKKRhdGpA==
X-Cc: david@ixit.cz, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, horms@kernel.org, oe-linux-nfc@lists.linux.dev,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <20261204060651.488-3-luob87709@gmail.com>
X-sashiko-severity: Critical
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