Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp663845ybh; Tue, 10 Mar 2020 06:06:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv5SuKtqb+jI0veXI3dF7JUgED0+rznUU1MGihE0Uxj9Lw6HPZJczu06WNg2oT/bjKgjGsa X-Received: by 2002:a9d:2215:: with SMTP id o21mr2266755ota.113.1583845614981; Tue, 10 Mar 2020 06:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583845614; cv=none; d=google.com; s=arc-20160816; b=xdchSYIamtKxy+yVhxS20IemqEKfr5/FKPkyHYvkKOi58KqIyTqqP8mZxgRVtSoznT ZtaxFbyjm+6OzRJ1oYkV3KKeraOCqP8Kh867hlUOOCzvpT5Uy4O4YQ0Dw8Qm+XJr5Oej ZIzPKZGv0LPFbVdxTYbdmGR+mrsr8sSOsEqw5YTV+ijRJW/SCQAV0Seg8arknhsaNbFI nk1MfBWHFoDcHd7RXToqTP+Ause6SpCvABbxVoHxXwNHZKqGVIYZmm11pCDOSCXeBbGA w+J5dvKF/DfifJXST78Z0v23ulncSD/aMMNxn7eH/+dPwq35qee5lHuKF2yN3nFPR72E 1zLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fPNxXCNva/1P1bY0DBlO3kMoQUieVgVtqzb5pDSJdWw=; b=iBU3tr0W778B7wOkSjcGcfPCLJ/n66lmGVXGixouvnYcchUupJB6z+LwnxF0/5/4eV H4J1ikTtj/XGOB4sZKDuOWpAcA2j+599g7gmKXG5LWpyKx6XXzW8JvBQfq+xNS4FExmA uOxOq78rJv4yRAcbKlX+kKnEEPJA3sXPE9iiLQ+dwcLq076IMq1rXZdcVPvGzvsWBNnz 4tASA9UB9+BHagzORj4guasqhwWOCcPYkrrcAnX5dIp76+tF+ex34NyTPddj0mofgiys UAAztAIWkMQCPUJbaz4519j2QhYh4nlWKx/D8pNZjxB4hM4Q2NFXv1DhzV0oq1moYzdc b7JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NgqBMAkH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si74952oij.97.2020.03.10.06.06.30; Tue, 10 Mar 2020 06:06:54 -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; dkim=pass header.i=@kernel.org header.s=default header.b=NgqBMAkH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730727AbgCJNEc (ORCPT + 99 others); Tue, 10 Mar 2020 09:04:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:49538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729481AbgCJNE2 (ORCPT ); Tue, 10 Mar 2020 09:04:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 32AE320409; Tue, 10 Mar 2020 13:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583845467; bh=ZqlUwVB66ydp/iIJwLEGmXhZSRl3CEmNjcB+VKOctZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NgqBMAkH7EaBKY1zU+gmUECYatcIgFz+IhBK6pX9d6HbJUVvi/s/sQbUNjvwT01mm nzj9hrqjMGn3yShMZZ2vQ+cHGgPNuzoI/mSrUqEo53hmSoP6n+RGvFpalCExW6rmVJ inrPQccTczGlmznADOLkcrqa3HnTetwOp52f4TGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 5.5 161/189] RDMA/odp: Ensure the mm is still alive before creating an implicit child Date: Tue, 10 Mar 2020 13:39:58 +0100 Message-Id: <20200310123656.312772237@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123639.608886314@linuxfoundation.org> References: <20200310123639.608886314@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe commit a4e63bce1414df7ab6eb82ca9feb8494ce13e554 upstream. Registration of a mmu_notifier requires the caller to hold a mmget() on the mm as registration is not permitted to race with exit_mmap(). There is a BUG_ON inside the mmu_notifier to guard against this. Normally creating a umem is done against current which implicitly holds the mmget(), however an implicit ODP child is created from a pagefault work queue and is not guaranteed to have a mmget(). Call mmget() around this registration and abort faulting if the MM has gone to exit_mmap(). Before the patch below the notifier was registered when the implicit ODP parent was created, so there was no chance to register a notifier outside of current. Fixes: c571feca2dc9 ("RDMA/odp: use mmu_notifier_get/put for 'struct ib_ucontext_per_mm'") Link: https://lore.kernel.org/r/20200227114118.94736-1-leon@kernel.org Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/umem_odp.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -187,14 +187,28 @@ ib_umem_odp_alloc_child(struct ib_umem_o odp_data->page_shift = PAGE_SHIFT; odp_data->notifier.ops = ops; + /* + * A mmget must be held when registering a notifier, the owming_mm only + * has a mm_grab at this point. + */ + if (!mmget_not_zero(umem->owning_mm)) { + ret = -EFAULT; + goto out_free; + } + odp_data->tgid = get_pid(root->tgid); ret = ib_init_umem_odp(odp_data, ops); - if (ret) { - put_pid(odp_data->tgid); - kfree(odp_data); - return ERR_PTR(ret); - } + if (ret) + goto out_tgid; + mmput(umem->owning_mm); return odp_data; + +out_tgid: + put_pid(odp_data->tgid); + mmput(umem->owning_mm); +out_free: + kfree(odp_data); + return ERR_PTR(ret); } EXPORT_SYMBOL(ib_umem_odp_alloc_child);