From: netdev-bot+sashiko@kernel.org
To: luob87709@gmail.com
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
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 [thread overview]
Message-ID: <179645308074.3146.1852550158044237615@kernel.org> (raw)
In-Reply-To: <20261204060651.488-3-luob87709@gmail.com>
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
prev parent reply other threads:[~2026-12-05 6:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261204060651.488-1-luob87709@gmail.com>
2026-12-04 6:06 ` [PATCH net v2 1/2] nfc: rawsock: serialize SEND_SHUTDOWN and write queue teardown Bin Luo via B4 Relay
2026-12-05 6:44 ` netdev-bot+sashiko
2026-12-04 6:06 ` [PATCH net v2 2/2] nfc: rawsock: move nfc_deactivate_target() to rawsock_release() Bin Luo via B4 Relay
2026-12-05 6:44 ` netdev-bot+sashiko [this message]
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=179645308074.3146.1852550158044237615@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luob87709@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
--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