* [PATCH net v9 1/2] nfc: annotate firmware download state accesses
2026-11-30 8:06 [PATCH net v9 0/2] nfc: split firmware download admission fixes Shubham Antil
@ 2026-11-30 8:06 ` Shubham Antil
2026-11-30 8:06 ` [PATCH net v9 2/2] nfc: reject overlapping firmware downloads Shubham Antil
1 sibling, 0 replies; 3+ 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] 3+ messages in thread* [PATCH net v9 2/2] nfc: reject overlapping firmware downloads
2026-11-30 8:06 [PATCH net v9 0/2] nfc: split firmware download admission fixes Shubham Antil
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
1 sibling, 0 replies; 3+ 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] 3+ messages in thread