From patchwork Wed Jan 24 08:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13528783 X-Patchwork-Delegate: kuba@kernel.org 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 9149B17981 for ; Wed, 24 Jan 2024 08:19:24 +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=1706084364; cv=none; b=C1VX+5KGxKVDszNvfpqaLJU8El7uLd7NM4SN1nvnEH6y/+DKSmSSpAnwTY8tarXRNpXkX7Jw4uFHucRJjPepKkUzFk9Q2tWtuliKENV7jLroxbA6MQfodSWCSuEyCgvoN2UdU+9gBUqT3IkKYmffVuizkOkQLMHkgUO9jCJ+Zn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706084364; c=relaxed/simple; bh=5l6HGg5ZcAnvS4zxp2OhGZkwdESarPuFUb1NH0AXCo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o0al65jylclrpKw/7V5MhhSRkDBkZ2aH5NwBzahvJ4h4EY5pO1bvyf6XUp4g/MgHRDiyx35nCsBIyf2p6o1jEDhZo5w4gSLQMnadZQvowpOdLTRPiiJ5t1ZQdGy263W/uFHUwfohXKbsJsY5spsrXiH9z4jtBlqgl3MsqVZDlkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ICMzPZN3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ICMzPZN3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4DDFC433F1; Wed, 24 Jan 2024 08:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706084364; bh=5l6HGg5ZcAnvS4zxp2OhGZkwdESarPuFUb1NH0AXCo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ICMzPZN3ax//kiIRVWCmFSFcg0nryFIX6SyCVxdFnopvlVJP5DThi7gQtJBsLDYxM r5m4pcYjOKRO27zpoaqt0xhuP9bBHyzUVWxFYtvzJzmGR4fSUZ0+N4C9UdqH/5R7a7 yfk8D74ya2GDJhcsyoOp8a5lEfL+glwIkyjh7d184ZLDEhKMPtwjMyV54Sk47O2Qlr 8/WTm1QP2YeVfDH76p2eBIi9lRNWLzT2i9c5GDQS90JBP7uShGoUrlqI5MFVlbX/9j xwVyyI+2+pqFSfoUIfZ/rWCdYZwxepl+X3uetHt9zbrtlhSXymOUvrGbvYy3adU/kB OHfezTkSeGngA== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Zhipeng Lu , Simon Horman Subject: [net 13/14] net/mlx5e: fix a double-free in arfs_create_groups Date: Wed, 24 Jan 2024 00:18:54 -0800 Message-ID: <20240124081855.115410-14-saeed@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124081855.115410-1-saeed@kernel.org> References: <20240124081855.115410-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Zhipeng Lu When `in` allocated by kvzalloc fails, arfs_create_groups will free ft->g and return an error. However, arfs_create_table, the only caller of arfs_create_groups, will hold this error and call to mlx5e_destroy_flow_table, in which the ft->g will be freed again. Fixes: 1cabe6b0965e ("net/mlx5e: Create aRFS flow tables") Signed-off-by: Zhipeng Lu Reviewed-by: Simon Horman Signed-off-by: Saeed Mahameed --- .../net/ethernet/mellanox/mlx5/core/en_arfs.c | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c index bb7f86c993e5..e66f486faafe 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c @@ -254,11 +254,13 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, ft->g = kcalloc(MLX5E_ARFS_NUM_GROUPS, sizeof(*ft->g), GFP_KERNEL); - in = kvzalloc(inlen, GFP_KERNEL); - if (!in || !ft->g) { - kfree(ft->g); - kvfree(in); + if (!ft->g) return -ENOMEM; + + in = kvzalloc(inlen, GFP_KERNEL); + if (!in) { + err = -ENOMEM; + goto err_free_g; } mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria); @@ -278,7 +280,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, break; default: err = -EINVAL; - goto out; + goto err_free_in; } switch (type) { @@ -300,7 +302,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, break; default: err = -EINVAL; - goto out; + goto err_free_in; } MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS); @@ -309,7 +311,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, MLX5_SET_CFG(in, end_flow_index, ix - 1); ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in); if (IS_ERR(ft->g[ft->num_groups])) - goto err; + goto err_clean_group; ft->num_groups++; memset(in, 0, inlen); @@ -318,18 +320,20 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, MLX5_SET_CFG(in, end_flow_index, ix - 1); ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in); if (IS_ERR(ft->g[ft->num_groups])) - goto err; + goto err_clean_group; ft->num_groups++; kvfree(in); return 0; -err: +err_clean_group: err = PTR_ERR(ft->g[ft->num_groups]); ft->g[ft->num_groups] = NULL; -out: +err_free_in: kvfree(in); - +err_free_g: + kfree(ft->g); + ft->g = NULL; return err; }