Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp69299ybd; Fri, 21 Jun 2019 22:02:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkt0OEGMAS6h5IcBak+0C85F08znPEuJVtH+fvsQMXZn22TkowlioCTWN4SCok357o/HQk X-Received: by 2002:a17:902:7e0e:: with SMTP id b14mr111473982plm.257.1561179771409; Fri, 21 Jun 2019 22:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561179771; cv=none; d=google.com; s=arc-20160816; b=Frzw/XPIoP0S4lnH2afVQgnK1BRFhV5TO7iHKW0FFN59WGzqp3zFRwdgdPJqs3RwdD XXNi/X1+P4w6AWgT8dW6lwQB0UL9Gq8VetuVCW4R2PK/tguaL34bPLLFwDUCJbBLaEfJ 7PKUo87kyma/8iDs0SoOj4vogMAnO4ApoDCpo8w+e/2b4zBimkgYNZcwXP6+9xjuhdSN omIr261SAs6O098KBobr1kphlE5h2X/0TmDZp4rh1iHx8eL1zekmZ+V+UiX5S5DF2IOg QwWHJAT728CqK8znbE/LXZmToRK4XL6Gl3H10sDTD7LmgTlCl1DNw4IXB5hGkljewn4u 5Ufg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=WlB3EgfbNvNkzCBJJCkZdYVxKpEST/NPutqyeaBnRhg=; b=zy607SaI69loQUPjO8zi37Ym2bHa+XoI1KogzWzci+yyexGbudn3TcqCMZMaGKgTtC Gjc1AepNqgGnfSoMA3hnLsuOLciY6r9GsVZY7dBZK4wRulVvZtuW0xBp6vgUx4Xf+RY3 VWWjn5bD4ECZNIqwcGZCK7o1CWQfSvWq8dd1xJWOnZ2zuyk+lIk6Er6nMdT2mgBAclUn vLqYDKPr4qx2Rv7zxmr4c8WUhE3V05SNpwcwTQhaWlDHWR2T9XS3sd+Okis4EMo1GmKn 6gTZRr6w3JTpXwb7LfTSSwhARGtR7dze41W3jBoSWZ0VvMTHPhZoD9KuHmX/oM9IkTZL lHLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3si4604241pju.69.2019.06.21.22.02.36; Fri, 21 Jun 2019 22:02:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726147AbfFVFCR (ORCPT + 99 others); Sat, 22 Jun 2019 01:02:17 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:26713 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbfFVFCQ (ORCPT ); Sat, 22 Jun 2019 01:02:16 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 21 Jun 2019 22:02:11 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 07D5C416DE; Fri, 21 Jun 2019 22:02:08 -0700 (PDT) From: Ajay Kaher To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 2/2][v4.9.y] coredump: fix race condition between mmget_not_zero()/get_task_mm() and core dumping Date: Sat, 22 Jun 2019 18:32:18 +0530 Message-ID: <1561208539-29682-2-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561208539-29682-1-git-send-email-akaher@vmware.com> References: <1561208539-29682-1-git-send-email-akaher@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: akaher@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/infiniband/hw/mlx4/main.c | 4 +++- drivers/infiniband/hw/mlx5/main.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index 8d59a59..7ccf722 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -1172,6 +1172,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) @@ -1190,7 +1192,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); diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index b1daf5c..f94df0e 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -1307,6 +1307,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; list_for_each_entry_safe(vma_private, n, &context->vma_private_list, list) { vma = vma_private->vma; @@ -1321,6 +1323,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) list_del(&vma_private->list); kfree(vma_private); } +skip_mm: up_write(&owning_mm->mmap_sem); mmput(owning_mm); put_task_struct(owning_process); -- 2.7.4