From: Zhi-Jun You <hujy652@gmail.com>
To: netdev-bot+sashiko@kernel.org
Cc: hujy652@gmail.com, 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
Subject: Re: [PATCH net v2] net: ethernet: mtk_wed: fix double free in mtk_wed_rx_reset
Date: Mon, 30 Nov 2026 21:08:28 +0800 [thread overview]
Message-ID: <179604410831.6583.1651714186941522401.b4-reply@b4> (raw)
In-Reply-To: <179586936991.3135.11080392761968621173@kernel.org>
On 2026-11-28 12:36 +0000, netdev-bot+sashiko@kernel.org wrote:
> 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.
ACK, I will update the commit message and fix tag.
Best regard,
Zhi-Jun
pw-bot: cr
>
> >
> > 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
>
>
prev parent reply other threads:[~2026-11-30 13:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 12:34 Zhi-Jun You
2026-11-28 12:36 ` netdev-bot+sashiko
2026-11-30 13:08 ` Zhi-Jun You [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179604410831.6583.1651714186941522401.b4-reply@b4 \
--to=hujy652@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=lorenzo@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=sujuan.chen@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®