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 B4FED29A0; Wed, 7 May 2025 19:03:43 +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=1746644623; cv=none; b=AlGm7CTZf6dyW1Ro6/68LDdDsty7QzlwgNks1NHn5qdKNdui+6MW6j757YhRWT2YlwoUkeMCqIMeoJM3ImVhnhhHYS8EsbIQyWF4Bg7jw43xnJHthS2/r6ItMf3M7VkE5VNYscei1kOMjoTIbeIA55HiZhTag5D5ZvNJaN9IyXk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746644623; c=relaxed/simple; bh=9knOvM9ar0pZTWL0rY4C6BKkhq5RkiMOp7ane6Hn7XI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nP0y6/Fb4fqYWj/yxBTNCsxTbjzNiMo2cSAQ4FEeJdE1mz6rPEOM3ehNItGtrkkCNtICbMYBwqrAC9vc7utRiVji6bMUX5BiVyAini2jtZZI0w9uDI1QsrdKXTsAICI4dhWjurdqRw3SNYlSfIlyyre3cbuCCTBJzqKiJFDBdPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NT2pGNVo; 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="NT2pGNVo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1763C4CEE2; Wed, 7 May 2025 19:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1746644623; bh=9knOvM9ar0pZTWL0rY4C6BKkhq5RkiMOp7ane6Hn7XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NT2pGNVoQ4QQuY0+mLG5x3GeN80L+de6cR02EdxnHZ5ZOf/OI/FQELwpzOlGSfKad 2+ZiEh0GdPTIY3gMzmtoyOolVDVGJeGbNEi3B6F/srmxYXo6MOxaXF5UeI+ReC+iLN 84Ib+jE8bhUv7DpOJFKOg8dFVwneD+JJhRxkHc1g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pavan Kumar Linga , Aleksandr Loktionov , Michal Swiatkowski , Simon Horman , Samuel Salin , Tony Nguyen , Sasha Levin Subject: [PATCH 6.12 104/164] idpf: fix potential memory leak on kcalloc() failure Date: Wed, 7 May 2025 20:39:49 +0200 Message-ID: <20250507183825.185383318@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250507183820.781599563@linuxfoundation.org> References: <20250507183820.781599563@linuxfoundation.org> User-Agent: quilt/0.68 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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Swiatkowski [ Upstream commit 8a558cbda51bef09773c72bf74a32047479110c7 ] In case of failing on rss_data->rss_key allocation the function is freeing vport without freeing earlier allocated q_vector_idxs. Fix it. Move from freeing in error branch to goto scheme. Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport") Reviewed-by: Pavan Kumar Linga Reviewed-by: Aleksandr Loktionov Suggested-by: Pavan Kumar Linga Signed-off-by: Michal Swiatkowski Reviewed-by: Simon Horman Tested-by: Samuel Salin Signed-off-by: Tony Nguyen Signed-off-by: Sasha Levin --- drivers/net/ethernet/intel/idpf/idpf_lib.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c index 1c345a0e885b7..5ce663d04de00 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c @@ -1108,11 +1108,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, num_max_q = max(max_q->max_txq, max_q->max_rxq); vport->q_vector_idxs = kcalloc(num_max_q, sizeof(u16), GFP_KERNEL); - if (!vport->q_vector_idxs) { - kfree(vport); + if (!vport->q_vector_idxs) + goto free_vport; - return NULL; - } idpf_vport_init(vport, max_q); /* This alloc is done separate from the LUT because it's not strictly @@ -1122,11 +1120,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, */ rss_data = &adapter->vport_config[idx]->user_config.rss_data; rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL); - if (!rss_data->rss_key) { - kfree(vport); + if (!rss_data->rss_key) + goto free_vector_idxs; - return NULL; - } /* Initialize default rss key */ netdev_rss_key_fill((void *)rss_data->rss_key, rss_data->rss_key_size); @@ -1139,6 +1135,13 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, adapter->next_vport = idpf_get_free_slot(adapter); return vport; + +free_vector_idxs: + kfree(vport->q_vector_idxs); +free_vport: + kfree(vport); + + return NULL; } /** -- 2.39.5