From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796044127; b=5midRtBAzmwVlbtx/S4MbneWLKqHcQD+DLQfMXu85PiOUUrMJ+9uyQecabQ+m8UGRURo f9mQSQxuGOvYbFDHQddjX963oigi92qXJ29mbhipxCSbhKf2aVNiAvQfY/tJ0UOO7xLlQ v4ZMTPj6ZNoC5TNoBkDlS17Tkf7AqjyFpsJvTNgXz4gBf/vUX2IW1sxJCsWAs8Heqhjbk sOYpH8UByWNJZPGi7d3cq2yhJXtDvv6bKkD8INs04Xgwz4BischPQfNtjimakZSSTNqdR rONS5Z3wMCCi6gPvKDmSPePjJh3z2Byutk5ciUYfDLaI4ZFFJNgRedPG03HEO3rBpjg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044127; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: MIME-Version:Content-Type:Content-Transfer-Encoding:Subject:From:To: Cc:In-Reply-To:References:Date:Message-Id:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=/kBP91leavo4pmW0rYFEDL8QfwUlIL07ws7igPylXOs=; b=QPN33cyffxE0lgKz4BlKH+zERE0CJPI5xdN0yP5gZ30H/hDE6XI33c/1MkBWpffmtF/f 8gLIrALJypxhV9KGd+VOOvVVsNNKsa83ehIBleGq/tL5tFlqQ4UQET02YUeetCX2HEl+z Uij9krj7WgyMPKNLtRQLu8tDp2EEh1JG95ZKRJ3AwNNIgGL1/9H7O48X1YOX/zzoL9Tuv 6UEJJAbpM/brV4nFD8Jk5uxjCeQrpYMGxAUfSYKgJ6DjeCmjsxcItmL9SjYLaTaoghAfW mCjDSYGBnuo/7kSj1FwmDSfvSHUuuWp7iDgkirBcv3wAdUQsEA50Q64sTv9geExzmRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mxIGvrWX; arc=none smtp.remote-ip=209.85.214.174 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89C56606A33E for ; Mon, 30 Nov 2026 13:08:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89C56606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=mxIGvrWX Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2f02ee04378so81482585ad.1 for ; Mon, 30 Nov 2026 05:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796044127; x=1796648927; darn=vger.kernel.org; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=/kBP91leavo4pmW0rYFEDL8QfwUlIL07ws7igPylXOs=; b=mxIGvrWXYXkWIG1lYc3kOdPhrcANb2OmuEr/qv8rjC8PmJGYY2z5C5aqqcOitXCc+h McXAj+Jbf29cWY3Sq5D7V9005sgvDBq8Gu8Uiwvusk65EV2dV2sp6DfS0BtiiRGhuV9O qCtWd7K5K6y3XewjzZid2FrfAj6yyAIDopjLIGJxhQSxhNpUk7Ud0b2nj/e3tsFidrrv zhBdSbX3OdYLS/JN/Ol6yKdbkANmF0RH6K8Im5aUYErIf6epWpYqLGXcN2lj3OhK11vv S/HhWAKryuqtm+nLv6ImjM5s3J5Q7bp/5TZWCxQ9leLNBAKHbJeMfDAE4Kf72wD9W0oE Y6fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796044127; x=1796648927; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=/kBP91leavo4pmW0rYFEDL8QfwUlIL07ws7igPylXOs=; b=x8hfYuqtZUR/qztjxZkFHW3/wLjoWhV0DJzk1g2bWzToht5kl+efeRiv0nPxk8LeV+ Zg2MwWqyHbQjcGAcY6QO8BAH4C+87zraGioHC9H8G8ejgbPtR2EF82wkEI/NMQPS9sgW kC18nL/5/q4UHi/cBxP9v1M45zxKgbtjMrq7BZhJzCFXF+DHkkjktwP6nfT4x7qOCGGK 1P4kMgdptgyNgg4hlTRG9Cpg16hle4jBnEksqnKgrJhQcbRn0wUDkdoZjm6AW0nycA6C 8TV7PhRCIhIZwzjTSQF4vTakv2boyIt07cdOEX9VRvBnY9BKv8Rpwogjb8LO08L09lj7 531g== X-Forwarded-Encrypted: i=1; AL+hErGoS7IWnt8Zgm4jqpwNFEWEdMyw+26cKM3t1wKLwZECXhSfap6zK3WyEu1pEruZygR4IzVAUqe5QEL1N54=@vger.kernel.org X-Gm-Message-State: APuU4Z8b97aXrOrN8Q+p5tlX6RkeCV7XZKgs6rBbXUGKUySjgik5h7vh /oDpDD3IVx52FLLlzOBJxCGWlm2MumsMvRI3agZF5JiHV4eD4B4sKOUw X-Gm-Gg: AZFdTZepN7KIjWOKA7Xy+L3r6avqZloBOiQT/yOtFuCtV220gkAQ7CSqUp0pUOroqg/ eEmAJXkkXQ/EFlGoiOlngUj6NwzialMLlpvRjQyd13RcPc5deiBuORwjmT8s5JRS6m53yUh2M2s hkXoMGWRFkQCMfPb1xcGoxY/sUWpKCkgGRBgIoGmahK0BpTwsloGoIKeL2fnZNmQeTW56eBqiWy HxMSXT/imewOARK3HngH+BhwMzxZ8yjCsIVax9Pq7fj51mua/wKqkqD/jGMnI8ya0KpfW+ej688 35zNttgWVAvGhtH3pMEvk0VJbIRtM1psiAbiFe8WmfU1IGiRVHIOMKaNYz1ioEhDspBnO27btc6 xVUYzqtCGZBb3pwi5MuikZ0a2s7Bpy3p1aZTMENEZ1THyIJEV99t+QjzYH5/Az0iDh5AsmcWz35 XZoDaPCjWHKNpetnGSfX2mSWvI6riGn7Ay9xuiprMyupBuiI0QWf0oK27WoSc1XUPOaLhO2ob75 +fW4PccAcWli8Ee5OLlLeHEdLJtF9zCuD8uFPZWFSDSRjZ1oHCpvovtEubNvHRtZ0FyQQp6WVIH SyQSeQ29HrFjsEG2wJS/s/CKIEZUgAzIaGlnQ5xz5v5oVLKKHflHHpPJTEUHuQ5d X-Received: by 2002:a17:902:ea01:b0:2e5:98d7:8202 with SMTP id d9443c01a7336-2f03f1cf4f1mr351370515ad.13.1796044126555; Mon, 30 Nov 2026 05:08:46 -0800 (PST) Received: from [192.168.1.102] (59-127-145-64.hinet-ip.hinet.net. [59.127.145.64]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f0c1f2csm166861755ad.22.2026.11.30.05.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:08:45 -0800 (PST) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Subject: Re: [PATCH net v2] net: ethernet: mtk_wed: fix double free in mtk_wed_rx_reset From: Zhi-Jun You 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 In-Reply-To: <179586936991.3135.11080392761968621173@kernel.org> References: <20261127-doublefree-v2-1-c0c6d3da3b52@gmail.com> <179586936991.3135.11080392761968621173@kernel.org> Date: Mon, 30 Nov 2026 21:08:28 +0800 Message-Id: <179604410831.6583.1651714186941522401.b4-reply@b4> X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796044129; l=5595; i=hujy652@gmail.com; s=20261123; h=from:subject:message-id; bh=kRKv2nWqxY1EwVGsy0m5Jb25KLbbWfDQRrb7PoT5OMQ=; b=8UUO1T1nF6O4NwXIi6ivqYXoODlUA7psbva6Kdm3mdGIUObMSwlqLMxuHl0+1YAfLJ9Y4VQrL c9zfF5QAoiAAfIkSRJdRvp3ETruQqmNfdJbGmYF4HEjDi/zD+LZcs7N X-Developer-Key: i=hujy652@gmail.com; a=ed25519; pk=MXiVj6rTyQLjK+RN0A0WiriSkqHj/WJPKnbDVaSWdgU= 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 > >