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 495C91D5CE0 for ; Mon, 11 May 2026 09:22:22 +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=1778491348; cv=none; b=BjsG/6lUAe6mnJP8759xveWuKVi4ZSdkvTWBG0d4SvwtAzdmAn/R1cDz3UbIys736MUUPJjLgI11t1PXxSP4sIGA4FJl8Oh+ZPn6mKokN8PBj45JDeSK9y5e3laegp3KEdeBt+GDQz4a7rl7zM7YgGqFUDwy9E+DJ2sswBQqIQ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778491348; c=relaxed/simple; bh=HoSaM1UlbucZd0Cr7bcberwVZY/BM23sObMy79yqq+I=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=AaSm2CCaKogZhQTk4W0VtKvNBaGS07UQ7GvhZiaipgR9R8KWBiUTtLJzCnMJu8up79PPT/nD6B2Vz+ebDD+UZXoRw816q+n+QUY5K1+qmbOXPLa6JCYsSxFiZaiyQgZXuA5Ev/kac6prpUUWpRHMC3B4pM85nvSN2lA/CE+o8LU= 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=G52W5Tzi; 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="G52W5Tzi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=139.com; s=dkim; l=0; h=from:subject:message-id:to:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=G52W5Tzi3FtCTwgI2LuWTpNqxOwC+v4d35plZGtPNrjU3ol+dCo3TKRt4QNfWuwi8CaUuQBxaYugB /+403XzdFT7QVuwp6ySEEQa3jLeOk4D+4aNEJvo+19OTTnrUreKbnCOdv1VquHDpam/seW8NCNecuq VIDdrymBppl5XOTU= X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG:00000000 Received:from NTT-kernel-dev (unknown[106.121.140.153]) by rmsmtp-lg-appmail-02-12080 (RichMail) with SMTP id 2f306a019fc5df0-f34f4; Mon, 11 May 2026 17:22:15 +0800 (CST) X-RM-TRANSID:2f306a019fc5df0-f34f4 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.1.y] ice: Fix memory leak in ice_set_ringparam() Date: Mon, 11 May 2026 17:22:13 +0800 Message-Id: <20260511092213.3267-1-681739313@139.com> X-Mailer: git-send-email 2.35.3 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 49c524304a41..7774292a5bdb 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -2891,7 +2891,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) { @@ -2921,7 +2921,7 @@ ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, } kfree(rx_rings); err = -ENOMEM; - goto free_tx; + goto free_xdp; } } @@ -2972,6 +2972,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.35.3