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=1796133887; b=xwYzmuIbxUw2s1rXxRZrG+RMS4UCk6Y4N53HtrQ2a5smOn82Bf4sQUqF2ds4I4LwkX8x 4tuWuz6qMnN30I4Xx4hWyUJmFsnAQ4S4eVZ1XEMxU+yJgA1K9zdbThY12Pm/w0MZ+SJYi YOYUUeHhKr/rA9OC1VuA2ThY1j48KC0KbvHd4fQSfcLFBd52elIaCXdlJi/ybq8tjGeeq 1qo5fNn8snAlf/QutlWfC3MlGl9nrf0lzbBYD9UuBmDK8oKSlrnZCWzhUZMs3zKkW+KyL wxmjF4/6nUeVpXVTTR7M3MgDxPxk9sV1HS1Ik+lVfpdlRyqIv7/s6ing27XktNP96Jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796133887; 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=nvJHWIU0miUvOXcvPaR+HDRgSHcDq2OZGnh+ZMsOGfQ=; b=nk84Lxex0xNyhlVbvxcJLWyt/AXC5WjT1aCmyc2pYL3ORwKEcFPxG7attwhGkxKJE2Qm JfQKu4TrNa5UFiBZU6y75+1/Pt7iv/DzimMwgYjQi2I76XGU2k34E8Hm7zEkSdKGweW/W w8jR7rAwaf5qe0X9M6LCtrtVj5T+mXaRcPqliIIXBmiX9/kmSzPdmnY8KS5LsHXSv62Pn 4sD27e2AZvIn9WA+Xh6X2EgB4dS3q5Toyv6Dve2Pexix3ot5ttDCV6iYz12ug9ww2vUoE jneORDj++USlxmxjy5CScCKnFa+xktTGRAfgOsqiUTccIS/iWCgKJrhSyCcFrRuM7BQ== 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=i7jghNBU; 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 EA8B3606A32F; Tue, 1 Dec 2026 14:04:46 +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=i7jghNBU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FAF21F0092C; Tue, 1 Dec 2026 14:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796133886; bh=nvJHWIU0miUvOXcvPaR+HDRgSHcDq2OZGnh+ZMsOGfQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=i7jghNBU6Njbo5uQPpxX4QrN/ikD5b6FwSbGhQd9Ta7A4nbJzEOq2dZTOE86oyiLi hs/GSsKamgqpHJ0ywT1b4+VySvCxD/EOjw8biVhIETKeJ2xngLKmR5PwvKomEnV6Rm DfEgtmOKfmPuW7QBhSjdR3BWRx/Xdy0Rm6oBXDmu5Mla67ZN80v2yCUmfmvdIi/8Wu 1SDWGdA2NIKerK9uFSTGacqG7hg7Rtf+l0iyvPJOnbKTmVBwa+E+6ckwX3HEAfOHRC KuI2zigXbQbgIzxGS9/9Txf4syu19ZnHvXo97HEoncP0UD+ixkLqqN26uzQH0ggfhb ZtnZgWqFFy5qw== Subject: Re: [PATCH net v9 2/3] nfc: nfcmrvl: serialize firmware completion and teardown 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, kuba@kernel.org Date: Tue, 01 Dec 2026 14:04:45 +0000 Message-ID: <179613388583.3146.2330494470837938376@kernel.org> In-Reply-To: <20261130130240.65411-3-shubham@octane.security> References: <20261130130240.65411-3-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] nfcmrvl_fw_dnld_start() (drivers/nfc/nfcmrvl/fw_dnld.c) checks only fw_dnld->stopping. Pre-existing issues: - [High] process_state_fw_dnld() (drivers/nfc/nfcmrvl/fw_dnld.c) trusts the 16-bit chunk length that the NFC controller sends. - [High] On the I2C and SPI PHYs, the NFCC interrupt is requested with devm_request_threaded_irq() in probe. -- nfc: nfcmrvl: serialize firmware completion and teardown This adds spinlock-protected active, stopping and starting state, plus an rx_active counter, to the nfcmrvl firmware download code. The goal is to serialize receive work, timeout completion and teardown. Timeout handling moves to a work item, and fw_dnld_over() drains receivers, stops the timer and work items, and cancels pending NCI commands before releasing the firmware. > diff --git a/drivers/nfc/nfcmrvl/fw_dnld.c b/drivers/nfc/nfcmrvl/fw_dnld.c > index 8b9d5257320dc..00c0e9e3e548b 100644 > --- a/drivers/nfc/nfcmrvl/fw_dnld.c > +++ b/drivers/nfc/nfcmrvl/fw_dnld.c [ ... ] > @@ -395,62 +420,80 @@ static int process_state_boot(struct nfcmrvl_private *priv, > > static void fw_dnld_rx_work(struct work_struct *work) > { [ ... ] > + spin_lock_irqsave(&fw_dnld->rx_lock, flags); > + if (fw_dnld->stopping || fw_dnld->starting || !fw_dnld->active) { > + spin_unlock_irqrestore(&fw_dnld->rx_lock, flags); > + return; > + } > + skb = skb_dequeue(&fw_dnld->rx_q); > + spin_unlock_irqrestore(&fw_dnld->rx_lock, flags); > + if (!skb) > + return; [ ... ] > + case STATE_FW_DNLD: > + ret = process_state_fw_dnld(priv, skb); > + break; [Severity: High] This isn't a bug introduced by this patch, but this path is being reworked, so it seemed worth asking. Does process_state_fw_dnld() trust the chunk length from the controller too much? In SUBSTATE_WAIT_COMMAND the length comes straight from the device. The only check is against a complement that the device also supplies: len = get_unaligned_le16(skb->data); ... if (((~len) & 0xFFFF) != comp_len) { ... priv->fw_dnld.chunk_len = len; Then in SUBSTATE_WAIT_ACK_CREDIT: out_skb = alloc_lc_skb(priv, priv->fw_dnld.chunk_len); ... skb_put_data(out_skb, ((uint8_t *)priv->fw_dnld.fw->data) + priv->fw_dnld.offset, priv->fw_dnld.chunk_len); alloc_lc_skb() takes a uint8_t plen. A chunk_len such as 0xFF00 therefore sizes the skb for only len & 0xff payload bytes, and hdr->plen is also wrong. Can skb_put_data() then hit skb_over_panic() once chunk_len exceeds the tailroom? Separately, fw_dnld.offset starts from binary_config->offset in process_state_open_lc() and grows by chunk_len on every data credit. It is never compared against fw->size. Can a controller make the driver read past the end of fw->data and send that memory to the device? nfcmrvl_fw_dnld_start() also casts fw->data to struct nfcmrvl_fw and reads magic, phy, helper and firmware without checking that fw->size is at least sizeof(struct nfcmrvl_fw). Would a truncated firmware file cause an out-of-bounds read there? [ ... ] > void nfcmrvl_fw_dnld_recv_frame(struct nfcmrvl_private *priv, > struct sk_buff *skb) > { > + unsigned long flags; > + > + spin_lock_irqsave(&priv->fw_dnld.rx_lock, flags); > + if (priv->fw_dnld.stopping || !priv->fw_dnld.active) { > + spin_unlock_irqrestore(&priv->fw_dnld.rx_lock, flags); > + kfree_skb(skb); > + return; > + } > + priv->fw_dnld.rx_active++; > + spin_unlock_irqrestore(&priv->fw_dnld.rx_lock, flags); [Severity: High] This is a pre-existing issue, but does this gate cover receive entries that come from the I2C and SPI interrupt threads after teardown? Both PHYs request the NFCC interrupt with devm_request_threaded_irq(). The IRQ stays requested and enabled until devres runs after remove() returns. nfcmrvl_i2c_remove() and nfcmrvl_spi_remove() only call nfcmrvl_nci_unregister_dev(), which does: nci_unregister_device(ndev); nfcmrvl_fw_dnld_deinit(priv); nci_free_device(ndev); kfree(priv); Nothing disables or frees the IRQ first, and drv_data->priv is never cleared. So this guard in nfcmrvl_i2c_int_irq_thread_fn() still passes: if (!drv_data->priv) return IRQ_HANDLED; if (test_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags)) Suppose the controller raises an interrupt after kfree(priv). Can the thread handler then read the freed priv and ndev through nci_skb_alloc() and nfcmrvl_nci_recv_frame(), and possibly enter nfcmrvl_fw_dnld_recv_frame()? The SPI thread handler calls nfcmrvl_nci_recv_frame(drv_data->priv, ...) in the same way. The stopping and rx_active state lives inside the freed priv, so it can't reject entries that begin after the free. No patch in this series quiesces the IRQ either. [ ... ] > @@ -497,6 +582,13 @@ int nfcmrvl_fw_dnld_start(struct nci_dev *ndev, const char *firmware_name) > if (!firmware_name || !firmware_name[0]) > return -EINVAL; > > + spin_lock_irqsave(&fw_dnld->rx_lock, flags); > + if (fw_dnld->stopping) { > + spin_unlock_irqrestore(&fw_dnld->rx_lock, flags); > + return -ENODEV; > + } > + spin_unlock_irqrestore(&fw_dnld->rx_lock, flags); > + > strscpy(fw_dnld->name, firmware_name); [Severity: High] Should this also reject a start while fw_dnld->active is set, or while a fw_dnld_over() is still running? nfc_fw_download() in net/nfc/core.c only rejects shutting_down and dev_up. It does not check fw_download_in_progress, unlike nfc_dev_up(). So a second NFC_CMD_FW_DOWNLOAD during an active download reaches this point. It then overwrites fw_dnld->name, fw, header, binary_config and state while rx_work, timeout_work or abort still own them. For example, take download A, active with its timer armed. A second request names an existing file with the wrong magic or phy: nfcmrvl_fw_dnld_start() request_firmware(&fw_dnld->fw, ...) <- A's firmware leaks release_firmware(fw_dnld->fw); fw_dnld->header = NULL; return -EINVAL; <- fw_dnld->fw left dangling nfc_fw_download() dev->fw_download_in_progress = false; fw_dnld->active is still true, so when A's timer fires: fw_dnld_timeout_work() fw_dnld_over() release_firmware(fw_dnld->fw); <- second release Can this double free the struct firmware? If a queued frame is processed before the timer fires, process_state_init() would dereference the NULL header. Alternatively, process_state_fw_dnld() would read the freed fw->data. If the second request names a file that doesn't exist, request_firmware() sets fw_dnld->fw to NULL. Would A's state machine then dereference fw_dnld->fw->data with fw_dnld->fw NULL? There is also a window in fw_dnld_over() itself: fw_dnld->active = false; spin_unlock_irqrestore(&fw_dnld->rx_lock, flags); strscpy(name, fw_dnld->name); wait_event(fw_dnld->rx_wait, !READ_ONCE(fw_dnld->rx_active)); timer_delete_sync(&fw_dnld->timer); ... nci_cancel_pending_cmds(priv->ndev); skb_queue_purge(&fw_dnld->rx_q); if (fw_dnld->fw) { release_firmware(fw_dnld->fw); fw_dnld_over() runs from the work items and from abort without device_lock. If start() runs during these sleeping steps, could fw_dnld_over() release the new download's firmware, purge its rx_q, delete its timer and clear fw_download_in_progress? The commit message says firmware state is released "exactly once". Does that hold while start() does not check the new active flag? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130130240.65411-1-shubham%40octane.security