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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 136ECC2D0E4 for ; Fri, 13 Nov 2020 00:34:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 865F920B80 for ; Fri, 13 Nov 2020 00:34:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 865F920B80 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 E78996B005C; Thu, 12 Nov 2020 19:34:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E02896B005D; Thu, 12 Nov 2020 19:34:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCA7D6B0068; Thu, 12 Nov 2020 19:34:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 9BBC16B005C for ; Thu, 12 Nov 2020 19:34:02 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2DD3F180AD801 for ; Fri, 13 Nov 2020 00:34:02 +0000 (UTC) X-FDA: 77477522724.23.sheet74_501034f2730a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id F3AA337608 for ; Fri, 13 Nov 2020 00:34:01 +0000 (UTC) X-HE-Tag: sheet74_501034f2730a X-Filterd-Recvd-Size: 5091 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 00:34:00 +0000 (UTC) IronPort-SDR: 6qd9y53Nq9bU0cvlFpm55WBzqyYt2Y1h3ldEd0JB/PBX2vfZC5zmHK4aA3l1xC4H+HcBVrkrCM cA7UNcrSTdFg== X-IronPort-AV: E=McAfee;i="6000,8403,9803"; a="232023271" X-IronPort-AV: E=Sophos;i="5.77,473,1596524400"; d="scan'208";a="232023271" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2020 16:33:58 -0800 IronPort-SDR: oorlKCcdMPi5FiuEQSWO3toS2B0mmzscwtxZjs8e2Fd24nSlC6WeYHIqBcrVpHQRqoh4vIPpb1 Mw/eztIzJUHg== X-IronPort-AV: E=Sophos;i="5.77,473,1596524400"; d="scan'208";a="357310119" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2020 16:33:58 -0800 Date: Thu, 12 Nov 2020 16:33:57 -0800 From: Ira Weiny To: Dennis Dalessandro Cc: jgg@ziepe.ca, dledford@redhat.com, Jann Horn , linux-rdma@vger.kernel.org, Mike Marciniszyn , linux-mm@kvack.org, Jason Gunthorpe Subject: Re: [PATCH for-rc v2] IB/hfi1: Move cached value of mm into handler Message-ID: <20201113003357.GW3976735@iweiny-DESK2.sc.intel.com> 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=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1 (2018-12-01) Content-Transfer-Encoding: quoted-printable 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:08:22PM -0500, Dennis Dalessandro wrote: > On 11/12/2020 5:06 PM, 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 c= ached > > > > value of the current->mm pointer at file open time. This is a pro= blem if > > > > another process with access to the FD calls in via write() or ioc= tl() 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. > > >=20 > > > Again I'm still not seeing the race here.=A0 It is entirely possibl= e > > > that the fix > > > I was trying to do way back was mistaken too...=A0 ;-)=A0 I would j= ust > > > delete the > > > last 2 sentences...=A0 and/or reference the commit of those fixes a= nd help > > > explain this more. > >=20 > > I was attempting to refer to [1], the email that started all of this. >=20 > That link should be: > [1] https://marc.info/?l=3Dlinux-rdma&m=3D159891753806720&w=3D2 Ah... ok That does not have anything to do with a close. He is worried= about the mm structure going away because the other process exited. That can't happen, even with the old code, because the release will not be called un= til the child process calls close. But even if the mm is still around the get_user_pages_fast() in the child= is _going_ to use current->mm if it falls back to the locked version. Thus = it is going to go off in the weeds when trying to pin user addresses in the chi= ld. Basically there is no 'race', the code is just broken and going to do the= wrong thing regardless of timing! :-( The new code is keeping the mm_grab() reference in the mmu_notifier rathe= r than in the fd structure, an improvement for sure, but for many applications l= ikely to have almost the same lifetime as before, in the parent process. Also Jann is 100% correct that the driver should not be operating on the = wrong mm and you are using his methodology #3.[1] So I think the final point is the key to fixing the bug. Keeping any current->mm which is not the one we opened the file with... (or more specifically the one which first registered memory). In some ways this m= ay be worse than before because technically the parent could open the fd and ha= nd it to the child and have the child register with it's mm. But that is ok really... May just be odd behavior for some users depending on what oper= ations they do and in what order. Ira [1] Also, you probably should credit Jann for the idea with a suggested b= y tag. >=20 > -Denny >=20