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/2026…@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