From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 969BF2E92B3; Sat, 30 May 2026 16:58:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780160297; cv=none; b=uFDPbToeGAIuzMoS8pfG9K7zVaBtZY97yyVyiCCEjsiYoeZU8BFLtuN0exiUxUabRxY60tv6vKBghcYKwExehQ7xrLiL5xduu9mibCr0mTWlEaOAyNkNKwCMXjQQzaqJk6nVC/d618/4QZG04GVD1U+Ev7+azwAjMNdudoyCt/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780160297; c=relaxed/simple; bh=mnSeUUDroYhjOCRNP5neHL4zAQ7x2yOjCONEO979UEY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U/j0vFYwL4wYXp/G35B2Gl2gemTaQo5FEciTZvSdhUk5XpDhuvYDe+2z8BoaF0kLXT+ajBVjoeie2NKgX+A9mGRoMXvDJgq74lbLuTOV+MemvcsU8veUrk3gm9lDB4ZTa4kBMP9u1CsGf4jmhUbdtJtK+qAsWAWPD6dpKGJpE9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DxoWMZfc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DxoWMZfc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA06B1F00893; Sat, 30 May 2026 16:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780160296; bh=b+ipQM2fc+p9CHiPW2Tmit4I0+7Cd5YTylV1yBDTNAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DxoWMZfc0MtCDky9tlb2qm3AfHKMCwYf8JuDUQCyaEgFNsHsr9Kav+x3hCA5SaGu9 aMDUvydOp7bHoOm6z6aAE55XbfpT5D+VOzVZqX4sgtB5oSB42yq0mflQVzEFhIT7ZB DtyR16UuHWq0viuEBFvawBdzJ1bTD86RAOhGCIXo= 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.1 298/969] ice: Fix memory leak in ice_set_ringparam() Date: Sat, 30 May 2026 17:57:02 +0200 Message-ID: <20260530160308.670180238@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160300.485627683@linuxfoundation.org> References: <20260530160300.485627683@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 49c524304a412..7774292a5bdbe 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.53.0