Skip to contentSkip to conversation

net/mlx5e: Fix potential null pointer dereference

PATCH Applied Gustavo A. R. Silva 3 participants 4 messages Sep 25, 2020 – Sep 29, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5e: Fix potential null pointer dereference

Calls to kzalloc() and kvzalloc() should be null-checked in order to avoid any potential failures. In this case, a potential null pointer dereference.

Fix this by adding null checks for _parse_attr_ and _flow_ right after allocation.

Addresses-Coverity-ID: 1497154 ("Dereference before null check")

Fixes c620b772152b ("net/mlx5: Refactor tc flow attributes structure")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +6 -4
index f815b0c60a6c..fb27154bfddb 100644
@@ -4534,20 +4534,22 @@ mlx5e_alloc_flow(struct mlx5e_priv *priv, int attr_size,
 	struct mlx5e_tc_flow_parse_attr *parse_attr;
 	struct mlx5_flow_attr *attr;
 	struct mlx5e_tc_flow *flow;
-	int out_index, err;
+	int err = -ENOMEM;
+	int out_index;
 
 	flow = kzalloc(sizeof(*flow), GFP_KERNEL);
 	parse_attr = kvzalloc(sizeof(*parse_attr), GFP_KERNEL);
+	if (!parse_attr || !flow)
+		goto err_free;
 
 	flow->flags = flow_flags;
 	flow->cookie = f->cookie;
 	flow->priv = priv;
 
 	attr = mlx5_alloc_flow_attr(get_flow_name_space(flow));
-	if (!parse_attr || !flow || !attr) {
-		err = -ENOMEM;
+	if (!attr)
 		goto err_free;
-	}
+
 	flow->attr = attr;
 
 	for (out_index = 0; out_index < MLX5_MAX_FLOW_FWD_VPORTS; out_index++)
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Gustavo A. R. Silva

Calls to kzalloc() and kvzalloc() should be null-checked in order to avoid any potential failures. In this case, a potential null pointer dereference.

Fix this by adding null checks for _parse_attr_ and _flow_ right after allocation.

Quoted 7 lines

Addresses-Coverity-ID: 1497154 ("Dereference before null check")

Fixes c620b772152b ("net/mlx5: Refactor tc flow attributes structure")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Thanks,

#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 4 lines · Gustavo A. R. Silva

Calls to kzalloc() and kvzalloc() should be null-checked in order to avoid any potential failures. In this case, a potential null pointer dereference.

Quoted 9 lines

Fix this by adding null checks for _parse_attr_ and _flow_ right after allocation.

Addresses-Coverity-ID: 1497154 ("Dereference before null check")

Fixes c620b772152b ("net/mlx5: Refactor tc flow attributes

structure")

---

Applied to net-next-mlx5.
Thanks.

#3 lore raw
Quoted 8 lines · Saeed Mahameed
Quoted 7 lines · Gustavo A. R. Silva

Calls to kzalloc() and kvzalloc() should be null-checked in order to avoid any potential failures. In this case, a potential null pointer dereference.

Fix this by adding null checks for _parse_attr_ and _flow_ right after allocation.

Quoted 8 lines
Quoted 6 lines

Addresses-Coverity-ID: 1497154 ("Dereference before null check")

Fixes c620b772152b ("net/mlx5: Refactor tc flow attributes

structure")

---

Applied to net-next-mlx5.

Thank you both. :)
--
Gustavo