From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18AC91F00896; Wed, 2 Dec 2026 15:32:12 +0000 (UTC) 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== From: Simon Horman To: xuyuqiabc@gmail.com Cc: Simon Horman , 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 Subject: Re: [PATCH net v3 1/1] nfc: digital: fix use-after-free in unregister Date: Wed, 2 Dec 2026 15:31:36 +0000 Message-ID: <20261202153135.109610-2-horms@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261121181620.57904-1-xuyuqiabc@gmail.com> References: <20261121181620.57904-1-xuyuqiabc@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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