Skip to content

Commit

Permalink
IB/mlx4: Fix error paths in mlx4_ib_create_flow()
Browse files Browse the repository at this point in the history
The unwinding clean up code are err_create_flow starts at the current
index i.  That means we shouldn't increment i until we're really sure
we won't have to destroy the current flow; otherwise we might
increment the index, fail inside an is_bonded block, and end up
accessing off the end of the reg_id[] array.

This was detected by Coverity (CID 1271229).

Signed-off-by: Roland Dreier <roland@purestorage.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
  • Loading branch information
Roland Dreier authored and Doug Ledford committed Jun 2, 2015
1 parent 18eaf1f commit 1156256
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/infiniband/hw/mlx4/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,6 @@ static struct ib_flow *mlx4_ib_create_flow(struct ib_qp *qp,
&mflow->reg_id[i].id);
if (err)
goto err_create_flow;
i++;
if (is_bonded) {
/* Application always sees one port so the mirror rule
* must be on port #2
Expand All @@ -1200,14 +1199,15 @@ static struct ib_flow *mlx4_ib_create_flow(struct ib_qp *qp,
j++;
}

i++;
}

if (i < ARRAY_SIZE(type) && flow_attr->type == IB_FLOW_ATTR_NORMAL) {
err = mlx4_ib_tunnel_steer_add(qp, flow_attr,
&mflow->reg_id[i].id);
if (err)
goto err_create_flow;
i++;

if (is_bonded) {
flow_attr->port = 2;
err = mlx4_ib_tunnel_steer_add(qp, flow_attr,
Expand All @@ -1218,6 +1218,7 @@ static struct ib_flow *mlx4_ib_create_flow(struct ib_qp *qp,
j++;
}
/* function to create mirror rule */
i++;
}

return &mflow->ibflow;
Expand Down

0 comments on commit 1156256

Please sign in to comment.