Article View: linux.kernel.netdev
Article #23859Re: [PATCH net v2] net: ethernet: mtk_wed: fix double free in mtk_wed_rx_reset
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 12:36
Date: Sat, 28 Nov 2026 12:36
145 lines
13032 bytes
13032 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · 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).
- [Medium] The commit message describes a different bug from the one the
new `dev->rx_buf_ring.desc = NULL` line fixes, and the only Fixes: tag…
Pre-existing issues:
- [Medium] mtk_wed_rx_reset() frees the RX buffer-manager resources only
on full success.
--
net: ethernet: mtk_wed: fix double free in mtk_wed_rx_reset
mtk_wed_free_rx_buffer() already calls mtk_wed_hwrro_free_buffer(), so
this patch removes the second mtk_wed_hwrro_free_buffer() call in
mtk_wed_rx_reset(). It also sets dev->rx_buf_ring.desc, dev->hw_rro.desc
and dev->hw_rro.pages to NULL after they are freed, so the existing NULL
checks work.
Link: https://sashiko.dev/#/map/216156
> diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
> index 0bae252477987..0f215dd3d2d44 100644
> --- a/drivers/net/ethernet/mediatek/mtk_wed.c
> +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
[ ... ]
> @@ -896,6 +898,7 @@ mtk_wed_free_rx_buffer(struct mtk_wed_device *dev)
> dev->wlan.release_rx_buf(dev);
> dma_free_coherent(dev->hw->dev, dev->rx_buf_ring.size * sizeof(*desc),
> desc, dev->rx_buf_ring.desc_phys);
> + dev->rx_buf_ring.desc = NULL;
[Severity: Medium]
Does this line fix an older bug than the one the Fixes: tag names?
The commit message describes the duplicated mtk_wed_hwrro_free_buffer()
call. Removing that call is enough to fix that bug. The only tag is:
Fixes: 1543b8ff02f0 ("net: ethernet: mtk_wed: add wed 3.0 reset support")
The stale rx_buf_ring.desc pointer goes back further, to b08134c6e109
("net: ethernet: mtk_wed: add mtk_wed_rx_reset routine"). That commit added
the mtk_wed_free_rx_buffer() call at the end of mtk_wed_rx_reset() and
moved mtk_wed_rx_buffer_alloc() into mtk_wed_start(). It also affects WED
v2 (MT7986/MT7915).
Before this patch, rx_buf_ring.desc stays dangling after a reset until the
next successful mtk_wed_start(). There are two ways the restart can be
skipped.
The first is mt7915_dma_start() with wed_reset=true returning early:
drivers/net/wireless/mediatek/mt76/mt7915/dma.c:mt7915_dma_start() {
...
ret = mt7915_mcu_wed_enable_rx_stats(dev);
if (ret)
return ret;
mtk_wed_device_start(&dev->mt76.mmio.wed, wed_irq_mask);
...
}
The second is mtk_wed_start() bailing out when dma_alloc_coherent() fails
in mtk_wed_rx_buffer_alloc().
In either case, a later detach runs the free path again on the stale
pointer:
__mtk_wed_detach()
mtk_wed_free_rx_rings()
mtk_wed_free_rx_buffer()
dev->wlan.release_rx_buf(dev);
dma_free_coherent(..., desc, ...);
With only 1543b8ff02f0 tagged, would stable trees that have b08134c6e109
but not the hwrro code (such as 6.6.y) miss this part of the fix?
Would it make sense to add a Fixes: tag for b08134c6e109 and describe the
reset->detach double free in the commit message?
Also, the commit message says dev->hw_rro.page, but the field is
dev->hw_rro.pages.
>
> mtk_wed_hwrro_free_buffer(dev);
> }
> @@ -1722,7 +1725,6 @@ mtk_wed_rx_reset(struct mtk_wed_device *dev)
> false);
> }
> mtk_wed_free_rx_buffer(dev);
> - mtk_wed_hwrro_free_buffer(dev);
>
> return 0;
> }
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch.
mtk_wed_rx_reset() only reaches mtk_wed_free_rx_buffer() if every step
succeeds. Both mtk_wed_mcu_send_msg() state change calls return early on
error:
ret = mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
MTK_WED_WO_CMD_CHANGE_STATE, &val,
sizeof(val), true);
if (ret)
return ret;
mtk_wed_reset_dma() then ignores the return value:
if (mtk_wed_get_rx_capa(dev))
mtk_wed_rx_reset(dev);
After that, the WLAN reset flow calls mtk_wed_device_start() again. On
mt7915 this goes through
mt7915_dma_reset()->mt7915_dma_enable()->mt7915_dma_start().
mtk_wed_start() always calls mtk_wed_rx_buffer_alloc(). That function
overwrites the live pointers without releasing them first:
dev->rx_buf_ring.desc = desc;
dev->rx_buf_ring.desc_phys = desc_phys;
dev->wlan.init_rx_buf(dev, dev->wlan.rx_npkt);
mtk_wed_hwrro_buffer_alloc() overwrites dev->hw_rro.pages and
dev->hw_rro.desc in the same way.
If a firmware message fails during SER recovery, can this leak the old
rx_buf_ring coherent ring? The same question applies to the hw_rro mapped
pages, page_list and coherent ring, and to the RX buffers taken by the
first init_rx_buf() call.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-doublefree-v2-1-c0c6d3da3b52%40gmail.com
Technical Details
Message-ID:
<179586936991.3135.11080392761968621173@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373115-linux-kernel-netdev=dewy.ruReferences:
<20261127-doublefree-v2-1-c0c6d3da3b52@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373115-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2] net: ethernet: mtk_wed: fix double free in mtk_wed_rx_reset Date: Sat, 28 Nov 2026 12:36:09 +0000 Organization: Usenet Network Message-ID: <179586936991.3135.11080392761968621173@kernel.org> References: <20261127-doublefree-v2-1-c0c6d3da3b52@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="947210"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:qrTgtJhgV9B44IUgNWy9LmVLf3w= sha256:1ct4lHUBRAFfiq/eb7+NcHSyYH59SoZAKSV6++6RHX4= sha1:n3Sd6n+f09EZ9y8RBgkaqUNBAQ8= sha256:5rBK4hLoh4hbNvxtXKLxexFgXcdVqEbirFWDlI97+II= 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 D189B125F7D; Sat, 28 Nov 2026 15:36:36 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[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 FW_bLK7mrxuk; Sat, 28 Nov 2026 15:36:29 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373115-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id E43C1125F77; Sat, 28 Nov 2026 15:36:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id CE22A602B0B; Sat, 28 Nov 2026 12:36:18 +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=1795869372; b=DsSrv+SM1Pxdu9IdXkwM5i36nuAt+CMZLjoqfGTWNRnb1atU6202Az6Bi7EAFo3ISWK6 I32zKLJYBw6yLZ9DU81SRohDv0zRNaJfKD1T5ITrN4KGbl1Krq4BPBcwQagIxD+pxfnyT gtPqf+DuIsCnAcE4DZ1Lcwdmv9a72WHK3fIaMq75swU8+D5RCHeUHK1V/QsljquCzPibH mSKnc65rwqbWHhffeh1rZPu6L/Wr6wqsP8Zu9vqj/ghHoEx/pa9Z0WdN+BwTdSlhOAdv1 jodlzx7B7yZ/y22TQFwO/nLNEXDpiOoRQa+8vytmll5JdjT3LfO2HuhJpJK/fbbxU+g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795869372; 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=e4tEpL5eqWttsGZfNF3g5fGUTnRitHzItkaZ9VIiO+w=; b=eqG4OBUH29JNq9HBIdz7xTfVgSfKtuuFNlg2UCbHWTTD9RZlIGETUdW9GIFrfXqhstY7 khbDvQRX20y/r3oHBwtPoqMvaTWFfYzWpUSBADz5PYVjmNO6iiy6yGUvy9WerJxGtyb33 TySzaliwaoNmJaikrmdeRKbrCK6JE5aQOASrCDUD4c5POToYmbuXbAZTCDi90B0t3KYii 5Vuzzaj5J3705FCnqmJOyhVVhxyuWWMReTmAKjr1tY9YTByO+krgTEbgOJ14+eu6tLr7x ijkMhXMBQnfTcpwVXg/xPOvpNFiCSQdTJEO416zRJ01NaJ+Yg7rnkKgcXDI37kRUaBQ== 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="n/puXPBr"; 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 7F407606A330; Sat, 28 Nov 2026 12:36:12 +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=n/puXPBr 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=1795869371; b=IiS/CVdqK25EcAijMl8Uo0nWbf9ZzAgAPyXAzPJpPdZhTGwPcJd4Mq+zTm0wCS812s0Y gi+ozqEjPwfZr5khiYzwEE+mYxdo/cH1iZ8wPpFTDblzaKCnlzNTfLE4oHt3E9BJqg8cw yQkCsR0c0P732VeYsShM3fULpJ9McEt4kVdZCpJuenulVSu70f/joTMTPkj7+RcZ0e3Xb pBR9XzyAffORb4MaMxb/4qMiqSSjCE7kw6VdOOPC7BrPOMDDyND4+hPJqWJn7dM0wLERZ UAiSnsXszNP1z/CJz59l8hLy2/i7HR+jcoiR7LKk42mlXtCdzzRf1oqeR/XQ19ywnIg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795869371; 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=e4tEpL5eqWttsGZfNF3g5fGUTnRitHzItkaZ9VIiO+w=; b=Z5fj2QrTM+ldH+W/mCT8knqpwR1O82X2jThCpkWqNvLqGloY8WdNYiT0x+UEGjsi+sbD vJkBXkLKnAKStvFCIl1i8CzrOubnoa2H02VFZ940YPwmr9jG6fD7/2ZSYYdN0zgH6XVkM zt5MQJn2hA4Mb+NPON0pSjuxcpwPf1I5TSmLWEokUfZp2LM4lfCVqhUf/esOz2bno2jnv mkLQJv2/ebrHIYpiw8K0Sgvy6lWaIgHoUgjePCTOOyvtbB9HplgL29EV1LMUZQZnZ+pC3 MuzfGh1qoK3vfExug/OaX/b4y1MWP/zVTWPGuTKG3tmNL6mLmezXwbSVx6Vy5nUVFPg== 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="n/puXPBr"; 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 95A54606A31F; Sat, 28 Nov 2026 12:36:11 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C6461F000C1; Sat, 28 Nov 2026 12:36:10 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795869371; bh=e4tEpL5eqWttsGZfNF3g5fGUTnRitHzItkaZ9VIiO+w=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=n/puXPBrrDA+MLP/N4C//9HByS6mFgpyNbxhZfoGCJA3AFXPDxVGi1ASDcSy+UyyJ UE7CZfNgHzyuluk/QXbHKEOujurk04uOhLQRTtxfmRFfklML9rNDhQQreogcDUh1dg nKGwM4nEmzjfcKJ6j7YtD1YMefnRezf1m2WQdOKdlGISBW0BnEd1HBdg+LusQtjSyw DXBa6FrgVK7pHmlMvtUAY0vq4m66WDvw1XhZLAZ+xRFw5h/0ZJoDjtgi0P8mi79GQG k3e8/9UPIFGaqqEzZ6M+Fy3yMCGJ31PIHbLIiYGPFEnmTQddd2jt4sBhYwl5+phL8u xQLTqReVxLUug== X-Cc: nbd@nbd.name, lorenzo@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, sujuan.chen@mediatek.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, sashiko-bot@kernel.org, stable@vger.kernel.org X-In-Reply-To: <20261127-doublefree-v2-1-c0c6d3da3b52@gmail.com> X-sashiko-severity: Medium 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