* [PATCH net v9 1/2] nfc: annotate firmware download state accesses
[not found] <20261130080645.60464-1-shubham@octane.security>
@ 2026-11-30 8:06 ` Shubham Antil
2026-12-01 8:49 ` netdev-bot+sashiko
2026-11-30 8:06 ` [PATCH net v9 2/2] nfc: reject overlapping firmware downloads Shubham Antil
1 sibling, 1 reply; 4+ messages in thread
From: Shubham Antil @ 2026-11-30 8:06 UTC (permalink / raw)
To: netdev; +Cc: Simon Horman, gio, David Heidelberg, oe-linux-nfc, stable
The firmware-download state is written from asynchronous completion and
read from receive and transmit callbacks without a common lock. Mark
every lockless access with READ_ONCE() or WRITE_ONCE() so the intended
one-copy communication is explicit and data-race tooling does not treat
the accesses as unrelated plain loads and stores.
This is a preparatory change for rejecting overlapping firmware
downloads; it does not change the state machine.
Discovered during an AI-assisted source audit using OpenAI Codex,
gpt-5.6-sol. The overlapping-download condition was reproduced at runtime
by issuing two NFC_CMD_FW_DOWNLOAD requests to a pty-backed controller.
No production incident or pre-fix kernel warning was observed. Patch
development and test planning used the same assistant.
Validated by inspecting every access to fw_download_in_progress and built
with W=1 and sparse. The complete series was exercised with a pty-backed
controller under KASAN, UBSAN, lockdep, and strict KCSAN. No physical NFC
controller was available.
Fixes: 9674da8759df ("NFC: Add firmware upload netlink command")
Cc: stable@vger.kernel.org
Assisted-by: LLM (OpenAI Codex, gpt-5.6-sol)
Signed-off-by: Shubham Antil <shubham@octane.security>
---
drivers/nfc/nfcmrvl/main.c | 2 +-
drivers/nfc/nfcmrvl/uart.c | 4 ++--
net/nfc/core.c | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c
index 6efa83219..b9b66127f 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;
}
diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c
index 9aedd1687..4b989fc4e 100644
--- a/drivers/nfc/nfcmrvl/uart.c
+++ b/drivers/nfc/nfcmrvl/uart.c
@@ -159,7 +159,7 @@ static void nfcmrvl_nci_uart_tx_start(struct nci_uart *nu)
{
struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data;
- if (priv->ndev->nfc_dev->fw_download_in_progress)
+ if (READ_ONCE(priv->ndev->nfc_dev->fw_download_in_progress))
return;
/* Remove BREAK to wake up the NFCC */
@@ -173,7 +173,7 @@ static void nfcmrvl_nci_uart_tx_done(struct nci_uart *nu)
{
struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data;
- if (priv->ndev->nfc_dev->fw_download_in_progress)
+ if (READ_ONCE(priv->ndev->nfc_dev->fw_download_in_progress))
return;
/*
diff --git a/net/nfc/core.c b/net/nfc/core.c
index f52166929..91b3274da 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);
if (rc)
- dev->fw_download_in_progress = false;
+ WRITE_ONCE(dev->fw_download_in_progress, false);
error:
device_unlock(&dev->dev);
@@ -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);
}
@@ -104,7 +104,7 @@ int nfc_dev_up(struct nfc_dev *dev)
goto error;
}
- if (dev->fw_download_in_progress) {
+ if (READ_ONCE(dev->fw_download_in_progress)) {
rc = -EBUSY;
goto error;
}
base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0
--
2.54.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net v9 2/2] nfc: reject overlapping firmware downloads
[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-11-30 8:06 ` Shubham Antil
2026-12-01 8:49 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Shubham Antil @ 2026-11-30 8:06 UTC (permalink / raw)
To: netdev; +Cc: Simon Horman, gio, David Heidelberg, oe-linux-nfc, stable
nfc_fw_download() marks an asynchronous download active before calling
the driver, but it does not reject a second request while that download
is running. If the driver rejects the second request, the core clears
fw_download_in_progress and makes the first operation appear complete.
Check the state while holding the NFC device lock and return -EBUSY
without modifying it. Asynchronous completion remains lockless because a
driver may report completion while holding a driver-private lock and the
start path invokes the driver while holding the device lock.
Discovered during an AI-assisted source audit using OpenAI Codex,
gpt-5.6-sol. The overlapping-download condition was reproduced at runtime
by issuing two NFC_CMD_FW_DOWNLOAD requests to a pty-backed controller.
After this change the second request returned -EBUSY without disturbing
the first. No production incident or pre-fix kernel warning was observed.
Patch development and test planning used the same assistant. No physical
NFC controller was available.
Fixes: 9674da8759df ("NFC: Add firmware upload netlink command")
Cc: stable@vger.kernel.org
Assisted-by: LLM (OpenAI Codex, gpt-5.6-sol)
Signed-off-by: Shubham Antil <shubham@octane.security>
---
net/nfc/core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/nfc/core.c b/net/nfc/core.c
index 91b3274da..b03b34b40 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -48,6 +48,11 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
goto error;
}
+ if (READ_ONCE(dev->fw_download_in_progress)) {
+ rc = -EBUSY;
+ goto error;
+ }
+
if (!dev->ops->fw_download) {
rc = -EOPNOTSUPP;
goto error;
--
2.54.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v9 1/2] nfc: annotate firmware download state accesses
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
0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 8:49 UTC (permalink / raw)
To: shubham; +Cc: netdev, horms, gio, david, oe-linux-nfc, stable, kuba
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v9 2/2] nfc: reject overlapping firmware downloads
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
0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 8:49 UTC (permalink / raw)
To: shubham; +Cc: netdev, horms, gio, david, oe-linux-nfc, stable, kuba
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 (1) · Low: 2 (1)
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 new -EBUSY check in nfc_fw_download()
(net/nfc/core.c:51-54) removes the only userspace way to recover a…
- [Medium] The new check only serializes writers that go through
nfc_fw_download() under device_lock.
- [Medium] The series' earlier commit 'nfc: annotate firmware download
state accesses' says it marks 'every lockless access with READ_ONCE()…
- [Low] The commit message understates what this patch prevents.
- [Low] The patch turns fw_download_in_progress into a lockless handoff
of the driver's firmware-download state, from the completion context…
Pre-existing issues:
- [Medium] The kernel-doc of nfc_fw_download_done() (net/nfc/core.c:76)
says @result is 'The positive value of a standard errno value'.
- [Low] For the same 'firmware download not supported' condition,
nfc_fw_download() returns -EOPNOTSUPP when dev->ops->fw_download is…
--
nfc: reject overlapping firmware downloads
With this commit, nfc_fw_download() returns -EBUSY when
fw_download_in_progress is already set. A second NFC_CMD_FW_DOWNLOAD can
then no longer clear the flag of a running download. The check is done
under the NFC device lock, and the completion path stays lockless.
> If the driver rejects the second request, the core clears
> fw_download_in_progress and makes the first operation appear complete.
[ ... ]
> No production incident or pre-fix kernel warning was observed.
[Severity: Low]
Is this description complete? In some drivers the overlap looks like a
memory-safety problem rather than a flag-accounting problem.
In nfcmrvl_fw_dnld_start() in drivers/nfc/nfcmrvl/fw_dnld.c, a second
request calls request_firmware(&fw_dnld->fw, ...). That overwrites, and
leaks, the firmware of the running download. If the new image has a bad
magic, the error path frees it but leaves the pointer set:
release_firmware(fw_dnld->fw);
fw_dnld->header = NULL;
return -EINVAL;
When the first download ends through fw_dnld_timeout() or rx_work,
fw_dnld_over() frees the same pointer again:
if (priv->fw_dnld.fw) {
release_firmware(priv->fw_dnld.fw);
Queued rx work can also read header->ref_clock (now NULL), or
priv->fw_dnld.fw->data (freed) in process_state_fw_dnld().
If the second image is valid, timer_setup() and mod_timer() run on
fw_dnld.timer while it is still queued from the first download.
In drivers/nfc/nxp-nci/firmware.c, nxp_nci_fw_download() overwrites
fw_info->fw, fw_info->data and fw_info->size while fw_info->work may
still be using them. It also leaks the first firmware.
The new check in nfc_fw_download() blocks all of these on the core path.
Could the commit message describe them?
> diff --git a/net/nfc/core.c b/net/nfc/core.c
> index 91b3274dad41a..b03b34b40e1c9 100644
> --- a/net/nfc/core.c
> +++ b/net/nfc/core.c
> @@ -48,6 +48,11 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
> goto error;
> }
>
> + if (READ_ONCE(dev->fw_download_in_progress)) {
> + rc = -EBUSY;
> + goto error;
> + }
[Severity: Medium]
Can this lock out a pn544 i2c device for good if its firmware download
never completes?
pn544_hci_i2c_fw_download() always accepts the request, so the core
leaves fw_download_in_progress set:
phy->fw_work_state = FW_WORK_STATE_START;
schedule_work(&phy->fw_work);
return 0;
pn544_hci_i2c_fw_work() then waits in one of these states:
FW_WORK_STATE_WAIT_WRITE_ANSWER
FW_WORK_STATE_WAIT_CHECK_ANSWER
FW_WORK_STATE_WAIT_SECURE_WRITE_ANSWER
Only pn544_hci_i2c_irq_thread_fn() moves it forward, and
drivers/nfc/pn544/ has no timer or timeout. If the controller never
raises the answer IRQ (wedged bootloader, lost interrupt, I2C fault),
pn544_hci_i2c_fw_work_complete() and nfc_fw_download_done() never run.
Before this patch, a retried NFC_CMD_FW_DOWNLOAD reached
pn544_hci_i2c_fw_download(). That reset the state to FW_WORK_STATE_START
and restarted the download. The retry was racy and leaked phy->fw, but
the device recovered.
With this check every retry gets -EBUSY. nfc_dev_up() also returns
-EBUSY:
if (READ_ONCE(dev->fw_download_in_progress)) {
rc = -EBUSY;
goto error;
}
The only remaining way to clear the flag seems to be unbinding the
driver, through pn544_hci_i2c_remove():
if (phy->fw_work_state != FW_WORK_STATE_IDLE)
pn544_hci_i2c_fw_work_complete(phy, -ENODEV);
st-nci can set the same flag through vendor FWUPD_START, but vendor
DM_LOAD can still clear it there. So the lockout applies to pn544.
The missing pn544 timeout predates this patch, but the new check turns a
hang that could be retried into a lockout. Should the commit message
mention this change? It should also state the new rule that an accepted
->fw_download() must always end in nfc_fw_download_done().
[Severity: Medium]
Does this check cover every writer of fw_download_in_progress? st-nci also
writes the flag from the NFC_CMD_VENDOR path, and nfc_genl_vendor_cmd()
calls cmd->doit() without device_lock:
dev->cur_cmd_info = info;
err = cmd->doit(dev, data, data_len);
st_nci_hci_dm_fwupd_start() in drivers/nfc/st-nci/vendor_cmds.c uses the
same set-then-clear-on-error pattern that this patch removes from the
core:
dev->fw_download_in_progress = true;
r = nci_hci_send_cmd(ndev, ST_NCI_DEVICE_MGNT_GATE,
ST_NCI_HCI_DM_FWUPD_START, data, data_len, NULL);
if (r)
dev->fw_download_in_progress = false;
st_nci_hci_dm_direct_load() also checks and clears the flag without a
lock.
With two overlapping vendor FWUPD_START requests, the second can still
clear the flag while the first update is running.
Also, st_nci_ops has no fw_download, so nci_fw_download() returns
-ENOTSUPP after the core has already set the flag. Consider:
CPU0 (NFC_CMD_FW_DOWNLOAD) CPU1 (vendor FWUPD_START, no lock)
nfc_fw_download()
READ_ONCE() sees false
st_nci_hci_dm_fwupd_start()
fw_download_in_progress = true
WRITE_ONCE(..., true)
nci_fw_download() returns -ENOTSUPP
WRITE_ONCE(..., false)
The vendor update then looks finished and DM_LOAD returns -EPROTO.
nfc_dev_up() can also bring the controller up in the middle of a
firmware update.
Should these writers be covered too, or at least mentioned in the commit
message?
[Severity: Medium]
This check relies on the marked accesses from the earlier commit "nfc:
annotate firmware download state accesses". That commit says it marks
"every lockless access with READ_ONCE() or WRITE_ONCE()". Are some
accesses still unmarked?
At this commit these plain accesses remain:
drivers/nfc/st-nci/vendor_cmds.c:st_nci_hci_dm_fwupd_start()
dev->fw_download_in_progress = true;
...
dev->fw_download_in_progress = false;
drivers/nfc/st-nci/vendor_cmds.c:st_nci_hci_dm_direct_load()
if (dev->fw_download_in_progress) {
dev->fw_download_in_progress = false;
drivers/nfc/nfcmrvl/main.c:nfcmrvl_nci_unregister_dev()
if (priv->ndev->nfc_dev->fw_download_in_progress)
nfcmrvl_fw_dnld_abort(priv);
The st-nci accesses run unlocked from nfc_genl_vendor_cmd(). The nfcmrvl
read can race with nfc_fw_download_done(), called from the fw_dnld timer
or from rx_work. The same nfcmrvl file already converted the read in
nfcmrvl_nci_recv_frame().
Won't KCSAN flag these against the READ_ONCE() and WRITE_ONCE() calls in
nfc_fw_download(), nfc_dev_up() and nfc_fw_download_done()? The KCSAN run
mentioned in the series used a pty-backed controller, which doesn't
exercise st-nci or nfcmrvl unregister.
[Severity: Low]
Is READ_ONCE() strong enough here? The flag now hands the download state
from the completion context, which takes no device_lock, to the next
nfc_fw_download() caller. Neither WRITE_ONCE() in nfc_fw_download_done()
nor READ_ONCE() here provides release or acquire ordering.
In pn544_hci_i2c_fw_work_complete(), nothing orders the teardown stores
before the flag store:
phy->fw_work_state = FW_WORK_STATE_IDLE;
if (phy->fw) {
release_firmware(phy->fw);
phy->fw = NULL;
}
nfc_fw_download_done(phy->hdev->ndev, phy->firmware_name, (u32) -result);
Under the LKMM, the starter can see the flag as false and write
fw_work_state = FW_WORK_STATE_START, and the stale IDLE store can still
land after it. The re-run fw_work would then see IDLE and do nothing,
and the flag would stay set.
The window is very small in practice. Would smp_store_release() in
nfc_fw_download_done(), paired with smp_load_acquire() here, be the right
primitives for this handoff?
> +
> if (!dev->ops->fw_download) {
> rc = -EOPNOTSUPP;
> goto error;
[Severity: Low]
This isn't a bug introduced by this patch, but the same "firmware
download not supported" condition gives different errnos. The core
returns -EOPNOTSUPP here, while nci_fw_download() and hci_fw_download()
return the kernel-internal -ENOTSUPP:
net/nfc/nci/core.c:nci_fw_download()
if (!ndev->ops->fw_download)
return -ENOTSUPP;
net/nfc/hci/core.c:hci_fw_download()
if (!hdev->ops->fw_download)
return -ENOTSUPP;
nci_nfc_ops and hci_nfc_ops always set .fw_download, so the check above
never fires for NCI and HCI devices. nfc_genl_fw_download() then passes
errno 524 to userspace.
Should these return -EOPNOTSUPP as well?
[Severity: Medium]
This is a pre-existing issue, but the status nfcmrvl reports through
nfc_fw_download_done() doesn't match the kernel-doc:
* @result: The positive value of a standard errno value
nxp-nci and pn544 pass (u32)-result. nfcmrvl's fw_dnld_over() passes its
error argument through unchanged, and its callers pass negative errnos:
fw_dnld_over(priv, -ETIMEDOUT);
nfcmrvl_fw_dnld_abort() (-EHOSTDOWN) and fw_dnld_rx_work() do the same.
nfc_genl_fw_download_done() writes this value to
NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS with nla_put_u32(). On a timeout,
userspace sees 4294967186 instead of 110.
Should fw_dnld_over() negate the value before reporting it?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130080645.60464-1-shubham%40octane.security
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-01 8:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox