Netdev List
 help / color / mirror / Atom feed
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 3/5] nfc: digital: complete DEP data exchange on terminal errors
Date: Sat, 28 Nov 2026 14:13:39 +0000	[thread overview]
Message-ID: <179587521936.3135.8436597074279524607@kernel.org> (raw)
In-Reply-To: <20261127134029.1813-4-luob87709@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 (1) · High: 0 · Medium: 2 · Low: 0

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 commit message calls the removed `if (rc)
  kfree_skb(resp);` in digital_in_recv_dep_res() "redundant".
- [Medium] The commit message says that after the change "data_exch->cb()
  is always invoked" for DEP data exchanges.

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but the ACK-
  PDU branch of digital_in_recv_dep_res() can be reached while RX…

--

nfc: digital: complete DEP data exchange on terminal errors

This patch changes the terminal error branches in digital_in_recv_dep_res()
to jump to the exit label instead of the error label, so data_exch->cb() is
called. It also removes the trailing kfree_skb(resp) on error, because the
callback now owns any non-NULL resp.

> diff --git a/net/nfc/digital_dep.c b/net/nfc/digital_dep.c
> index 968547c306a5d..cd6eff01235f8 100644
> --- a/net/nfc/digital_dep.c
> +++ b/net/nfc/digital_dep.c
> @@ -703,7 +703,7 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
>
>  			rc = digital_in_send_nack(ddev, data_exch);
>  			if (rc)
> -				goto error;
> +				goto exit;
>
>  			return;
>  		} else if ((rc == -ETIMEDOUT) &&

[Severity: Medium]
The commit message says errors are routed "so data_exch->cb() is always
invoked". Does that still hold after a retry like this one has been queued?

All of these go through digital_in_send_cmd() -> digital_send_cmd():

  digital_in_send_nack()
  digital_in_send_atn()
  digital_in_send_rtox()
  digital_in_send_saved_skb()
  digital_in_send_ack()
  digital_in_send_dep_req()

digital_send_cmd() only queues the command and returns 0, so this path
returns and waits for the next response.

If the driver's send fails later, digital_wq_cmd() drops the command
without calling cmd->cmd_cb:

net/nfc/digital_core.c:digital_wq_cmd() {
    ...
	pr_err("in_send_command returned err %d\n", rc);

	mutex_lock(&ddev->cmd_lock);
	list_del(&cmd->queue);
	mutex_unlock(&ddev->cmd_lock);

	kfree_skb(cmd->req);
	kfree(cmd->mdaa_params);
	kfree(cmd);
    ...
}

digital_unregister_device(), by contrast, does notify the issuer:

	if (cmd->cmd_cb)
		cmd->cmd_cb(ddev, cmd->cb_context, ERR_PTR(-ENODEV));

In that case digital_in_recv_dep_res() never runs again for the exchange.
data_exch is leaked and data_exch->cb() is never called.

For rawsock, this looks like the same hang the commit message describes.
The sock_hold() taken in rawsock_tx_work() is never dropped, and
tx_work_scheduled stays set.

This needs an in_send_cmd() failure from the driver. Examples are trf7970a
returning -EIO, -EBUSY or -ECANCELED, or a port100 USB submit failure.

Is a matching change needed in digital_wq_cmd(), calling cmd->cmd_cb with
ERR_PTR(rc), to close this completely? If not, could the commit message
be narrowed?

[ ... ]

> @@ -847,7 +847,7 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
>  					     ddev->chaining_skb,
>  					     ddev->data_exch);
>  		if (rc)
> -			goto error;
> +			goto exit;
>
>  		goto free_resp;
>

[Severity: Critical]
This isn't a bug introduced by this patch, but this branch is being
touched. Can a remote target reach this ACK PDU branch while RX chaining
is in progress, rather than TX chaining?

The only guard before the digital_in_send_dep_req() call is:

		if (!ddev->chaining_skb) {
			PROTOCOL_ERR("14.12.4.3");
			rc = -EIO;
			goto exit;
		}

