From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2373C56201 for ; Fri, 20 Nov 2020 17:46:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2C357223BE for ; Fri, 20 Nov 2020 17:46:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C357223BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A8BD66B0071; Fri, 20 Nov 2020 12:46:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3AB06B0073; Fri, 20 Nov 2020 12:46:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DA2F6B0074; Fri, 20 Nov 2020 12:46:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id 598396B0071 for ; Fri, 20 Nov 2020 12:46:34 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 058AF181AEF1D for ; Fri, 20 Nov 2020 17:46:34 +0000 (UTC) X-FDA: 77505526308.02.slope58_18074a12734d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id E5F0510097AA2 for ; Fri, 20 Nov 2020 17:46:33 +0000 (UTC) X-HE-Tag: slope58_18074a12734d X-Filterd-Recvd-Size: 4427 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 17:46:32 +0000 (UTC) IronPort-SDR: eVG5BJOaRy/kMVLS7yuyb+0pIOqRuMXStUxoUeKOYY/VhVZSsabxOLtB5WQF11uWyKMHtLA/SI h/ioEqC7wiPg== X-IronPort-AV: E=McAfee;i="6000,8403,9811"; a="170732216" X-IronPort-AV: E=Sophos;i="5.78,357,1599548400"; d="scan'208";a="170732216" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 09:46:30 -0800 IronPort-SDR: w9APTzgl3eZaJmvpwS8pmgr1+fYBNUbN42HsC3YvmFlK7mlm+Wi8vKfWM1sNFndxhj15P5keEG etF3nloQeyeA== X-IronPort-AV: E=Sophos;i="5.78,357,1599548400"; d="scan'208";a="477307350" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 09:46:30 -0800 Date: Fri, 20 Nov 2020 09:46:30 -0800 From: Ira Weiny To: Dennis Dalessandro Cc: jgg@ziepe.ca, dledford@redhat.com, linux-rdma@vger.kernel.org, linux-mm@kvack.org, Mike Marciniszyn , Jason Gunthorpe Subject: Re: [PATCH for-rc v3] IB/hfi1: Move cached value of mm into handler Message-ID: <20201120174630.GC1161629@iweiny-DESK2.sc.intel.com> References: <20201117233213.10558.47108.stgit@awfm-01.aw.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201117233213.10558.47108.stgit@awfm-01.aw.intel.com> User-Agent: Mutt/1.11.1 (2018-12-01) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Nov 17, 2020 at 06:32:13PM -0500, Dennis Dalessandro wrote: > Two earlier bug fixes have created a security problem in the hfi1 > driver. One fix aimed to solve an issue where current->mm was not valid > when closing the hfi1 cdev. It attempted to do this by saving a cached > value of the current->mm pointer at file open time. This is a problem if > another process with access to the FD calls in via write() or ioctl() to > pin pages via the hfi driver. The other fix tried to solve a use after > free by taking a reference on the mm. > > To fix this correctly we move the cached value of the mm into the mmu > handler struct for the driver. Is this true for this version of the patch? It seems this version removes the mm member from the mmu_rb_handler and relies on the mmu notifier mm... > Now we can check in the insert, evict, > etc. routines that current->mm matched what the handler was registered > for. If not, then don't allow access. The register of the mmu notifier > will save the mm pointer. > > Note the check in the unregister is not needed in the event that > current->mm is empty. This means the tear down is happening due to a > SigKill or OOM Killer, something along those lines. If current->mm has a > value then it must be checked and only the task that did the register > can do the unregister. > > Since in do_exit() the exit_mm() is called before exit_files(), which > would call our close routine a reference is needed on the mm. We rely on > the mmgrab done by the registration of the notifier, whereas before it > was explicit. Since you need to clean up the commit message above I think another good idea would be to put this explanation in the code in hfi1_mmu_rb_unregister() so that people understand right away why that check is special. [snip] > @@ -92,7 +81,7 @@ static unsigned long mmu_node_last(struct mmu_rb_node *node) > return PAGE_ALIGN(node->addr + node->len) - 1; > } > > -int hfi1_mmu_rb_register(void *ops_arg, struct mm_struct *mm, > +int hfi1_mmu_rb_register(void *ops_arg, > struct mmu_rb_ops *ops, > struct workqueue_struct *wq, > struct mmu_rb_handler **handler) > @@ -110,13 +99,12 @@ int hfi1_mmu_rb_register(void *ops_arg, struct mm_struct *mm, > INIT_HLIST_NODE(&handlr->mn.hlist); > spin_lock_init(&handlr->lock); > handlr->mn.ops = &mn_opts; > - handlr->mm = mm; NIT: I still think you should fix the spelling of handler... ;-) Otherwise I think the logic and code looks good... With changes to the commit message and the comment... Reviewed-by: Ira Weiny Ira