Article View: linux.kernel.netdev
Article #25316Re: [PATCH net v9 2/3] nfc: nfcmrvl: serialize firmware completion and teardown
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 14:04
Date: Tue, 01 Dec 2026 14:04
234 lines
15800 bytes
15800 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] 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
Technical Details
Message-ID:
<179613388583.3146.2330494470837938376@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375138-linux-kernel-netdev=dewy.ruReferences:
<20261130130240.65411-3-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!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375138-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v9 2/3] nfc: nfcmrvl: serialize firmware completion and teardown Date: Tue, 01 Dec 2026 14:04:45 +0000 Organization: Usenet Network Message-ID: <179613388583.3146.2330494470837938376@kernel.org> References: <20261130130240.65411-3-shubham@octane.security> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1729568"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:2RWzif/eOE2B2Vz27C6sMKPw4CU= sha256:jMIWOTaJTP/OKWXxXPD29WvOGT83KUmHTDyBDRtftJo= sha1:CCdo1dW3pbrJwwI59zfoysEF+y4= sha256:WHYJb04XJc19fsyUSqjV7QiT+BEOAbW/wowrz8/cns0= 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 B1E391173D1; Tue, 1 Dec 2026 17:05:05 +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 5fUR5u941CYk; Tue, 1 Dec 2026 17:05:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375138-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 964E61173CE; Tue, 1 Dec 2026 17:04:53 +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 08601271BE; Tue, 1 Dec 2026 14:04:48 +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=1796133887; b=gb9y4PjwZUpgvTYvqbN1IBE58FiwA1mtk3eeK6i74VzqmlQPFcRGVqw2fdT8Vt6BIOla qSb1d8sGyY+jQNfL7KoJyFhwtwxar1fNKz/H3ZnfyM5dCJUL2EVix1S42gl3KM/k6E2ef EWSYTB3AkEs1woUBJmx21g0+T9gzYfx3VTaouHdTL+mQ1F18MxZmdD+AqznBvLlq75x8U eL5vfMPmKOM9GXMh5baqQvxLCvgS1NdJ03plhJrq2uNDbWT5rtjtK/IIm0AynVEdDJ12m KLfb2wE0hbYveXCS4o+8DdXDkYZusU+zt237+YhMzctSvRfpCeemgFpSHZDxVyJvbLA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796133887; 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=nvJHWIU0miUvOXcvPaR+HDRgSHcDq2OZGnh+ZMsOGfQ=; b=vx9PM4k9yoyMz07VObMMDVSYpXV5A3VbdIb+azXrKlIJSZZykbes863RfYa6xx8xKopp IEbEapDXiIGs10kXQLNyJuu+Oz5kDPEu8QwhIl1xXZmAQSEIUujoeBnTIEAoga9eFbrup HqAIj6kd0wWbYe8BUVZykQJI5XLzyynaEFgAyTibdvrnmf7aJPVEQR1z1hJDS3Z3w4HRG HI/62f7B3KxQmW7+qi4cQXGgJdnuZflDvpLu3mlMc2WCKq37FGd8s0CLLgvzia/SGRPr+ AzO239PVEwXVb2wU8UaCsZGPaI4FhCWt5CIqNL2SnklVcFabkGXy9HMeZex0pFpXNJw== 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=i7jghNBU; 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 C87A0606A32C; Tue, 1 Dec 2026 14:04:47 +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=i7jghNBU 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=1796133887; b=xwYzmuIbxUw2s1rXxRZrG+RMS4UCk6Y4N53HtrQ2a5smOn82Bf4sQUqF2ds4I4LwkX8x 4tuWuz6qMnN30I4Xx4hWyUJmFsnAQ4S4eVZ1XEMxU+yJgA1K9zdbThY12Pm/w0MZ+SJYi YOYUUeHhKr/rA9OC1VuA2ThY1j48KC0KbvHd4fQSfcLFBd52elIaCXdlJi/ybq8tjGeeq 1qo5fNn8snAlf/QutlWfC3MlGl9nrf0lzbBYD9UuBmDK8oKSlrnZCWzhUZMs3zKkW+KyL wxmjF4/6nUeVpXVTTR7M3MgDxPxk9sV1HS1Ik+lVfpdlRyqIv7/s6ing27XktNP96Jw== X-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== 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=i7jghNBU; 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 EA8B3606A32F; Tue, 1 Dec 2026 14:04:46 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FAF21F0092C; Tue, 1 Dec 2026 14:04:46 +0000 (UTC) X-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== X-Cc: netdev@vger.kernel.org, horms@kernel.org, gio@octane.security, david@ixit.cz, oe-linux-nfc@lists.linux.dev, kuba@kernel.org X-In-Reply-To: <20261130130240.65411-3-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