From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from n169-110.mail.139.com (n169-110.mail.139.com [120.232.169.110]) (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 C73D53822B1 for ; Fri, 17 Apr 2026 09:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=120.232.169.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776417489; cv=none; b=bfdrLim21Fd1T0QYnisdtD+6rVtLYAWmkBHPLbSVvUl3lanbq6ASFOW/EL0FYkyJcsBkRpH8aixU7dZ5W09i2jpCKurOLQS187HWOI2tUj6qFZx33dmmqKX1QEI15FuW501aRv6C8ee2ud8cjXwWK4T3l+o0U1CzHPM0MF/SQj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776417489; c=relaxed/simple; bh=l/VsInp3cv5Y2ECuouOOnaCEWrth9QJ1JX3CLUiPCew=; h=From:To:Subject:Date:Message-Id; b=QsvK+rWmj9nADo6A2fHRFrSGo2xRKe23gXQUJXHcG8u8DDJRVgG61aN3sCcMerZJPE5csTGJhPrBrC+VF6+nrIrACqn6MrPWU2CJA1VI2kQPZw0R+Tfpp0J17vGrFkfSDd5Xtl+m8aT5rTNTOIziuq5BXepZF2DxIcwFRTX/Hz8= 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=dc+T+LvX; arc=none smtp.client-ip=120.232.169.110 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="dc+T+LvX" 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=dc+T+LvXCwbFfJ7Hda+PHZLx50DY2lJOqD+Indhm83fsD48C0d+2yRS2/pQscmzHKdIXwCue7aWI5 Hgi9NvoRWnKA+CwKWnaPWPJsnz392crdB2Lj7WxWrb6XswDxMUWdODPNa1gYecZCxzV6Qm1XiqRryj Nd9ibfYx+abzv5S8= 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-02-12080 (RichMail) with SMTP id 2f3069e1fac6f02-29b69; Fri, 17 Apr 2026 17:17:59 +0800 (CST) X-RM-TRANSID:2f3069e1fac6f02-29b69 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.6.y] ice: Fix memory leak in ice_set_ringparam() Date: Fri, 17 Apr 2026 17:17:53 +0800 Message-Id: <20260417091753.4175-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 448ca855df90..c254484e9b6b 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.17.1