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=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 AA175C5519F for ; Fri, 13 Nov 2020 00:01:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 006D520657 for ; Fri, 13 Nov 2020 00:01:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="cRbBUJPd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 006D520657 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 44A016B005C; Thu, 12 Nov 2020 19:01:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FC676B0068; Thu, 12 Nov 2020 19:01:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C5166B006E; Thu, 12 Nov 2020 19:01:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id E2CFD6B005C for ; Thu, 12 Nov 2020 19:01:39 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4C5F33628 for ; Fri, 13 Nov 2020 00:01:39 +0000 (UTC) X-FDA: 77477441118.09.man80_3c036962730a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 2FA39180AD802 for ; Fri, 13 Nov 2020 00:01:39 +0000 (UTC) X-HE-Tag: man80_3c036962730a X-Filterd-Recvd-Size: 5965 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 00:01:38 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id d28so7309967qka.11 for ; Thu, 12 Nov 2020 16:01:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RltXDH0FgaRusmPo4cNOYiqkUGtOvZLa8FgaLyW6/QQ=; b=cRbBUJPdHSqlA7MgYLSCQ680bqlGr2mKz4/cUeKhmyGfojLITJ/VAA6Bp+Kee/1RG8 VKHHUMvoub+mAFbhoEf6SR8HpAi8V+lg4/JuxFOdnPszM6ZfMzT2tC1xBTRcoH3W3EAL IGAZRrtSHqyu0iqJXwUdou0hneYFtMmWNPuVeCjIX5rBlWqPzm2UKZ5QjVzWHOtfuZHN IvvwA9AGWC3yb/RK1Uw5jyu4bzgd6figaoSn7H8QUd3ITUeD1pqbw0fBN79eMXsc3EgN xeGjquQVyFqpAohk7NbRTvWZkm+j1aVjgln4h/BCwPTcgWLqD/SCNxyu1gNBhkJVaSQ+ UBEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RltXDH0FgaRusmPo4cNOYiqkUGtOvZLa8FgaLyW6/QQ=; b=PZ96EzTp7mVJnXkxGmzU/vlayc/wzE7AiHltw8WdjncL37WGwTuRI2e2rHVFByajMK fWfhv39kRCrrIIObJJr0eTCFYMkAiDRQtTMnZv7ZNunBMJu1jUU1pnsZGERGYVR9oEif SwRWSHMNBbki+C7++U1aCZxz4V48kj7jWXHtc+voSTDI9KQgWI6ziIwihk5V2CDSEA3V kYJP5jJj4GzOJIyWg37GHDtZ7DDw89/KgSC71YOAmaDI3GkYaJL5fTKHRnHUcvxp0rq6 TX0AeGyb8UwG+shM5/F0Jw5Ek+BdcOS0rqLYhukLmitoum7R/jKsrwt0S3cyS2pNBTJK m2wg== X-Gm-Message-State: AOAM532BHR46FaGe5sOxk81dM37RCg/Kp2FP9t6B5yPex1bBRoTlc9kw B3k8SzCNpRrBtlmqnsW/0Ue0LA== X-Google-Smtp-Source: ABdhPJy/pDQ9Eqqb9pwaxGOwE/6Z10O6Gyf0jdFoMNxRg3i5i4P4RGk7l9ia9zNStnowU5Jnza1O9w== X-Received: by 2002:a37:4bc1:: with SMTP id y184mr2421639qka.278.1605225697395; Thu, 12 Nov 2020 16:01:37 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id 203sm5898928qkd.25.2020.11.12.16.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 16:01:36 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kdMX2-004Bpq-6S; Thu, 12 Nov 2020 20:01:36 -0400 Date: Thu, 12 Nov 2020 20:01:36 -0400 From: Jason Gunthorpe To: Dennis Dalessandro Cc: Ira Weiny , dledford@redhat.com, Jann Horn , linux-rdma@vger.kernel.org, Mike Marciniszyn , linux-mm@kvack.org Subject: Re: [PATCH for-rc v2] IB/hfi1: Move cached value of mm into handler Message-ID: <20201113000136.GW244516@ziepe.ca> References: <20201112025837.24440.6767.stgit@awfm-01.aw.intel.com> <20201112171439.GT3976735@iweiny-DESK2.sc.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Nov 12, 2020 at 05:06:30PM -0500, Dennis Dalessandro wrote: > On 11/12/2020 12:14 PM, Ira Weiny wrote: > > On Wed, Nov 11, 2020 at 09:58:37PM -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. This was just wrong because its > > > possible for a race condition between one process with an mm that opened > > > the cdev if it was accessing via an IOCTL, and another process > > > attempting to close the cdev with a different current->mm. > > > > Again I'm still not seeing the race here. It is entirely possible that the fix > > I was trying to do way back was mistaken too... ;-) I would just delete the > > last 2 sentences... and/or reference the commit of those fixes and help > > explain this more. > > I was attempting to refer to [1], the email that started all of this. > > > > > > > To fix this correctly we move the cached value of the mm into the mmu > > > handler struct for the driver. > > > > Looking at this closer I don't think you need the mm member of mmu_rb_handler > > any longer. See below. > > We went back and forth on this as well. We thought it better to rely on our > own pointer vs looking into the notifier to get the mm. Same reasoning for > doing our own referecne counting. Question is what is the preferred way > here. Functionally it makes no difference and I'm fine going either way. Use the mm pointer in the notifier if you have a notifier registered, it is clearer as to the lifetime and matches what other places do > That's the question. It does make sense to do that if we are sticking iwth > the notifier's reference vs our own explicit one. I'm not 100% sold that we > should not be doing the ref counting and keeping our own pointer. To me we > shoudln't be looking inside the notifer struct and instead honestly there > should probably be an API/helper call to get the mm from it. I'm open to > either approach. The notifier is there to support users of the notifier, and nearly all notifier users require the mm at various points. Adding get accessors is a bit of a kernel anti-pattern, this isn't Java.. Jason