Article View: linux.kernel.netdev
Article #12468Re: [PATCH] net: stmmac: free RX resources when TX allocation fails
From: netdev-bot+sashiko
Date: Sat, 07 Nov 2026 12:52
Date: Sat, 07 Nov 2026 12:52
175 lines
15131 bytes
15131 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1 (1)
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] net: stmmac: double free of RX resources after stmmac_xdp_open()
failure
- [Low] The commit message does not accurately describe what leaks, and
it leaves out one of the two callers whose behaviour changes.
Pre-existing issues:
- [High] The NULL-pointer oops this concern describes exists in the code,
but it predates this patch.
- [Low] This problem wasn't introduced by this patch, but the kernel-doc
of alloc_dma_desc_resources() (lines 2434-2442), repeated word for…
--
net: stmmac: free RX resources when TX allocation fails
This patch makes alloc_dma_desc_resources() release the RX queues with
free_dma_rx_desc_resources() when alloc_dma_tx_desc_resources() fails.
The goal is to stop the RX side from leaking when stmmac_setup_dma_desc()
drops the partially populated dma_conf.
> stmmac_setup_dma_desc() only frees the
> dma_conf on this path, so the RX DMA rings, page pools and socket
> buffers are leaked.
[Severity: Low]
Is the list of leaked resources accurate? When the TX allocation fails,
__alloc_dma_rx_desc_resources() has only done four things: created the
page_pool, allocated the buf_pool array, allocated the descriptor ring with
dma_alloc_coherent(), and registered xdp_rxq.
The RX buffers are filled in later by init_dma_desc_rings(), so no socket
buffers exist at this point.
stmmac_setup_dma_desc() is also not the only caller. stmmac_xdp_open()
calls alloc_dma_desc_resources() on the persistent priv->dma_conf:
ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
if (ret < 0) {
netdev_err(dev, "%s: DMA descriptors allocation failed\n",
__func__);
goto dma_desc_error;
}
Before this patch, the RX resources on that path were not leaked, because a
later release freed them. Now they are freed early inside
alloc_dma_desc_resources(), and priv->dma_conf still holds the pointers.
Could the commit message mention this caller and explain how the change
affects it?
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 7ffed295eb14a..3f9f3b7878c20 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -2450,6 +2450,8 @@ static int alloc_dma_desc_resources(struct stmmac_priv *priv,
> return ret;
>
> ret = alloc_dma_tx_desc_resources(priv, dma_conf);
> + if (ret)
> + free_dma_rx_desc_resources(priv, dma_conf);
[Severity: High]
Can this turn into a double free on the stmmac_xdp_open() path?
stmmac_xdp_set_prog() calls stmmac_xdp_release() and then
stmmac_xdp_open() when the interface is running.
stmmac_xdp_release() frees everything with
free_dma_desc_resources(priv, &priv->dma_conf), and stmmac_xdp_open()
then calls alloc_dma_desc_resources() directly on the persistent
priv->dma_conf. It does not use a temporary copy the way
stmmac_setup_dma_desc() does.
If the RX side succeeds and the TX side fails there, this new call
frees the new RX descriptor rings, rx_q->buf_pool and rx_q->page_pool.
__free_dma_rx_desc_resources() does not clear rx_q->dma_rx,
rx_q->dma_erx, rx_q->buf_pool or rx_q->page_pool afterwards, so
priv->dma_conf.rx_queue[] is left holding freed pointers.
stmmac_xdp_set_prog() ignores the return value of stmmac_xdp_open(),
so the device stays IFF_UP. The next __stmmac_release(), MTU change or
XDP toggle calls free_dma_desc_resources(priv, &priv->dma_conf) again.
That would read the freed buf_pool in dma_free_rx_skbufs(), and then
kfree() buf_pool, page_pool_destroy() the page_pool and
dma_free_coherent() the rings a second time.
Before this patch the RX side of that path was only freed once, by the
later release. The TX side already had the same problem, since
__free_dma_tx_desc_resources() leaves tx_q->dma_tx, tx_q->dma_etx,
tx_q->dma_entx, tx_q->tx_skbuff_dma and tx_q->tx_skbuff dangling, and
a partial failure in either allocator can unwind stale pointers left
over from stmmac_xdp_release().
Should the free helpers reset these pointers to NULL? Or should
stmmac_xdp_open() build a new dma_conf and only install it on success
the way stmmac_setup_dma_desc() does? Either way, it seems like this
needs to be handled before the early RX free is safe for every caller
of alloc_dma_desc_resources().
[Severity: High]
This is a pre-existing issue, but can the TX unwind oops before this new
free_dma_rx_desc_resources() call is reached?
stmmac_setup_dma_desc() allocates dma_conf with kzalloc_obj(), so
tx_skbuff_dma and tx_skbuff start out NULL for every TX queue.
Say __alloc_dma_tx_desc_resources() fails for queue k. The err_dma label in
alloc_dma_tx_desc_resources() then unwinds all tx_queues_to_use queues,
including queue k and the queues after it that were never allocated:
alloc_dma_tx_desc_resources()
free_dma_tx_desc_resources()
__free_dma_tx_desc_resources()
dma_free_tx_skbufs()
stmmac_free_tx_buffer()
stmmac_free_tx_buffer() reads the arrays without checking them:
if (tx_q->tx_skbuff_dma[i].buf &&
tx_q->tx_skbuff_dma[i].buf_type != STMMAC_TXBUF_T_XDP_TX) {
...
if (tx_q->xdpf[i] &&
Wouldn't this dereference NULL when tx_skbuff_dma was never allocated? And
when only the tx_skbuff allocation failed, wouldn't the read of xdpf[i] (a
union alias of tx_skbuff) do the same?
The only TX failure the unwind seems to survive is a dma_alloc_coherent()
failure on the last TX queue, because dma_free_coherent() returns early for
a NULL cpu_addr. That would mean the path this patch targets still oopses
in most cases.
alloc_dma_rx_desc_resources() looks like it has the same problem.
stmmac_free_rx_buffer() does:
struct stmmac_rx_buffer *buf = &rx_q->buf_pool[i];
if (buf->page)
buf_pool is still NULL at that point if page_pool_create() or the buf_pool
allocation failed, or if the queue was never allocated.
>
> return ret;
> }
[Severity: Low]
This isn't a bug introduced by this patch, but the kernel-doc above
alloc_dma_desc_resources() says the following, and the same text appears on
__alloc_dma_rx_desc_resources() and __alloc_dma_tx_desc_resources():
* this function allocates the resources for TX and RX paths. In case of
* reception, for example, it pre-allocated the RX socket buffer in order to
* allow zero-copy mechanism.
None of these functions allocate RX buffers. That happens later, in
init_dma_desc_rings().
The comment also has no Return: section. Both callers now rely on
everything being released already when the function fails, and that is not
written down anywhere.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103102857.1340748-1-vulab%40iscas.ac.cn
Technical Details
Message-ID:
<179405595688.994134.1843500788974971566@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358368-linux-kernel-netdev=dewy.ruReferences:
<20261103102857.1340748-1-vulab@iscas.ac.cn>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358368-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH] net: stmmac: free RX resources when TX allocation fails Date: Sat, 07 Nov 2026 12:52:36 +0000 Organization: Usenet Network Message-ID: <179405595688.994134.1843500788974971566@kernel.org> References: <20261103102857.1340748-1-vulab@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4105135"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:pPwZ1VQD6wJ2je85ASVCb1iwBms= sha256:lq8Z9RsfPjmjomyqo/gpctPM9E7vx1l/s8kot8tFUMA= sha1:kEG38uMOZVYPhGFuYgXPtJh0GoE= sha256:/DM2ldSQm9hipk26E5mx2fMzwr5s9MVjeVb8NDqrH2s= 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 D3319113419; Sat, 7 Nov 2026 15:53:24 +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 17n3uG2yJkQU; Sat, 7 Nov 2026 15:53:13 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358368-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 AAE19113415; Sat, 7 Nov 2026 15:53:03 +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 BDB0A2F752; Sat, 7 Nov 2026 12:52:39 +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=1794055959; b=VaM0DIyeeDaYhQ5jLx33g2dOWkcgMPyIjTTJTGlp/nHzjJzHuHmJc/Xz4/Cz5U7z0bhI SunEhE1fWZR0wOMCpNkMPpLB83UKYBl93zPZoaXMvgKtNGiITk9dqWEfXznajs/VcMEtS b6c/xhgTu8aHc7pBgnyMWSZzxKdPRJSw26ywrw9YTY2w4LhCpt/GuuPgBQAbp3mihAp9N PEOv9mjnzj0OL2kOkj4DOntr+fI4Dx8cK6XSk0sDaABDZ/sGBD2aYSqggmpIEK8Rx88KD y94xCFVqR9nhqHs/I4UAFQhORRfaqjGWB5zkKPrR1+Q84AdbNJ/vKIlnsybLlq0u17A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794055959; 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=Dz4nU+XktsAws1dehkwjm0qCQeZEQukoJ/eEOgzjJmw=; b=1cQm+wwItJ1ECaTCSVcHaknuiQdMVDHusxwfIjdZ1Mo34wKRhpY23GFwKa77ytMGNQCL Mn+O3hCCNZY8apSm58TZSkRW7P+Kt4bMmOZEwXPZYQiiaoKGeL+foRNnOMnXnnd4nEQic cUt8jmgroTCYE0s3JU2MPVp0tzPlwuPM2nwHx5sYT+XSYdfjuwn3JUAJ2TSNrAy9jT944 8z63Ap/Ivo9FrU6ZwGYU2nVGZSHmQXQOj5KP9H6ENSkpwPlbAG28ggvoHe2habnOu/hvc y5mQB+CFTv4Vitc24iSbau1A1aGiTr1IrF8l5A3+oSU5TRzdOz3+tmgm+gul7WaghkA== 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="CW/Xjxlz"; 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 96D44606A334; Sat, 7 Nov 2026 12:52:39 +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=CW/Xjxlz 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=1794055958; b=UCzg3qYxUv2yGuH8lri2/GHLf/9kWuqYbTJOhGgCY/DQ8AGmXVPGS0CJ7HkeQXuXv88P E0VezMhuqexxVuYQ20gwn0hTA5dXKiEoIe64VfA9txEzEnCO61BlG9DjfMtxwNAiBS3fr fBlYZXXsJ/NYqAMR9JGoJ2UP1q/LVPHD9uFc1vGX7oYbDw5e3S19CdHxxYFe98h2BsXti lkItWK09CJV9UD3VRO4gAhZomWUpFg+I6DCArfq7AtOS7dN5TmoiT+KQgH6ytIk7gw8ZT v6TwSPedBMQqdomumC5otGsR2RNuqjxefkh6CEL87PLQkQlL19qZfohpPpYqL5dRFjQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794055958; 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=Dz4nU+XktsAws1dehkwjm0qCQeZEQukoJ/eEOgzjJmw=; b=4KRKS9wnHqVNB6Fn/HYfq3iTjQzm/ZS5Z6f8rUnv+xaW/oGP1tI9+ih705ovmXWUzgo0 NOechnTSEPGHOesmZXD/NDkCLYslhib6WCuAh8gC7GUSxC76d1gq0tyngvjlT1UW9/p6w ooQih5WB+NouLIubf3TaBbUJOCQpSiELgiZqN9txOs+Wjbb9ifUrmCX1+6AIpWeC4PqG2 mpL1z0sKlbmlZx+bZLpkYZDpRleBrzZNk67J7L2d2XS3Q0+UL1IQNwaARuuQu9HSG/4ia 5J/1lw1gHgbyAj6kfxISgMrST+us/+J6zixFFAC/HEEJez5I67X8KhiRxvkBNzwmgwQ== 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="CW/Xjxlz"; 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 6FF41606A332; Sat, 7 Nov 2026 12:52:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB991F0089F; Sat, 7 Nov 2026 12:52:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794055958; bh=Dz4nU+XktsAws1dehkwjm0qCQeZEQukoJ/eEOgzjJmw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=CW/XjxlzDTg1aVQdaW7JqzCU9aaRZxg62YnM+vgqwA4flyextgxB4VK1ac/IZ1+v8 Cld5GUjoR/e3mRH/HCVPROmI+GqeAVSCy0MnXbulfqi3Wg3TcDyaUu8OJ0KPQ9C4i+ l5t5U3OLiP7rQ9LyRNqBdmyAEfWssgWcaIleDJl3djI003zeCK49MptH2JveNn6Sj0 IYM96xWfsnZsLVEpC461U6Y9DFgP8aRtUIMcm4BCbGuF+ws5liDWWlFWiQN/0ZkVSx 3uMyOs5gUS7S2Iidi1R4Zoizlq2D/QeYDvO73S//iARvwmixC1nJu8Uktg24qnjpqD UhmvdKDI8T73A== X-Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-In-Reply-To: <20261103102857.1340748-1-vulab@iscas.ac.cn> 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