RDMA/core: Fix race between destroy and release FD object
authorLeon Romanovsky <leonro@mellanox.com>
Thu, 23 Apr 2020 06:01:22 +0000 (09:01 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 May 2020 06:15:12 +0000 (08:15 +0200)
commit169b8b62717af0f05b1fa88bdf9efa3ba285b4d9
tree2391b81831016400b42f853191d31c694c5ea59d
parent1e12524f09a1597edba11dfdfe33aa5e997dabb8
RDMA/core: Fix race between destroy and release FD object

commit f0abc761bbb9418876cc4d1ebc473e4ea6352e42 upstream.

The call to ->lookup_put() was too early and it caused an unlock of the
read/write protection of the uobject after the FD was put. This allows a
race:

     CPU1                                 CPU2
 rdma_lookup_put_uobject()
   lookup_put_fd_uobject()
     fput()
   fput()
     uverbs_uobject_fd_release()
       WARN_ON(uverbs_try_lock_object(uobj,
       UVERBS_LOOKUP_WRITE));
   atomic_dec(usecnt)

Fix the code by changing the order, first unlock and call to
->lookup_put() after that.

Fixes: 3832125624b7 ("IB/core: Add support for idr types")
Link: https://lore.kernel.org/r/20200423060122.6182-1-leon@kernel.org
Suggested-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/core/rdma_core.c