From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42E3E1F00893; Tue, 1 Dec 2026 08:49:12 +0000 (UTC) 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== Subject: Re: [PATCH net v9 1/2] nfc: annotate firmware download state accesses 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 Date: Tue, 01 Dec 2026 08:49:11 +0000 Message-ID: <179611495176.3146.1188806879982477881@kernel.org> In-Reply-To: <20261130080645.60464-2-shubham@octane.security> References: <20261130080645.60464-2-shubham@octane.security> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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