From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A31D3D5643; Fri, 24 Apr 2026 13:38:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777037896; cv=none; b=Ft01HdLSLz8Epv4sNQF+s1Hd5VDz2upe8byayUXM1ZYC6vvx/0lpxwKhm8udZODpDf1qdWkoeuInjiMHlZPGBZ27kKHPMfe6HJ7dxQXqkYUz/ZnwGOp/u6H8ftEAsfGMDofleatp1jV1L+bz0XYYEcqJaU86fjTIfmRWXcM8UkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777037896; c=relaxed/simple; bh=myJgHMK+7iXJ+sojBp6GmkQ8JUX9BzPF58xDvlP65ic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QfTfv6rBFA1By/cEBIpjqktaKSq93PE3FsjplYoX3O6T/5lJXvngogvlcYLW5u/m3iz1NS1C44OldGNGQOV55vOCjosMAdh1qrBDvimAEtushOJJHJCvnfjM1sSWeiOFRlXKwpy4amQpylhkJoYlQ/uVki4houD/Gx7lxCHugy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cup2WaiL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cup2WaiL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D731C19425; Fri, 24 Apr 2026 13:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1777037896; bh=myJgHMK+7iXJ+sojBp6GmkQ8JUX9BzPF58xDvlP65ic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cup2WaiLMmukOwfwziFc2lgeaUDcJiBb+hSxluaJOG225kTKnoMLL7q5c3z09CK8W LfCGsOASlhYwAVF7Fbb4P7JW9NbDHJpAgbXJ1jR0XB+Y0PWRu+dfbrtHuSO9K1CuI8 xIIhip1ikFiRyg6H7mBEr7ksImIkKTxm0G3nWO50= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zilin Guan , Paul Menzel , Aleksandr Loktionov , Tony Nguyen , Rajani Kantha <681739313@139.com>, Sasha Levin , Rinitha S Subject: [PATCH 6.6 111/166] ice: Fix memory leak in ice_set_ringparam() Date: Fri, 24 Apr 2026 15:30:25 +0200 Message-ID: <20260424132556.013809668@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260424132532.812258529@linuxfoundation.org> References: <20260424132532.812258529@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zilin Guan [ Upstream commit fe868b499d16f55bbeea89992edb98043c9de416 ] In ice_set_ringparam, tx_rings and xdp_rings are allocated before rx_rings. If the allocation of rx_rings fails, the code jumps to the done label leaking both tx_rings and xdp_rings. Furthermore, if the setup of an individual Rx ring fails during the loop, the code jumps to the free_tx label which releases tx_rings but leaks xdp_rings. Fix this by introducing a free_xdp label and updating the error paths to ensure both xdp_rings and tx_rings are properly freed if rx_rings allocation or setup fails. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: fcea6f3da546 ("ice: Add stats and ethtool support") Fixes: efc2214b6047 ("ice: Add support for XDP") Signed-off-by: Zilin Guan Reviewed-by: Paul Menzel Reviewed-by: Aleksandr Loktionov Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen Signed-off-by: Rajani Kantha <681739313@139.com> Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/ice/ice_ethtool.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c index 448ca855df901..c254484e9b6b2 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -2847,7 +2847,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL); if (!rx_rings) { err = -ENOMEM; - goto done; + goto free_xdp; } ice_for_each_rxq(vsi, i) { @@ -2877,7 +2877,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, } kfree(rx_rings); err = -ENOMEM; - goto free_tx; + goto free_xdp; } } @@ -2928,6 +2928,13 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, } goto done; +free_xdp: + if (xdp_rings) { + ice_for_each_xdp_txq(vsi, i) + ice_free_tx_ring(&xdp_rings[i]); + kfree(xdp_rings); + } + free_tx: /* error cleanup if the Rx allocations failed after getting Tx */ if (tx_rings) { -- 2.53.0