Article View: linux.kernel.netdev
Article #25089Re: [PATCH net v9 1/2] nfc: annotate firmware download state accesses
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 08:49
Date: Tue, 01 Dec 2026 08:49
208 lines
15486 bytes
15486 bytes
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
Technical Details
Message-ID:
<179611495176.3146.1188806879982477881@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374857-linux-kernel-netdev=dewy.ruReferences:
<20261130080645.60464-2-shubham@octane.security>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374857-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v9 1/2] nfc: annotate firmware download state accesses Date: Tue, 01 Dec 2026 08:49:11 +0000 Organization: Usenet Network Message-ID: <179611495176.3146.1188806879982477881@kernel.org> References: <20261130080645.60464-2-shubham@octane.security> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1664232"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:CmheO95978JB7wfkeu1gzUJfcjY= sha256:3bH2jYls5tm0wMKIzS6EYJyoxXb0l1XuC+kfr3qitc0= sha1:Us9k4aeWlqmj3nQ60+5sXClxuZg= sha256:M+hmecBxIRWK/BpA4XPAz/gWjaBxMq4gY2FKo25n3tY= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id EF7861172D7; Tue, 1 Dec 2026 11:49:30 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IalZfqsOpIGf; Tue, 1 Dec 2026 11:49:27 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374857-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 0990E1172CA; Tue, 1 Dec 2026 11:49:17 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 37D052D956; Tue, 1 Dec 2026 08:49:15 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796114954; b=4G5OlSuliMYVzruZgHXP8TuLKH9xKFFdkFmqD9wTsBopW8Sw0pp4QDUCVJlca7q0tQq0 9YjdpzMNOJZFjdqGeE5ChbHVO/pNmO3C6QksTjady0HGPYgYhDgUJ1SGIivGZwDzROnBE ClyERY4jqN8fUWFCNGGugo9MFHIso7khIRBYmy1wwhf7Sb6rLmArwrMLBMoyaeqt8PkVr q7EF/I75KQqUBmHDdO1H6pF4i3nMCHulQOpVIQ62TZyJ3Z2/9uy6EZOkwOldyTl5W0Y8x 1jM8Y/e7Ml2LXaB/XANYaQm7UXXxKEKz2bvE4KZv4j/Qcml0u/BSlJw7DXwuwSnhl0A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796114954; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=YJXYsKXcNyucVfqgmoGSx3RoMOr/QO5RuJfluAhK0IM=; b=a0DW2A1RzI0CPOEm1xynX/TNQBqcG52aFPwExHStcVZ5Ns3R/9cXzj/SKx3MD5IWKWDL 55K9ks9N5tDX58+wJP/P/f7tXovIwljhgvqT0TImfKhD747hg4Q9Enwd3C2D4zIdYoNn2 rTInlCGFBgq+ixtcvO3PFjRmZCQDNOmq6374LZMGzrAGBGITP9lZRsVggTiscX7g/70+9 aroc3ENUrOBz1qtCBV0ZcHadUZ7ivxlhm/mP6A4UIbOgyIxYslJUfbDyJvmMni/1Qrobw +OQONSD2obFxkghueel1XjitO6YN3WqXuYIWFfSLE45bu+fRexHL5aXhqs97Iem8ozw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YZ4gbEvx; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81618606A32D; Tue, 1 Dec 2026 08:49:14 +0000 (UTC) X-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=YZ4gbEvx X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796114953; b=JdzA44n1/VoMgB5nd/ukOMNnab37eoHGODIEdue1reGV6DqY01Cy4eQ4U1Xr46wy9YMK bmD1kGfhgC0op8CxfuGIqoDy7izIePPVdNg1S5Lj9HU2KLH2oGmuKG5Kj0PBqUsWrnhG1 9pQjHzNNOpizOW7bC1b0MbWMkmzoamO8IDWTCfdL+Scc/iUl9fQxg5MHIgVcTaVw0iypr xw/ikIU5K0p2K2ibkIWl3tKdQYywyV2J+wY1JYtcU6Rb9pvBA64ewrgM9JsdupdEWTmDS zwx8uUJPTmccv74NKqH9ZC/83Y+POdQyyIZHvndN6+wveSXp7y1ruF764U18Go1cIRQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796114953; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=YJXYsKXcNyucVfqgmoGSx3RoMOr/QO5RuJfluAhK0IM=; b=xdIEugUgrLlXdi//Rk9W8yvhnu1j9If92calelzqXZTPkuUg0c/kheBox37PVo/G6nV9 bDXKVzLUFaG4n47X9Rzz/2g3R/zRCbeFTaEb5lH0HXACQdsi+buXCe90+pxqBz0sFDlFk LZDhjisy7xjYftxLC1+rjI3CAOMVtJPeA7LECuavQ4UgatZzRUx6mvXAQMHE4l0utKY3d jAXrWR9uxPWtAgyjqD/VKa3jGqgP9ZQAGOm7ztuUP4Xmt0KCdQYezRGEXTa/Druf1Pmmj oNFvkOBXlyRj+35+HwqClkuCqT1ISljVYs3InbMEfh7uXrjuui/MIm4RkQnrjJiJTRw== X-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=YZ4gbEvx; arc=none smtp.remote-ip=100.103.45.18 X-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 A0C56606A32E; Tue, 1 Dec 2026 08:49:13 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E3E1F00893; Tue, 1 Dec 2026 08:49:12 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796114952; bh=YJXYsKXcNyucVfqgmoGSx3RoMOr/QO5RuJfluAhK0IM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=YZ4gbEvxOxJVjHKRc9H+8uGzgAsCNmLSdRzeX0b3XhFnn5lc2cx1Tu1d8UO2UKxzp XY0ZpR8f8vL3jBYswLgS4EBUDTYpJIiVW4eWFyS+xEtpO5JugWltxesw0CrE2vXIaJ XycrnyJJS7x6lUxcYepu9wRbqqsrl/0oxlCqC2reM/yz96nwWEuxyqZqc8JsN2KVls 6YYSN4yjk7QFnwsfX71iZ3kZ1ApZ2ec8dzc4TJQnAeeypLl5JVHJtgBuQXQyroXLxL rSta/co6mfOGhBcMeP+29JSq+BDBSbAvGm0pqIJCqNM4ONV+x3aU2aW9gNxdTPPw2Q MPSVDBlnM7Hww== X-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 X-In-Reply-To: <20261130080645.60464-2-shubham@octane.security> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list