Skip to content

Commit c5ebaca

Browse files
shayshyigregkh
authored andcommitted
RDMA/core: Add CM to restrack after successful attachment to a device
[ Upstream commit cb5cd0e ] The device attach triggers addition of CM_ID to the restrack DB. However, when error occurs, we releasing this device, but defer CM_ID release. This causes to the situation where restrack sees CM_ID that is not valid anymore. As a solution, add the CM_ID to the resource tracking DB only after the attachment is finished. Found by syzcaller: infiniband syz0: added syz_tun rdma_rxe: ignoring netdev event = 10 for syz_tun infiniband syz0: set down infiniband syz0: ib_query_port failed (-19) restrack: ------------[ cut here ]------------ infiniband syz0: BUG: RESTRACK detected leak of resources restrack: User CM_ID object allocated by syz-executor716 is not freed restrack: ------------[ cut here ]------------ Fixes: b09c4d7 ("RDMA/restrack: Improve readability in task name management") Link: https://lore.kernel.org/r/ab93e56ba831eac65c322b3256796fa1589ec0bb.1618753862.git.leonro@nvidia.com Signed-off-by: Shay Drory <shayd@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 63c61d2 commit c5ebaca

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • drivers/infiniband/core

‎drivers/infiniband/core/cma.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ static void _cma_attach_to_dev(struct rdma_id_private *id_priv,
463463
id_priv->id.route.addr.dev_addr.transport =
464464
rdma_node_get_transport(cma_dev->device->node_type);
465465
list_add_tail(&id_priv->list, &cma_dev->id_list);
466-
rdma_restrack_add(&id_priv->res);
467466

468467
trace_cm_id_attach(id_priv, cma_dev->device);
469468
}
@@ -700,6 +699,7 @@ static int cma_ib_acquire_dev(struct rdma_id_private *id_priv,
700699
mutex_lock(&lock);
701700
cma_attach_to_dev(id_priv, listen_id_priv->cma_dev);
702701
mutex_unlock(&lock);
702+
rdma_restrack_add(&id_priv->res);
703703
return 0;
704704
}
705705

@@ -754,8 +754,10 @@ static int cma_iw_acquire_dev(struct rdma_id_private *id_priv,
754754
}
755755

756756
out:
757-
if (!ret)
757+
if (!ret) {
758758
cma_attach_to_dev(id_priv, cma_dev);
759+
rdma_restrack_add(&id_priv->res);
760+
}
759761

760762
mutex_unlock(&lock);
761763
return ret;
@@ -816,6 +818,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
816818

817819
found:
818820
cma_attach_to_dev(id_priv, cma_dev);
821+
rdma_restrack_add(&id_priv->res);
819822
mutex_unlock(&lock);
820823
addr = (struct sockaddr_ib *)cma_src_addr(id_priv);
821824
memcpy(&addr->sib_addr, &sgid, sizeof(sgid));
@@ -2529,6 +2532,7 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv,
25292532
rdma_addr_size(cma_src_addr(id_priv)));
25302533

25312534
_cma_attach_to_dev(dev_id_priv, cma_dev);
2535+
rdma_restrack_add(&dev_id_priv->res);
25322536
cma_id_get(id_priv);
25332537
dev_id_priv->internal_id = 1;
25342538
dev_id_priv->afonly = id_priv->afonly;
@@ -3169,6 +3173,7 @@ static int cma_bind_loopback(struct rdma_id_private *id_priv)
31693173
ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey);
31703174
id_priv->id.port_num = p;
31713175
cma_attach_to_dev(id_priv, cma_dev);
3176+
rdma_restrack_add(&id_priv->res);
31723177
cma_set_loopback(cma_src_addr(id_priv));
31733178
out:
31743179
mutex_unlock(&lock);
@@ -3201,6 +3206,7 @@ static void addr_handler(int status, struct sockaddr *src_addr,
32013206
if (status)
32023207
pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to acquire device. status %d\n",
32033208
status);
3209+
rdma_restrack_add(&id_priv->res);
32043210
} else if (status) {
32053211
pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to resolve IP. status %d\n", status);
32063212
}
@@ -3812,6 +3818,8 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
38123818
if (ret)
38133819
goto err2;
38143820

3821+
if (!cma_any_addr(addr))
3822+
rdma_restrack_add(&id_priv->res);
38153823
return 0;
38163824
err2:
38173825
if (id_priv->cma_dev)

0 commit comments

Comments
 (0)