linux/drivers/infiniband/hw
Dennis Dalessandro 3d2a9d6425 IB/hfi1: Ensure correct mm is used at all times
Two earlier bug fixes have created a security problem in the hfi1
driver. One fix aimed to solve an issue where current->mm was not valid
when closing the hfi1 cdev. It attempted to do this by saving a cached
value of the current->mm pointer at file open time. This is a problem if
another process with access to the FD calls in via write() or ioctl() to
pin pages via the hfi driver. The other fix tried to solve a use after
free by taking a reference on the mm.

To fix this correctly we use the existing cached value of the mm in the
mmu notifier. Now we can check in the insert, evict, etc. routines that
current->mm matched what the notifier was registered for. If not, then
don't allow access. The register of the mmu notifier will save the mm
pointer.

Since in do_exit() the exit_mm() is called before exit_files(), which
would call our close routine a reference is needed on the mm. We rely on
the mmgrab done by the registration of the notifier, whereas before it was
explicit. The mmu notifier deregistration happens when the user context is
torn down, the creation of which triggered the registration.

Also of note is we do not do any explicit work to protect the interval
tree notifier. It doesn't seem that this is going to be needed since we
aren't actually doing anything with current->mm. The interval tree
notifier stuff still has a FIXME noted from a previous commit that will be
addressed in a follow on patch.

Cc: <stable@vger.kernel.org>
Fixes: e0cf75deab ("IB/hfi1: Fix mm_struct use after free")
Fixes: 3faa3d9a30 ("IB/hfi1: Make use of mm consistent")
Link: https://lore.kernel.org/r/20201125210112.104301.51331.stgit@awfm-01.aw.intel.com
Suggested-by: Jann Horn <jannh@google.com>
Reported-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-11-25 20:30:46 -04:00
..
bnxt_re RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
cxgb4 RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
efa RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
hfi1 IB/hfi1: Ensure correct mm is used at all times 2020-11-25 20:30:46 -04:00
hns RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
i40iw RDMA/i40iw: Address an mmap handler exploit in i40iw 2020-11-25 10:38:11 -04:00
mlx4 RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
mlx5 RDMA/mlx5: Fix devlink deadlock on net namespace deletion 2020-10-26 19:18:19 -03:00
mthca IB/mthca: fix return value of error branch in mthca_init_cq() 2020-11-23 16:22:34 -04:00
ocrdma RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
qedr RDMA/qedr: Fix memory leak in iWARP CM 2020-10-28 09:45:25 -03:00
qib Merge branch 'mlx5_active_speed' into rdma.git for-next 2020-09-18 10:31:45 -03:00
usnic RDMA: Explicitly pass in the dma_device to ib_register_device 2020-10-16 13:53:46 -03:00
vmw_pvrdma RDMA/pvrdma: Fix missing kfree() in pvrdma_register_device() 2020-11-12 13:05:46 -04:00
Makefile RDMA/iw_cxgb3: Remove the iw_cxgb3 module from kernel 2019-10-04 15:08:59 -03:00