Article View: linux.kernel.netdev
Article #25860Re: [PATCH net v3 1/1] nfc: digital: fix use-after-free in unregister
From: Simon Horman
Date: Wed, 02 Dec 2026 15:31
Date: Wed, 02 Dec 2026 15:31
121 lines
12630 bytes
12630 bytes
This is an AI-generated review of your patch. The human sending this
email says "This review does seem to be a legitimate concern, I'd
suggest dropping the duplicate call to cancel_delayed_work() in
trf7970a_abort_cmd()"
Full review at: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121181620.57904-1-xuyuqiabc@gmail.com?part=1
---
nfc: digital: fix use-after-free in unregister
This patch makes nfc_digital_unregister_device() abort the in-flight
driver command and drain the completion works before it frees the queued
commands. It also stops new commands from being queued or submitted once
the device is shutting down. The port100, nfcsim, st95hf and trf7970a
drivers are updated so that no completion callback can run after abort or
removal.
> diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
> index 001748d91ec1c..bf3567c146fff 100644
> --- a/drivers/nfc/trf7970a.c
> +++ b/drivers/nfc/trf7970a.c
> @@ -652,6 +652,12 @@ static void trf7970a_send_upstream(struct trf7970a *trf)
> dev_kfree_skb_any(trf->tx_skb);
> trf->tx_skb = NULL;
>
> + /*
> + * A timeout handler may already be running and waiting for trf->lock.
> + * It must not deliver another completion after this one.
> + */
> + trf->ignore_timeout = true;
> +
[Severity: High]
This is a pre-existing issue, but with this change, can
trf7970a_issue_eof() leave the driver stuck with a stale cb_arg when
trf7970a_cmd() fails?
trf7970a_issue_eof() does not return after it completes the command on an
error:
drivers/nfc/trf7970a.c:trf7970a_issue_eof() {
ret = trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET);
if (ret)
trf7970a_send_err_upstream(trf, ret);
ret = trf7970a_cmd(trf, TRF7970A_CMD_EOF);
if (ret)
trf7970a_send_err_upstream(trf, ret);
trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA;
...
schedule_delayed_work(&trf->timeout_work,
msecs_to_jiffies(trf->timeout));
}
The first trf7970a_send_err_upstream() calls trf->cb(), which is
digital_send_cmd_complete(). That queues cmd_complete_work, which frees
the digital_cmd.
If the EOF command fails as well, the second call passes the same cb_arg
again. digital_send_cmd_complete() can then write cmd->resp into a freed
digital_cmd and queue cmd_complete_work again.
In both cases the state goes back to TRF7970A_ST_WAIT_FOR_RX_DATA and a
new timeout is armed for a command that has already completed.
trf->cb_arg is never cleared.
Before this patch, the re-armed timeout delivered that stale completion.
With the unconditional ignore_timeout = true above,
trf7970a_timeout_work_handler() now only clears the flag:
if (trf->ignore_timeout)
trf->ignore_timeout = false;
The device then stays in WAIT_FOR_RX_DATA. trf7970a_send_cmd() and
_trf7970a_tg_listen() reject every new command with -EIO ("Bogus state"),
so cb_arg is never refreshed.
What happens on the next event in that state? An SRX IRQ would reach
skb_tailroom(skb) in trf7970a_drain_fifo() with trf->rx_skb == NULL. An
error IRQ, or trf7970a_shutdown() on suspend or remove, would call
trf->cb() through trf7970a_send_err_upstream(trf, -ECANCELED) with the
freed digital_cmd as cb_arg.
Should trf7970a_issue_eof() return after each trf7970a_send_err_upstream()
call?
[ ... ]
> @@ -1903,7 +1909,9 @@ static void trf7970a_abort_cmd(struct nfc_digital_dev *ddev)
> trf->aborting = true;
> break;
> case TRF7970A_ST_LISTENING:
> - trf->ignore_timeout = !cancel_delayed_work(&trf->timeout_work);
> + case TRF7970A_ST_LISTENING_MD:
> + if (!cancel_delayed_work(&trf->timeout_work))
> + trf->ignore_timeout = true;
> trf7970a_send_err_upstream(trf, -ECANCELED);
[Severity: Low]
The commit message says:
Preserve an ignore_timeout already set by the IRQ path, and cancel the
timeout work synchronously after shutdown and before unregister
Does this conditional store change anything?
trf7970a_send_err_upstream() calls cancel_delayed_work() again and then
calls trf7970a_send_upstream(). That function now sets
trf->ignore_timeout = true unconditionally.
So ignore_timeout ends up true whichever branch is taken here. The same
is true of the new LISTENING_MD hunk in trf7970a_shutdown().
The store that actually stops a running timeout handler from completing
the command a second time is the one added to trf7970a_send_upstream().
This is tagged for stable. Could the commit message say that the abort and
shutdown hunks depend on the trf7970a_send_upstream() change, so a
backport does not take one without the other? Alternatively, could the
redundant cancel_delayed_work() and conditional store be dropped?
--
pw-bot: changes-requested
Technical Details
Message-ID:
<20261202153135.109610-2-horms@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375894-linux-kernel-netdev=dewy.ruReferences:
<20261121181620.57904-1-xuyuqiabc@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375894-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v3 1/1] nfc: digital: fix use-after-free in unregister Date: Wed, 2 Dec 2026 15:31:36 +0000 Organization: Usenet Network Message-ID: <20261202153135.109610-2-horms@kernel.org> References: <20261121181620.57904-1-xuyuqiabc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2000104"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:3Vw7kqdC0ty7MwJi46Hhh4apwYc= sha256:Dpwas01DkldKfDVDotV8Vj7LNXirXPnzCo36Ayu/cRI= sha1:pQojXpkI3Rp/E41A9q1J5TYXabc= sha256:G+IxWxBzWTbFl6az50HybqTsjyufmHpJeTtY4xFqu68= 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 ABB4D11768B; Wed, 2 Dec 2026 18:32:34 +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 N7T59MxzTz2e; Wed, 2 Dec 2026 18:32:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375894-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 6AD4711764A; Wed, 2 Dec 2026 18:32:19 +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 0D2762AF72; Wed, 2 Dec 2026 15:32:18 +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=1796225537; b=RGVLlECSV1oS/InHqu+RxOnFYF1h8c50fTeC9+tNo98VAQ+ZIfR48yb+wWOvxW7NamdA HnvmUN+fkpd72hBSzHn2gUA4SrmwuJoe0zB5wyx17/+koQLfv+8a3bBmYnP4Gtfl15GKG 0UT2KJnbrI1CQ1viDfVJxHZgLNRIBOlG3fRb2DcE9kkJw1GmZRdxAp1mtroGCdglK9KsK I5pEkBtJ5OO7bk2D7/ay08IYL5k4CzyhXyZNPzuTPdKA5+C6ZkuG4xI74JSGZyNqn+jUA 4kU8tNUiSGWBdmwV7E2Cm1bujuQJIZFwzaAreVYldXXERCnnIeUiPmqi7n+6oOXJluA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796225537; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding; bh=Lks1J8a3N2apKgV2pD74oFWmp9oajRaxH9CdTODFF7Y=; b=SDeJXBa4vVW+ewiT59Z617Gjt99060ouZ8ql6orMLU+ueSwtL8pkQRMU7l9rIv51SjAz 0uS90Hw6yFKC+dOxA0QEiqGURv3Svg/Ph1dnxAGXHg0Pvvump9QkcNH6UUrb/cGDOvknm H47O5QuSZoc4uau4Y8fBO8z6ckZd9U/2nAQkJG6g9Dd8LyA5JbDbuXK5hmt+WDJumaOEV FohLKJPxH8PtaB1ECGtBXCtUhoyKrIKgwIUQkmoKaWOog7D3jhE3WWKSux0o4XPsh+h+L rqLu5n87Y7Cayzqt97Jzvn28WmLmVF+Fhy8Qaa2FgP7cGxlSwIPqWMHmG37In6j2fLg== 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=i42nNJtd; 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 C0702606A32E; Wed, 2 Dec 2026 15:32:17 +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=i42nNJtd 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=1796225536; b=xgRTsqubQGhzsKPm4iJnWdMVvjIduaG4ecD5Loyy6dp5c1//KRgSaLM4qmY+qAwqW/ND jk+DTJKaMqZLow8KP2hH2WJchtTGjYrarYqWk6vJlo0MaXqfFkPJxrxEjI75xX1SR87Ej DJDJzxqKDe7UMieehGNjlfZOIsxcojyTnvgVsAKHfPg2L4wmyhasTeOjCt2+0VM7T7fXM D2fm+BGpQBNYU7wacc0awwKgY3nN4lHduoDXUJi2l05+cv28hBQkrrhHlGEJSce1cqNRy Yxp4/sJ3dlz7dGBMcAKobYjQ3YSLA/CScy4ICPCWffMAgN2S2D4Z/MtYJWwt03a8cmw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796225536; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Lks1J8a3N2apKgV2pD74oFWmp9oajRaxH9CdTODFF7Y=; b=lVvYX0XrNi4/t/G70h/XoBhLphD2lpxDrisdHMZ8rCgqO5OP8elC2A62TTAsdM1Y1ZX7 g9Pc/V2eD2Hsvm9+MJO2cLlbXH46EaD8hnZZZkhp712MUhfWMQmT0O+DnSyE3DSxAysDX wNk2ufFTzIUP1iStOeE1yHQe2BjdIFa5p1aaAL+w/C8d+ViA2YYDBDnSMfWKcQpLOq/jc r48ZD6PdFrReN1UvIlF35RLbtIk5cVrl/NMPgyb0hiExbHJ08I8zPiQzqnw2xVnsseAgT RQ/ooInb1fh6MGWQ95GVn3iZGjp/ihDw1hmvY1fiVlJ4Ae/vk2i1KxRn9zSw4IpaxyQ== 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=i42nNJtd; 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 DE348606A31A; Wed, 2 Dec 2026 15:32:16 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18AC91F00896; Wed, 2 Dec 2026 15:32:12 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796225536; bh=Lks1J8a3N2apKgV2pD74oFWmp9oajRaxH9CdTODFF7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i42nNJtd+y4AUd2y3ZmgZ++C6ddhYXcwfvS2ryiqBFbPGe6DfFaQHxmC3J6A6z2Nq Z5pfpzXho56HVWB/fOIEMlJmQjsHUKVl8a3vb89Uhv2MPPvC6KwGwk1QM55ER7unuQ CRoxK0fKrzCoSvqVxxaQUrEg5JwJwfrOw8YGMUkYK2pIS9KrwEXH9dB9IfuFj9wOTw rY4o1I9Q1dg0leYW3L4Bwjvglmp3YaV8bYJgKDgwQOVMSOZzhODjMyTYcugBgx6Z2f hXCNeft+NT8cI5sr2uM/AIc1eVdLh6XFGlv4lWcq+aZ1nGNFOluhYjQZDRRJXQOMZO 0h8z5ztkfSUzQ== X-Cc: Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, oe-linux-nfc@lists.linux.dev, david@ixit.cz, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, stable@vger.kernel.org, vega@nebusec.ai, weir@nebusec.ai, xuyq21@lenovo.com, mgreer@animalcreek.com, u.kleine-koenig@baylibre.com, ian.ray@gehealthcare.com, dmitry.torokhov@gmail.com, thierry.escande@linux.intel.com, sameo@linux.intel.com X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261121181620.57904-1-xuyuqiabc@gmail.com> 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