Received: from n169-112.mail.139.com (n169-112.mail.139.com [120.232.169.112]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03E1A35958 for ; Thu, 2 Apr 2026 08:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=120.232.169.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775118360; cv=none; b=REqe4ofh/JK1DfOQ0SwHDYypuJI7nlUvCMh/TH/5ypXEn8gbkNEtKbb9fenv0mlLXUIoB5wwk71LDPjJq13eyPrJZ6yfUbsbF4B4BPPTVsOHqXUtdRme4rS812Kgskv4bueT9HNxSD+Wrkz5SGyGNSTpb67/4z8Ov2FF8khnlHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775118360; c=relaxed/simple; bh=kw74a7MVwzQ7G4joZG7CvrVIxxfwrN3W4C9eUeO6LLk=; h=From:To:Subject:Date:Message-Id; b=mF16BODrt7va/alxagIYB12blConPrw3av6kvHokshLPQ7Mz7zLKYcpGiqM56Qw20Bir7tSfHIMuJluD2m3n7xupi05pRAmbTGmzHhnpTdVtz5U34D1zV5p42vqxeLSKtpHbLfQayO/uD+B38ADvRRhr4Gs7TkjzjOrqOzDM6jA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com; spf=pass smtp.mailfrom=139.com; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b=PZoC2sAc; arc=none smtp.client-ip=120.232.169.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=139.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b="PZoC2sAc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=139.com; s=dkim; l=0; h=from:subject:message-id:to; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=PZoC2sAcBRlcfS1R6Ky8AcFC7iQtNkfg7btIu6GjfWaZsQAwaYOaPa3liH4W92fzxUGzvcUZMbs95 P4cVks7agAe4rolHlsJQHSgs1wa1wbK1JvsthEmoJgPtOMmUUKCETEOTajKBhWpKScOJy0NBuX/S+c 85sXVzFnM+otkpQI= X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG:00000000 Received:from NTT-kernel-dev (unknown[183.241.248.246]) by rmsmtp-lg-appmail-22-12025 (RichMail) with SMTP id 2ef969ce273b095-7c830; Thu, 02 Apr 2026 16:22:21 +0800 (CST) X-RM-TRANSID:2ef969ce273b095-7c830 From: Rajani Kantha <681739313@139.com> To: zilin@seu.edu.cn, pmenzel@molgen.mpg.de, aleksandr.loktionov@intel.com, sx.rinitha@intel.com, anthony.l.nguyen@intel.com, stable@vger.kernel.org Subject: [PATCH 6.12.y] ice: Fix memory leak in ice_set_ringparam() Date: Thu, 2 Apr 2026 16:22:14 +0800 Message-Id: <20260402082214.17191-1-681739313@139.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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> --- 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 b2183d5670b8..337396d8beba 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -3323,7 +3323,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) { @@ -3353,7 +3353,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, } kfree(rx_rings); err = -ENOMEM; - goto free_tx; + goto free_xdp; } } @@ -3404,6 +3404,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.17.1