RDMA/core: Add CM to restrack after successful attachment to a device
authorShay Drory <shayd@nvidia.com>
Sun, 18 Apr 2021 13:55:54 +0000 (16:55 +0300)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 21 Apr 2021 23:53:14 +0000 (20:53 -0300)
commitcb5cd0ea4eb3ce338a593a5331ddb4986ae20faa
tree7762916197bcba1b17902188b48e9ed6eb899178
parent4d51c3d9de4bf5b9d637966dce9d1df77ed93288
RDMA/core: Add CM to restrack after successful attachment to a device

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: b09c4d701220 ("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>
drivers/infiniband/core/cma.c