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 5/5] nfc: preserve NCI data status error codes
Date: Sat, 28 Nov 2026 14:13:41 +0000 [thread overview]
Message-ID: <179587522130.3135.16484405009456028236@kernel.org> (raw)
In-Reply-To: <20261127134029.1813-6-luob87709@gmail.com>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message understates how userspace sees the bug.
- [Low] In nci_nfcc_loopback_cb() (net/nfc/nci/core.c), the `else
nci_req_complete(ndev, NCI_STATUS_FAILED);` branch for err > 0 is dead…
--
nfc: preserve NCI data status error codes
The patch changes the status parameter of nci_add_rx_data_frag() from __u8
to int. Before, the negative errno from nci_to_errno() was truncated into
an unrelated positive value. With the change, the original errno reaches
nci_data_exchange_complete() and the AF_NFC raw socket.
> For userspace AF_NFC raw sockets, this corrupts the reported error: for
> example, an NCI status error mapped to -EBUSY (-16) is truncated to
> 240 and negated to SO_ERROR=-240 instead of reporting EBUSY (16).
[Severity: Low]
Should this paragraph also describe what recv() returns on the raw socket
before this patch? The wrong SO_ERROR value doesn't seem to be the only
symptom userspace sees.
With the old __u8 parameter, -EBUSY arrives as 240 and gets passed down
this path:
nci_add_rx_data_frag()->nci_data_exchange_complete()->
rawsock_data_exchange_complete()->rawsock_report_error()
net/nfc/rawsock.c:rawsock_report_error() {
...
sk->sk_err = -err;
...
}
That stores -240 in sk_err. On the next recv(), sock_error() returns
-xchg(&sk->sk_err, 0), which is +240.
__skb_recv_datagram() only retries on -EAGAIN, so it returns NULL with
*err = 240. rawsock_recvmsg() then returns that value as is:
net/nfc/rawsock.c:rawsock_recvmsg() {
...
skb = skb_recv_datagram(sk, flags, &rc);
if (!skb)
return rc;
...
}
So userspace sees a successful read of 240 bytes with nothing copied into
its buffer, and 240 can be larger than the buffer it passed in. The other
mapped statuses behave the same way: -EBADMSG gives 182, -EPROTO 185,
-ETIMEDOUT 146, -ECOMM 186 and -ENOSYS 218.
The code change fixes this path as well. Could the commit message mention
the phantom read so stable maintainers can see the full impact?
> diff --git a/net/nfc/nci/data.c b/net/nfc/nci/data.c
> index 3bbebb9505545..4a2326a337649 100644
> --- a/net/nfc/nci/data.c
> +++ b/net/nfc/nci/data.c
> @@ -213,13 +213,11 @@ EXPORT_SYMBOL(nci_send_data);
>
> static void nci_add_rx_data_frag(struct nci_dev *ndev,
> struct sk_buff *skb,
> - __u8 pbf, __u8 conn_id, __u8 status)
> + __u8 pbf, __u8 conn_id, int err)
[Severity: Low]
This isn't a bug, but with this change the err > 0 branch in
nci_nfcc_loopback_cb() can no longer run:
net/nfc/nci/core.c:nci_nfcc_loopback_cb() {
...
if (err) {
kfree_skb(skb);
if (err < 0)
nci_req_cancel(ndev, -err);
else
nci_req_complete(ndev, NCI_STATUS_FAILED);
return;
}
...
}
The else branch was added in the earlier commit "net/nfc: fix skb
ownership on data exchange errors". At that point, the truncated status
coming out of this __u8 parameter was the only source of positive err
values.
After this patch, nci_add_rx_data_frag() passes only 0, a negative
nci_to_errno() value, or -ENOMEM. The other callers of
nci_data_exchange_complete() pass -ENODEV, -ETIMEDOUT or -EIO.
Could nci_nfcc_loopback_cb() be simplified to always call
nci_req_cancel(ndev, -err) when err is nonzero? Leaving the positive
branch in suggests that positive NCI status values can still arrive there.
> {
> int reassembly_len;
> - int err = 0;
>
> - if (status) {
> - err = status;
> + if (err) {
> kfree_skb(ndev->rx_data_reassembly);
> ndev->rx_data_reassembly = NULL;
> goto exit;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127134029.1813-1-luob87709%40gmail.com
prev parent 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
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 [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=179587522130.3135.16484405009456028236@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