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=1794062230; b=lf1VON4OGfD68fJjQrvQs1T8RuHKfvl6d78LsFhzwTi9mTPEa3EZ828uc6XfSRGJ/ke7 XL3qb51E3JvrsguZcZ5Zi3BJJ7O3uHgTcjNjwSAkPDvl4N6FwvBIWdT9Wtfl1gIX0MQqz YtdIErwUSjPPlhBRyN4uboDUHhCEGp9jofolRCNWLO+QYioQR0bov8Eg6kKanI99Xj7Ui ADQ0dFcWgucGxZAoZ9734c1tb7HxnqoeTDRWTNxY1y//Au5Lu59wtRkUXKqhzLipb+kmU B8pCxAUDo75j2QjT2VpK+Ue10HLgRjAXvuoTWdgNMrJRiCeHuKUKoMQ4z1jgvsFKU7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794062230; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=wHvhg4KkVXAq+ws3H7aE+HZSdlYy3nVIliPtTp5tx/k=; b=iB58O66SS28RZ7trGAKJnBBxeLZZKsOyW/yHzeMF8uLYdXdjjKzgOqUslvbnu6U8C8kR heEha2wySsDKfFClkzRU2xPtY2gQfgzNYlS8SPonPJr4U+cX9sH9lRUi9Q0h5ulROLCKS a/ID9/oU+5JyWWI3BNO3IjQElONmefk2V+HdpdQkPzMnCYnrHi9h/A59vv5k78KDQuTTQ VUJCOv2cw0QblpOL8+YehVk9p4BcdVrIbgsf8mDwSow4M6M1HBZqeO/mwSNUPZDaQnI9U zQls97wScCWMJN7Z9gczcN49O5SskKpvhE50mMW2DizXbaQQALR8irtPhHELsxSB3og== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=pQEggfzB; 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 4CA60606D827; Sat, 7 Nov 2026 14:37:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=pQEggfzB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01BA31F0089F; Sat, 7 Nov 2026 14:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794062230; bh=wHvhg4KkVXAq+ws3H7aE+HZSdlYy3nVIliPtTp5tx/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pQEggfzBsheOhz+440VY5D5Q0Ie5S2gzdNfsNnAmJB3UgXPuHpPOvBjVtDzspC65p KnBKfBuKaWqQ/5OUhjG+NgWqsyQ8LdJ6y5NF0cFokWj1yF3gFfnq+6NBigPh4GhCuJ nJC+6WH2otZa95RsHT69ePj3e+mYyavUfORxd5rI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Devin Wittmayer , Eason Lai , Hans Buchheim , Sergei Melnichenko , Felix Fietkau , Sasha Levin Subject: [PATCH 6.12 1181/1536] wifi: mt76: fix memory leak in USB TX path Date: Sat, 7 Nov 2026 08:53:17 -0500 Message-ID: <20261107135030.912208525@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134957.653319350@linuxfoundation.org> References: <20261107134957.653319350@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eason Lai [ Upstream commit 82856da2d3b6a30011f4db6ea5f34c13484e0ef8 ] When errors occur in mt76u_tx_queue_skb(), the skb is not properly freed, leading to memory leaks. This happens when: - The queue is full - tx_prepare_skb() drops zero-length frames (such as WMM NULL frames) to prevent hardware TX hangs - Buffer setup fails Fix by properly releasing the skb with ieee80211_tx_status_ext() when the queue is full or tx_prepare_skb() fails, and using mt76_tx_complete_skb() when mt76u_tx_setup_buffers() fails (since tx_prepare_skb() has already succeeded and may have allocated resources that need cleanup) Fixes: b40b15e1521f ("mt76: add usb support to mt76 layer") Cc: stable@vger.kernel.org Tested-by: Devin Wittmayer Closes: https://github.com/morrownr/mt76/issues/83 Signed-off-by: Eason Lai Tested-by: Hans Buchheim Reported-by: Sergei Melnichenko Signed-off-by: Devin Wittmayer Link: https://patch.msgid.link/20260914021920.32246-3-eason.lai@mediatek.com Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- drivers/net/wireless/mediatek/mt76/usb.c | 31 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index f9e67b8c3b3c8..b39dbf22dfc1d 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -854,6 +854,9 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, enum mt76_txq_id qid, struct sk_buff *skb, struct mt76_wcid *wcid, struct ieee80211_sta *sta) { + struct ieee80211_tx_status status = { + .sta = sta, + }; struct mt76_tx_info tx_info = { .skb = skb, }; @@ -861,17 +864,27 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, u16 idx = q->head; int err; - if (q->queued == q->ndesc) - return -ENOSPC; + if (q->queued == q->ndesc) { + err = -ENOSPC; + goto err_free_skb; + } skb->prev = skb->next = NULL; err = dev->drv->tx_prepare_skb(dev, NULL, qid, wcid, sta, &tx_info); if (err < 0) - return err; + goto err_free_skb; err = mt76u_tx_setup_buffers(dev, tx_info.skb, q->entry[idx].urb); - if (err < 0) - return err; + if (err < 0) { + /* + * mt76_tx_status_skb_get() walks the idr and dereferences + * a freed skb. This SKB is not counted in non-AQL counter + * due to error return, so using 0xffff as wcid to keep + * balanced. + */ + mt76_tx_complete_skb(dev, 0xffff, tx_info.skb); + goto err_ret; + } mt76u_fill_bulk_urb(dev, USB_DIR_OUT, q->ep, q->entry[idx].urb, mt76u_complete_tx, &q->entry[idx]); @@ -882,6 +895,14 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, q->queued++; return idx; + +err_free_skb: + status.skb = tx_info.skb; + spin_lock_bh(&dev->rx_lock); + ieee80211_tx_status_ext(dev->hw, &status); + spin_unlock_bh(&dev->rx_lock); +err_ret: + return err; } static void mt76u_tx_kick(struct mt76_dev *dev, struct mt76_queue *q) -- 2.53.0