Skip to content

Commit 3b01fe7

Browse files
Jack Morgensteindavem330
authored andcommitted
net/mlx4_core: Use-after-free causes a resource leak in flow-steering detach
mlx4_QP_FLOW_STEERING_DETACH_wrapper first removes the steering rule (which results in freeing the rule structure), and then references a field in this struct (the qp number) when releasing the busy-status on the rule's qp. Since this memory was freed, it could reallocated and changed. Therefore, the qp number in the struct may be incorrect, so that we are releasing the incorrect qp. This leaves the rule's qp in the busy state (and could possibly release an incorrect qp as well). Fix this by saving the qp number in a local variable, for use after removing the steering rule. Fixes: 2c473ae ("net/mlx4_core: Disallow releasing VF QPs which have steering rules") Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il> Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f0c16ba commit 3b01fe7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/ethernet/mellanox/mlx4/resource_tracker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4473,6 +4473,7 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
44734473
struct res_qp *rqp;
44744474
struct res_fs_rule *rrule;
44754475
u64 mirr_reg_id;
4476+
int qpn;
44764477

44774478
if (dev->caps.steering_mode !=
44784479
MLX4_STEERING_MODE_DEVICE_MANAGED)
@@ -4489,10 +4490,11 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
44894490
}
44904491
mirr_reg_id = rrule->mirr_rule_id;
44914492
kfree(rrule->mirr_mbox);
4493+
qpn = rrule->qpn;
44924494

44934495
/* Release the rule form busy state before removal */
44944496
put_res(dev, slave, vhcr->in_param, RES_FS_RULE);
4495-
err = get_res(dev, slave, rrule->qpn, RES_QP, &rqp);
4497+
err = get_res(dev, slave, qpn, RES_QP, &rqp);
44964498
if (err)
44974499
return err;
44984500

@@ -4517,7 +4519,7 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
45174519
if (!err)
45184520
atomic_dec(&rqp->ref_count);
45194521
out:
4520-
put_res(dev, slave, rrule->qpn, RES_QP);
4522+
put_res(dev, slave, qpn, RES_QP);
45214523
return err;
45224524
}
45234525

0 commit comments

Comments
 (0)