Skip to content

Commit c8f304d

Browse files
mustafakismailjgunthorpe
authored andcommitted
RDMA/irdma: Prevent QP use after free
There is a window where the poll cq may use a QP that has been freed. This can happen if a CQE is polled before irdma_clean_cqes() can clear the CQE's related to the QP and the destroy QP races to free the QP memory. then the QP structures are used in irdma_poll_cq. Fix this by moving the clearing of CQE's before the reference is removed and the QP is destroyed. Fixes: b48c24c ("RDMA/irdma: Implement device supported verb APIs") Link: https://lore.kernel.org/r/20230522155654.1309-3-shiraz.saleem@intel.com Signed-off-by: Mustafa Ismail <mustafa.ismail@intel.com> Signed-off-by: Shiraz Saleem <shiraz.saleem@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent ffe14de commit c8f304d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/infiniband/hw/irdma/verbs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,19 @@ static int irdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
522522
if (!iwqp->user_mode)
523523
cancel_delayed_work_sync(&iwqp->dwork_flush);
524524

525-
irdma_qp_rem_ref(&iwqp->ibqp);
526-
wait_for_completion(&iwqp->free_qp);
527-
irdma_free_lsmm_rsrc(iwqp);
528-
irdma_cqp_qp_destroy_cmd(&iwdev->rf->sc_dev, &iwqp->sc_qp);
529-
530525
if (!iwqp->user_mode) {
531526
if (iwqp->iwscq) {
532527
irdma_clean_cqes(iwqp, iwqp->iwscq);
533528
if (iwqp->iwrcq != iwqp->iwscq)
534529
irdma_clean_cqes(iwqp, iwqp->iwrcq);
535530
}
536531
}
532+
533+
irdma_qp_rem_ref(&iwqp->ibqp);
534+
wait_for_completion(&iwqp->free_qp);
535+
irdma_free_lsmm_rsrc(iwqp);
536+
irdma_cqp_qp_destroy_cmd(&iwdev->rf->sc_dev, &iwqp->sc_qp);
537+
537538
irdma_remove_push_mmap_entries(iwqp);
538539
irdma_free_qp_rsrc(iwqp);
539540

0 commit comments

Comments
 (0)