From: netdev-bot+sashiko@kernel.org
To: shubham@octane.security
Cc: netdev@vger.kernel.org, horms@kernel.org, gio@octane.security,
david@ixit.cz, oe-linux-nfc@lists.linux.dev,
stable@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH net v9 1/2] nfc: annotate firmware download state accesses
Date: Tue, 01 Dec 2026 08:49:11 +0000 [thread overview]
Message-ID: <179611495176.3146.1188806879982477881@kernel.org> (raw)
In-Reply-To: <20261130080645.60464-2-shubham@octane.security>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (2) · Medium: 0 · 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).
- [High] The commit message says the patch marks "every lockless access"
to fw_download_in_progress with READ_ONCE()/WRITE_ONCE(), and that…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
nfcmrvl_nci_unregister_dev() (drivers/nfc/nfcmrvl/main.c:179-191) has…
- [High] This problem wasn't introduced by this patch, but in nfcmrvl the
fw_download_in_progress flag is used as the only gate that sends rx…
--
nfc: annotate firmware download state accesses
This commit wraps accesses to nfc_dev->fw_download_in_progress in
READ_ONCE()/WRITE_ONCE(). The changed sites are in net/nfc/core.c and in
the nfcmrvl receive and UART transmit callbacks. The commit describes
itself as preparation for rejecting overlapping firmware downloads, with no
change to the state machine.
> diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c
> index 6efa832191172..b9b66127f9e62 100644
> --- a/drivers/nfc/nfcmrvl/main.c
> +++ b/drivers/nfc/nfcmrvl/main.c
> @@ -205,7 +205,7 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
> }
> }
>
> - if (priv->ndev->nfc_dev->fw_download_in_progress) {
> + if (READ_ONCE(priv->ndev->nfc_dev->fw_download_in_progress)) {
> nfcmrvl_fw_dnld_recv_frame(priv, skb);
> return 0;
> }
[Severity: High]
The commit message says the patch will "Mark every lockless access with
READ_ONCE() or WRITE_ONCE()". It also says it was "Validated by inspecting
every access to fw_download_in_progress".
Was one reader in this same file missed?
drivers/nfc/nfcmrvl/main.c:nfcmrvl_nci_unregister_dev() {
...
nci_unregister_device(ndev);
if (priv->ndev->nfc_dev->fw_download_in_progress)
nfcmrvl_fw_dnld_abort(priv);
...
}
This function runs from the driver remove paths: USB disconnect, i2c/spi
remove, and nfcmrvl_nci_uart_close(). Nothing serializes it against the
asynchronous completion:
fw_dnld_timeout() or fw_dnld_rx_work()
fw_dnld_over()
nfc_fw_download_done()
WRITE_ONCE(dev->fw_download_in_progress, false);
Won't KCSAN still report the plain load in nfcmrvl_nci_unregister_dev()
racing with that WRITE_ONCE()?
The later patch "nfc: reject overlapping firmware downloads" does not seem
to touch this site either. So it is still a plain load at the end of the
series.
The st-nci accesses in vendor_cmds.c look fine. Their callers are all genl
doit handlers, which run serialized under genl_mutex.
This patch carries Fixes: and Cc: stable. Should this site be handled too?
It may need real synchronization here rather than another READ_ONCE(): shut
down fw_dnld.timer and cancel fw_dnld.rx_work before testing the flag.
[ ... ]
> diff --git a/net/nfc/core.c b/net/nfc/core.c
> index f521669293f05..91b3274dad41a 100644
> --- a/net/nfc/core.c
> +++ b/net/nfc/core.c
> @@ -53,10 +53,10 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
> goto error;
> }
>
> - dev->fw_download_in_progress = true;
> + WRITE_ONCE(dev->fw_download_in_progress, true);
> rc = dev->ops->fw_download(dev, firmware_name);
[Severity: High]
This is a pre-existing issue, but in nfcmrvl this flag is the only thing
that routes rx frames into the fw_dnld state machine.
Neither the flag nor the fields it guards (fw_dnld.fw, header,
binary_config and state) are updated under a lock or with any ordering.
Can queued frames be processed against a NULL binary_config?
On the completion side, a successful boot response in STATE_BOOT does
this:
drivers/nfc/nfcmrvl/fw_dnld.c:process_state_boot() {
...
priv->if_ops->nci_update_config(priv,
&priv->fw_dnld.binary_config->config);
...
} else {
nfc_info(priv->dev, "FW loading: firmware loaded");
fw_dnld_over(priv, 0);
}
return 0;
}
fw_dnld_over() sets fw, header and binary_config to NULL and clears the
flag. However, state stays at STATE_BOOT and the return value is 0, so the
loop in fw_dnld_rx_work() keeps dequeuing:
while ((skb = skb_dequeue(&fw_dnld->rx_q))) {
...
case STATE_BOOT:
ret = process_state_boot(priv, skb);
Suppose nfcmrvl_nci_recv_frame() had already queued a second boot response
while the flag was true. Then process_state_boot() runs again with
binary_config == NULL. Both nfcmrvl_uart_nci_update_config() and
nfcmrvl_spi_nci_update_config() dereference that pointer.
This needs no CPU race. With a pty-backed UART controller, the device side
controls the input.
On the start side, the flag is set here before ops->fw_download().
nfcmrvl_fw_dnld_start() then sleeps in request_firmware(), and only sets
header, binary_config and state = STATE_RESET after that.
Frames that arrive in that window are dispatched on the state left by the
previous download. After a successful download that is STATE_BOOT, and the
pointers are still NULL.
The error break in fw_dnld_rx_work() also leaves skbs in rx_q. Those are
later processed against the next download's state.
READ_ONCE()/WRITE_ONCE() do not order accesses to these fields.
> @@ -73,7 +73,7 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
> int nfc_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
> u32 result)
> {
> - dev->fw_download_in_progress = false;
> + WRITE_ONCE(dev->fw_download_in_progress, false);
>
> return nfc_genl_fw_download_done(dev, firmware_name, result);
> }
[Severity: High]
This isn't a bug introduced by this patch, but can
nfcmrvl_nci_unregister_dev() race with this completion and free priv while
it is still in use?
nfcmrvl_nci_unregister_dev()
if (fw_download_in_progress)
nfcmrvl_fw_dnld_abort()
fw_dnld_over()
nfcmrvl_fw_dnld_deinit()
nci_free_device()
kfree(priv)
Nothing stops fw_dnld_timeout() or fw_dnld_rx_work() from running
fw_dnld_over() at the same time. fw_dnld_over() checks and releases the
firmware without a lock:
if (priv->fw_dnld.fw) {
release_firmware(priv->fw_dnld.fw);
priv->fw_dnld.fw = NULL;
So both callers could call release_firmware() on the same firmware, and
nfc_fw_download_done() would run twice.
While fw_dnld_timeout() is running, timer_pending(&priv->fw_dnld.timer)
returns false. The unregister path therefore skips timer_delete_sync():
if (timer_pending(&priv->fw_dnld.timer))
timer_delete_sync(&priv->fw_dnld.timer);
It then frees priv and the nfc_dev. Meanwhile the timer callback still uses
priv->ndev, priv->fw_dnld.name and dev->idx in
nfc_genl_fw_download_done().
The callback may also have cleared the flag but not yet returned. In that
case the abort is skipped entirely and priv is freed underneath it.
fw_dnld.rx_work is not cancelled or flushed before the abort either, and
destroy_workqueue() runs only afterwards. process_state_fw_dnld() could
therefore still be reading priv->fw_dnld.fw->data after the firmware was
released.
Would this need timer_shutdown_sync() on fw_dnld.timer and
cancel_work_sync() on fw_dnld.rx_work before the flag check?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130080645.60464-1-shubham%40octane.security
next prev parent reply other threads:[~2026-12-01 8:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261130080645.60464-1-shubham@octane.security>
2026-11-30 8:06 ` [PATCH net v9 1/2] nfc: annotate firmware download state accesses Shubham Antil
2026-12-01 8:49 ` netdev-bot+sashiko [this message]
2026-11-30 8:06 ` [PATCH net v9 2/2] nfc: reject overlapping firmware downloads Shubham Antil
2026-12-01 8:49 ` 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=179611495176.3146.1188806879982477881@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=david@ixit.cz \
--cc=gio@octane.security \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=shubham@octane.security \
--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