Article View: linux.kernel.netdev
Article #23890Re: [PATCH v5 3/5] nfc: digital: complete DEP data exchange on terminal errors
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 14:13
Date: Sat, 28 Nov 2026 14:13
242 lines
15501 bytes
15501 bytes
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
Technical Details
Message-ID:
<179587521936.3135.8436597074279524607@kernel.org>Path:
mbox-mo1.pugleaf.net!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-373151-linux-kernel-netdev=dewy.ruReferences:
<20261127134029.1813-4-luob87709@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!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-373151-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH v5 3/5] nfc: digital: complete DEP data exchange on terminal errors Date: Sat, 28 Nov 2026 14:13:39 +0000 Organization: Usenet Network Message-ID: <179587521936.3135.8436597074279524607@kernel.org> References: <20261127134029.1813-4-luob87709@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="963387"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ERNxXTSZv3zu6jtlu0yKi+6bF5Q= sha256:yFcflzrgW37HvQbBiWRHkeq+5cGZd88w1yNaDqW6HGA= sha1:UK1iLlBVwIbnno2aBxOGey5MkwA= sha256:Kt6aCCG1VYVgx9mYgpWfI2QvRasOb355w1Ylo9JyXbU= 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 7013C125F79; Sat, 28 Nov 2026 17:14:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 gJBRr9Sx8S5P; Sat, 28 Nov 2026 17:14:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373151-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 6D8FB125F76; Sat, 28 Nov 2026 17:13:52 +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 8008F2AA9C; Sat, 28 Nov 2026 14:13:46 +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=1795875226; b=2pYEtiOwR9SasO7wYQ5rDGHSg7fgXmsFgWrAltJ3ceqW+iNzDUGpYKOSgmZJRH31DqhJ VPhpZ+LzFdz4KE7a11sA6mSbTGLUQiDP3iw2DJ3IXNdEj8g0U/CXn30rCW+AhsWAOqPBy fYsUUNC/D3cWUAXsgQAaH2lBOy9eQEgojQ3dUa3Rn17SZjVOEzho5M1WeYlxJZPXafYrK HYijOdDwJLjwlXJzeULBZhBdJAGSpxJPyL6+dwb51JY6/Spt0LGAux01DucLvv+aeJjAA 7O+yqkfx+MKaeNSWbTZ0MVnqRSYhPmR0IjhhyxzUHbi8cOf+K1b6JrMgyNPxo4N26HQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795875226; 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=MfbJlqAYuqKvbh4oLT4dnNJ370gx6Q2LecWWnOcU8gg=; b=kkVMkYAaJRbgYUE7ar1wdXjdhClKy8Qqi13eHFrNGsQK5NwFmdIhUp/w2/G2CzMTz9ce 7Mw/h4HPISFu48G5d9G6rmqHkG9MjoZjbv80Xjkw2BW6+LtvFh47rBINCPdNQXX7ValgH 65ufloHBvx74Edxv8WunbC/DmcQj6FxZ/SuIJd4K1iOgwNEyEjftoT7Id+UasPbmztEzn lU3tNRfzNZkJnJhqAm87z71kCy0bbvgpQMY6iiSwDzTz4XesF2woozdRaPNy6KXnqzm9s YHZxbufYwOMfLMGKYqIj1hwxAAbHnXCvZewNk2w0x79h5Q8XpYfULyz08bPbnFY8PEg== 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=YO5zEZ+1; 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 57225606A32C; Sat, 28 Nov 2026 14:13:46 +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=YO5zEZ+1 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=1795875220; b=D7YyUApjgDi7ZqXJWY1Uod/aDqDvD8O7ZpbIFrb99sRnGHPSjooT7d45dWSzBczBArYh weevEe2ZIvDcfEOjKi0Lj7Ooz4suuux+Vo5iqTN5yQG66VcNGjLzxzTmi0WuGVhQ/oeN+ sgL0sAtv6uGhA0B13ogPDvadSy4wplcdljaFtXFa1be9DhfuhiWIa+zvRe3R2UlbrM3Gt LyyInZZYM1pFTLnBNOf+ZgR8Ao/6B+8B/PKLm63vYFdHHmBSfVK1yyJV1HdOLDzmrVoVR SpqfA+MCRexXAuQ+NUm/hV67HbzfCBFCDS5vlqpb/N7QmlyKB9nfDVmTbM5EC2+Er4g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795875220; 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=MfbJlqAYuqKvbh4oLT4dnNJ370gx6Q2LecWWnOcU8gg=; b=gckBJ1FYYqq3E6Zvh6Ui8j5FMd+3kMdFN21U58Kgmn9EdQuU9V6M4LQnQN402tiejWoB kqS+amaAU9W5IrPgGvBPJVJ162UvJIncNDZhfz+pLDv8YX3J3xFLgJe1TrWUgOTOg7I0r rvnTNHFg+ZNtoXbTJOgVzNt6CTZlJkhX6WFnDVmpsgJ6Rmjv8i+A/gFIhoLsH0HkZGIH6 Rd0t8htpFrZl6+v7H3N1Ht7wPwTs+mejupIokTVkqLesg4v4bd9AySJB4QJ90AyC0i89o hGVM9rdJnje9mxPVpCHA9VhcaLeD99hbiP1F/OQsBpRIyLLIOcrbhip9hN9h7hS7mcg== 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=YO5zEZ+1; 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 7703A606A32A; Sat, 28 Nov 2026 14:13:40 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFE8E1F000C1; Sat, 28 Nov 2026 14:13:39 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795875220; bh=MfbJlqAYuqKvbh4oLT4dnNJ370gx6Q2LecWWnOcU8gg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=YO5zEZ+1c4/CzlC5UYJ3zk0w3xEVn0YJRu3Ejo+G8fZ0dMyTZe1DUVfu2JvYRUN5M yLngGxUdpqt7mJVQKJrMtHielcP1OmIzbgrsj4A1tFS+afi82LeY+wTtzlxBm0XVwA rr41oq+6eXjDDfuThgkPaoY9mtOA0ZqBKIicp9lzvb3+nX8yt6aAWfSIoT/Ez0bBlf ih8dBPlBueCBB6IqRWy9GwCxVN3ig2gmwy9lDncxaOTC8Ww1OV0WoWcuFqtnb69T+W UW/H9oqc/iD6Ddt7kRbrGNHrv5Q7gWVx+NKlmWdoFqR6efhIU1jP4MsAi7jLrRSiTD 2P3VGOkIFtaLg== X-Cc: oe-linux-nfc@lists.linux.dev, johan@kernel.org, david@ixit.cz, kuba@kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org X-In-Reply-To: <20261127134029.1813-4-luob87709@gmail.com> X-sashiko-severity: Medium 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