Skip to content

Commit 2bbac98

Browse files
drmiller-cnijgunthorpe
authored andcommitted
RDMA/hfi1: Fix use-after-free bug for mm struct
Under certain conditions, such as MPI_Abort, the hfi1 cleanup code may represent the last reference held on the task mm. hfi1_mmu_rb_unregister() then drops the last reference and the mm is freed before the final use in hfi1_release_user_pages(). A new task may allocate the mm structure while it is still being used, resulting in problems. One manifestation is corruption of the mmap_sem counter leading to a hang in down_write(). Another is corruption of an mm struct that is in use by another task. Fixes: 3d2a9d6 ("IB/hfi1: Ensure correct mm is used at all times") Link: https://lore.kernel.org/r/20220408133523.122165.72975.stgit@awfm-01.cornelisnetworks.com Cc: <stable@vger.kernel.org> Signed-off-by: Douglas Miller <doug.miller@cornelisnetworks.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 4d809f6 commit 2bbac98

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/infiniband/hw/hfi1/mmu_rb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler)
8080
unsigned long flags;
8181
struct list_head del_list;
8282

83+
/* Prevent freeing of mm until we are completely finished. */
84+
mmgrab(handler->mn.mm);
85+
8386
/* Unregister first so we don't get any more notifications. */
8487
mmu_notifier_unregister(&handler->mn, handler->mn.mm);
8588

@@ -102,6 +105,9 @@ void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler)
102105

103106
do_remove(handler, &del_list);
104107

108+
/* Now the mm may be freed. */
109+
mmdrop(handler->mn.mm);
110+
105111
kfree(handler);
106112
}
107113

0 commit comments

Comments
 (0)