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: `luo…@gmail.com <luob…@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: stab…@vger.kernel.org > Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob…@gmail.com>
[Severity: Low] This isn't a bug, but the Author field on this commit is only the bare address "luob…@gmail.com <luob…@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 <luob…@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/2026…%40gmail.com