infiniband: fix race condition between infiniband mlx4, mlx5 driver and core dumping
authorAjay Kaher <akaher@vmware.com>
Mon, 10 Jun 2019 20:52:17 +0000 (02:22 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 Jun 2019 06:16:19 +0000 (08:16 +0200)
This patch is the extension of following upstream commit to fix
the race condition between get_task_mm() and core dumping
for IB->mlx4 and IB->mlx5 drivers:

commit 04f5866e41fb ("coredump: fix race condition between
mmget_not_zero()/get_task_mm() and core dumping")'

Thanks to Jason for pointing this.

Signed-off-by: Ajay Kaher <akaher@vmware.com>
Acked-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx5/main.c

index e2beb182d54c313a1fb4ea1f1778543441408870..0299c0642de81ba8a9938dc50d10f7044b4e105b 100644 (file)
@@ -1197,6 +1197,8 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
         * mlx4_ib_vma_close().
         */
        down_write(&owning_mm->mmap_sem);
+       if (!mmget_still_valid(owning_mm))
+               goto skip_mm;
        for (i = 0; i < HW_BAR_COUNT; i++) {
                vma = context->hw_bar_info[i].vma;
                if (!vma)
@@ -1215,7 +1217,7 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
                /* context going to be destroyed, should not access ops any more */
                context->hw_bar_info[i].vma->vm_ops = NULL;
        }
-
+skip_mm:
        up_write(&owning_mm->mmap_sem);
        mmput(owning_mm);
        put_task_struct(owning_process);
index 13a92062e9ca54be799571c774cd5a0c03a71463..3fbe3962d53b5e3f24aeaf270106f4fae094b4e1 100644 (file)
@@ -1646,6 +1646,8 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
         * mlx5_ib_vma_close.
         */
        down_write(&owning_mm->mmap_sem);
+       if (!mmget_still_valid(owning_mm))
+               goto skip_mm;
        mutex_lock(&context->vma_private_list_mutex);
        list_for_each_entry_safe(vma_private, n, &context->vma_private_list,
                                 list) {
@@ -1662,6 +1664,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
                kfree(vma_private);
        }
        mutex_unlock(&context->vma_private_list_mutex);
+skip_mm:
        up_write(&owning_mm->mmap_sem);
        mmput(owning_mm);
        put_task_struct(owning_process);