Skip to content

Commit 6e05197

Browse files
committed
RDMA/siw: Fix potential siw_mem refcnt leak in siw_fastreg_mr()
siw_fastreg_mr() invokes siw_mem_id2obj(), which returns a local reference of the siw_mem object to "mem" with increased refcnt. When siw_fastreg_mr() returns, "mem" becomes invalid, so the refcount should be decreased to keep refcount balanced. The issue happens in one error path of siw_fastreg_mr(). When "base_mr" equals to NULL but "mem" is not NULL, the function forgets to decrease the refcnt increased by siw_mem_id2obj() and causes a refcnt leak. Reorganize the flow so that the goto unwind can be used as expected. Fixes: b9be6f1 ("rdma/siw: transmit path") Link: https://lore.kernel.org/r/[email protected] Reported-by: Xiyu Yang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c08cfb2 commit 6e05197

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/infiniband/sw/siw/siw_qp_tx.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,20 +920,27 @@ static int siw_fastreg_mr(struct ib_pd *pd, struct siw_sqe *sqe)
920920
{
921921
struct ib_mr *base_mr = (struct ib_mr *)(uintptr_t)sqe->base_mr;
922922
struct siw_device *sdev = to_siw_dev(pd->device);
923-
struct siw_mem *mem = siw_mem_id2obj(sdev, sqe->rkey >> 8);
923+
struct siw_mem *mem;
924924
int rv = 0;
925925

926926
siw_dbg_pd(pd, "STag 0x%08x\n", sqe->rkey);
927927

928-
if (unlikely(!mem || !base_mr)) {
928+
if (unlikely(!base_mr)) {
929929
pr_warn("siw: fastreg: STag 0x%08x unknown\n", sqe->rkey);
930930
return -EINVAL;
931931
}
932+
932933
if (unlikely(base_mr->rkey >> 8 != sqe->rkey >> 8)) {
933934
pr_warn("siw: fastreg: STag 0x%08x: bad MR\n", sqe->rkey);
934-
rv = -EINVAL;
935-
goto out;
935+
return -EINVAL;
936936
}
937+
938+
mem = siw_mem_id2obj(sdev, sqe->rkey >> 8);
939+
if (unlikely(!mem)) {
940+
pr_warn("siw: fastreg: STag 0x%08x unknown\n", sqe->rkey);
941+
return -EINVAL;
942+
}
943+
937944
if (unlikely(mem->pd != pd)) {
938945
pr_warn("siw: fastreg: PD mismatch\n");
939946
rv = -EINVAL;

0 commit comments

Comments
 (0)