Skip to contentSkip to conversation

net/mlx5: fix use after free on Rx queue start

PATCH In review Dariusz Sosnowski 2 participants 2 messages Nov 9, 2023 – Nov 12, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5: fix use after free on Rx queue start

If RX queue is not started yet, then a mlx5_rxq_obj struct used for storing HW queue objects will be allocated and added to the list held in port's private data structure.
After that allocation, Rx queue HW object configuration is done. If that configuration failed, then mlx5_rxq_obj struct is freed, but not removed from the list. This causes an use after free bug, during error handling in mlx5_rxq_start(), where this deallocated struct was accessed during list cleanup.

This patch fixes that by inserting mlx5_rxq_obj struct to the list only after HW queue object configuration succeeded.

Fixes 09c2555303be ("net/mlx5: support shared Rx queue")
---
 drivers/net/mlx5/mlx5_trigger.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/mlx5/mlx5_trigger.c +3 -3
index 7bdb897612..88dc271a21 100644
@@ -226,17 +226,17 @@ mlx5_rxq_start(struct rte_eth_dev *dev)
 		if (rxq == NULL)
 			continue;
 		rxq_ctrl = rxq->ctrl;
-		if (!rxq_ctrl->started) {
+		if (!rxq_ctrl->started)
 			if (mlx5_rxq_ctrl_prepare(dev, rxq_ctrl, i) < 0)
 				goto error;
-			LIST_INSERT_HEAD(&priv->rxqsobj, rxq_ctrl->obj, next);
-		}
 		ret = priv->obj_ops.rxq_obj_new(rxq);
 		if (ret) {
 			mlx5_free(rxq_ctrl->obj);
 			rxq_ctrl->obj = NULL;
 			goto error;
 		}
+		if (!rxq_ctrl->started)
+			LIST_INSERT_HEAD(&priv->rxqsobj, rxq_ctrl->obj, next);
 		rxq_ctrl->started = true;
 	}
 	return 0;
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 22 lines

-----Original Message-----
From: Dariusz Sosnowski <[email protected]>
Sent: Thursday, November 9, 2023 7:58 PM
To: Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Suanming Mou <[email protected]>; Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>; [email protected]
Subject: [PATCH] net/mlx5: fix use after free on Rx queue start

If RX queue is not started yet, then a mlx5_rxq_obj struct used for storing HW queue objects will be allocated and added to the list held in port's private data structure.
After that allocation, Rx queue HW object configuration is done.
If that configuration failed, then mlx5_rxq_obj struct is freed, but not removed from the list. This causes an use after free bug, during error handling in mlx5_rxq_start(), where this deallocated struct was accessed during list cleanup.

This patch fixes that by inserting mlx5_rxq_obj struct to the list only after HW queue object configuration succeeded.

Quoted 6 lines
Fixes 09c2555303be ("net/mlx5: support shared Rx queue")

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh