Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2482260ybd; Mon, 24 Jun 2019 07:12:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxinlyGljwvbfjFmd3HiCTv4sbj+Z7SoNfTWqRVtuOyVnPXsjsVvEu9yAG35TlFcxIDpggm X-Received: by 2002:a17:902:d20a:: with SMTP id t10mr39517454ply.52.1561385535541; Mon, 24 Jun 2019 07:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561385535; cv=none; d=google.com; s=arc-20160816; b=JBzg1bhVMzeqI1G+aznqF7+BriEVDcTB4azaSuU0V1hmJNJGgKzzoST8Fu8zZOfQoi SNOY3iUEtsWruWslwI/ApoPjCSBQFFFGZVb/PfTlgKMRdD8liv2Fgtpzsm/8CbTs+RPU FZmPJyWVetGmbZ3pt9uiRC+JMGOsCDMM94oKTca372B8GXLlQ5xUcDIvKSZci7mbSHU4 N+9ZOt8t7dZkA9XkaCq7V+j8E3qICOFMcC4XnF2uF4X6YDlmStFYWUFzS9zP6iUNoq0a wK/MrsiyqW/DD3TAWozdEiFKrRN/Fo72jx7z7vQkNOZoAh+tim5IPBQCzNMUBVBb3NkX DDAw== 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=RrpDX4FYMrFtaV+gyW1w3MWRzmOeSX4d+jdvERFayLbH0aStuWAPeYYqo14xRfNTV8 /RnfgPXZbAHhaLH7poXXfCtGo/7KzgAIndS6gRAO/XwnRJtAoBDgWMeY09wSqoXWTMSd 5kuy+t3Y+15CEbFX3H43nhBW67GkcQRVrxTNJ+NuiSxGcpfsHAvYTE6Jtv9DZVjlUcsb Lb2CKC33nvWyutof6d272Aqeoy2pCJwZPJI9mXlzSy3ivEsxPeuXfXuyDOzYfE17AdEC SnI2ISHLf0m3ClEPYS0if7X+BGkusMXcGBldUw05cfKChDYNAhRyPptVdFo50CVR3rpf BjhQ== 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 cp14si4792051plb.183.2019.06.24.07.11.59; Mon, 24 Jun 2019 07:12:15 -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 S1730140AbfFXNDA (ORCPT + 99 others); Mon, 24 Jun 2019 09:03:00 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:28280 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729130AbfFXNC7 (ORCPT ); Mon, 24 Jun 2019 09:02:59 -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; Mon, 24 Jun 2019 06:02:56 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 8452E412C5; Mon, 24 Jun 2019 06:02:51 -0700 (PDT) From: Ajay Kaher To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 2/3][v4.9.y] coredump: fix race condition between mmget_not_zero()/get_task_mm() and core dumping Date: Tue, 25 Jun 2019 02:33:04 +0530 Message-ID: <1561410186-3919-2-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1561410186-3919-1-git-send-email-akaher@vmware.com> References: <1561410186-3919-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