This accepts any chaining buffer. During RX reassembly,
digital_recv_dep_data_gather() stores the receive buffer in the same
field:

	if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb) && (!ddev->chaining_skb)) {
		ddev->chaining_skb =
			nfc_alloc_recv_skb(8 * ddev->local_payload_max,
					   GFP_KERNEL);

nfc_alloc_recv_skb() reserves only 1 byte of headroom, and
skb_copy_expand() keeps it:

	total_size = size + 1;
	skb = alloc_skb(total_size, gfp);

	if (skb)
		skb_reserve(skb, 1);

A target could do the following:

  1) Reply to a DEP_REQ with an I-PDU that has MI set and the correct PNI.
     The initiator allocates the RX chaining skb and sends an ACK
     carrying curr_nfc_dep_pni.
  2) Reply with a DEP_RES ACK PDU using that PNI.

All the checks pass, and digital_in_send_dep_req() then runs this on the
RX buffer:

	skb_push(skb, sizeof(struct digital_dep_req_res));

Would this push 3 bytes into 1 byte of headroom and hit
skb_under_panic() -> BUG()?

There is a second issue. ddev->data_exch is only written in
digital_send_dep_data_prep():

		ddev->chaining_skb = skb;
		ddev->data_exch = data_exch;

It is never cleared, including when the exit label does kfree(data_exch).
On this path it would be NULL or point to an earlier exchange that has
already been freed.

Even without the headroom problem, the queued command would carry a stale
or NULL cb_context. Wouldn't the next digital_in_recv_dep_res() then call
data_exch->cb() through freed memory or a NULL pointer, while the current
exchange's data_exch is orphaned?

> @@ -883,7 +883,6 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
>  exit:
>  	data_exch->cb(data_exch->cb_context, resp, rc);
>
> -error:
>  	kfree(data_exch);
>
>  	kfree_skb(ddev->chaining_skb);
> @@ -892,9 +891,6 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
>  	kfree_skb(ddev->saved_skb);
>  	ddev->saved_skb = NULL;
>
> -	if (rc)
> -		kfree_skb(resp);
> -
>  	return;
>
>  free_resp:

[Severity: Medium]
The commit message describes this as dropping "the redundant
kfree_skb(resp)". Is "redundant" accurate for the series as posted?

The earlier patch "net/nfc: fix skb ownership on data exchange errors"
changed rawsock_data_exchange_complete() and nfc_llcp_recv() to free a
non-NULL skb when err != 0:

net/nfc/rawsock.c:rawsock_data_exchange_complete() {
    ...
	if (err) {
		if (skb)
			kfree_skb(skb);
		goto error;
	}
    ...
}

That patch does not touch net/nfc/digital_dep.c. Neither does "nfc: pn533:
clear resp after queueing to avoid double free".

So at both of those intermediate commits, the existing goto exit paths
that carry a non-NULL resp with rc != 0 free resp twice. One malformed
DEP_RES frame is enough:

digital_in_recv_dep_res()
  digital_skb_pull_dep_sod() returns -EIO
  goto exit
  data_exch->cb(data_exch->cb_context, resp, -EIO)
    rawsock_data_exchange_complete()
      kfree_skb(skb)
  if (rc) kfree_skb(resp)    <- second free

The same applies to these paths:

  - the -EMSGSIZE check
  - the NAD bit check
  - the ACK PDU checks for the NACK bit, a PNI mismatch and a missing
    chaining_skb

The reverse case also breaks. If this patch is backported to stable
without the ownership patch, the callbacks there don't free on error.
Wouldn't resp then leak on every terminal error path, including the ones
that already went to exit before this patch?

Both patches carry Cc: stable, but this one only has Fixes: 7d0911c02fa2
and no dependency note.

Could this be squashed into the ownership patch? Alternatively, could the
commit message say that this removal is required by that patch, and note
the dependency for stable?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127134029.1813-1-luob87709%40gmail.com

  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 [this message]
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

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=179587521936.3135.8436597074279524607@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