RDMA/cma: Fix deadlock on &lock in rdma_cma_listen_on_all() error unwind
authorJason Gunthorpe <jgg@nvidia.com>
Wed, 18 Nov 2020 13:33:23 +0000 (09:33 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 30 Dec 2020 10:53:22 +0000 (11:53 +0100)
commitf85d05c0a599ede6f161988ab6eea1a62b1b400f
tree0d34781ba30848f6f55c940dd2d08f3b2a633cdd
parent98e72ffe934d0e9879a4620d1d8762ca34c1476f
RDMA/cma: Fix deadlock on &lock in rdma_cma_listen_on_all() error unwind

[ Upstream commit dd37d2f59eb839d51b988f6668ce5f0d533b23fd ]

rdma_detroy_id() cannot be called under &lock - we must instead keep the
error'd ID around until &lock can be released, then destroy it.

This is complicated by the usual way listen IDs are destroyed through
cma_process_remove() which can run at any time and will asynchronously
destroy the same ID.

Remove the ID from visiblity of cma_process_remove() before going down the
destroy path outside the locking.

Fixes: c80a0c52d85c ("RDMA/cma: Add missing error handling of listen_id")
Link: https://lore.kernel.org/r/20201118133756.GK244516@ziepe.ca
Reported-by: syzbot+1bc48bf7f78253f664a9@syzkaller.appspotmail.com
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/core/cma.c