Skip to content

Commit b006834

Browse files
rpearsonhpe-designjgunthorpe
authored andcommitted
RDMA/rxe: Fix ref count error in check_rkey()
There is a reference count error in error path code and a potential race in check_rkey() in rxe_resp.c. When looking up the rkey for a memory window the reference to the mw from rxe_lookup_mw() is dropped before a reference is taken on the mr referenced by the mw. If the mr is destroyed immediately after the call to rxe_put(mw) the mr pointer is unprotected and may end up pointing at freed memory. The rxe_get(mr) call should take place before the rxe_put(mw) call. All errors in check_rkey() call rxe_put(mw) if mw is not NULL but it was already called after the above. The mw pointer should be set to NULL after the rxe_put(mw) call to prevent this from happening. Fixes: cdd0b85 ("RDMA/rxe: Implement memory access through MWs") Link: https://lore.kernel.org/r/20230517211509.1819998-1-rpearsonhpe@gmail.com Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 9a3763e commit b006834

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

drivers/infiniband/sw/rxe/rxe_resp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,9 @@ static enum resp_states check_rkey(struct rxe_qp *qp,
489489
if (mw->access & IB_ZERO_BASED)
490490
qp->resp.offset = mw->addr;
491491

492-
rxe_put(mw);
493492
rxe_get(mr);
493+
rxe_put(mw);
494+
mw = NULL;
494495
} else {
495496
mr = lookup_mr(qp->pd, access, rkey, RXE_LOOKUP_REMOTE);
496497
if (!mr) {

0 commit comments

Comments
 (0)