Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp115588ybt; Thu, 25 Jun 2020 16:52:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyQST+airFlpFw8Vemz6D3Ds7ZDm93BjSIiekEc4SPqnXeR21FxnFTLbC4FL0oycQLh2/o X-Received: by 2002:a05:6402:22a5:: with SMTP id cx5mr754898edb.246.1593129144752; Thu, 25 Jun 2020 16:52:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593129144; cv=none; d=google.com; s=arc-20160816; b=Dg1R/4BxLEk9j4gji49weI9+zV7PTS7EX1qsIQ8uNAQfbYXQHqaFBodlQGZ6qKZeMV K8usIuLyzMTP946LxEZ+6mhLzuUrHRLbLJv/VYH+xslc4gOARQ/Rx3nDXSth2yoNFMpQ VeG7mEaY6cSgv3EEah7fJNBDJjjcc3Ejbnmwb03Vb6liMjlpSKlyNjqS61lb2r5QEbrr xKF9piOtTRhlXl3d2PnFbIIQ1CxDYlo//3pvjaU9d2bvMa/Lvwr7BpLSfvJOdl/ZnrIp Mr9uqp4xvL3+9+yW1MrTokUzvWZWNATaf/BaLCwRgN+xa9HS3CXTY1m7AG7sgiOX0WX5 n5MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=9i0M/knCkuar2C4F+sLPC86iGpQsaHQ/4a6U+51arm0=; b=XzJ1Xz4tTA4J/Saj3uQ9sI/Kt/6eXAM0GA39oN1nB268K0N4P6goABUZbrmo7OmNLh l2Nek819a+K6hwiDoM5aCccPB/Rmu8zdRMP4qmTTQCmoKwMOWiXIjkU+KO9dPemz7NAA INt/D8VxHL5/3wSiUXHjdsNZRuaEsS8lFWBNkiNFONERKTDZGbQUfQM0/nUUfotoV+yR W1s1BL2kC1q8zzFh5vbNRKRTP+5F+OOeRmNb9sb6wqNlHO6wuTIGOItNrUB5wPEBqKq2 ySJBtHjkyyfrltKhNYNN1IJYV77Mkl23uCcR6aDPoKez7EwpcxZ5E+1q3WFzBI9s+yhR mB6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l2si7637955edk.332.2020.06.25.16.52.01; Thu, 25 Jun 2020 16:52:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407559AbgFYWkS (ORCPT + 99 others); Thu, 25 Jun 2020 18:40:18 -0400 Received: from mga02.intel.com ([134.134.136.20]:24488 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405127AbgFYWkR (ORCPT ); Thu, 25 Jun 2020 18:40:17 -0400 IronPort-SDR: rzNIDzYXhY3chKEt37x+7e3ouGoz4p41AF00kyYPsMQ4vB2He6cNokgXlavhpPcgQfkFwxWTVP NIwHfV1/zaYw== X-IronPort-AV: E=McAfee;i="6000,8403,9663"; a="133514468" X-IronPort-AV: E=Sophos;i="5.75,280,1589266800"; d="scan'208";a="133514468" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 15:40:16 -0700 IronPort-SDR: pcAXwb9yQiL0xZNaBVRyCJV77i34uuWomPinHUgK9MTjbZx8DQ3nVrdWpAFLY2nBC41ls/7Oe4 7GQgSHOdBz2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,280,1589266800"; d="scan'208";a="385605612" Received: from jproldan-mobl.ger.corp.intel.com (HELO localhost) ([10.252.49.123]) by fmsmga001.fm.intel.com with ESMTP; 25 Jun 2020 15:40:05 -0700 Date: Fri, 26 Jun 2020 01:40:04 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: Matthew Wilcox , Borislav Petkov , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Jethro Beekman , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com, linux-mm@kvack.org Subject: Re: [PATCH v33 10/21] mm: Introduce vm_ops->may_mprotect() Message-ID: <20200625224004.GA31121@linux.intel.com> References: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> <20200617220844.57423-11-jarkko.sakkinen@linux.intel.com> <20200625171416.GI20319@zn.tnic> <20200625173050.GF7703@casper.infradead.org> <20200625180646.GF3437@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625180646.GF3437@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 25, 2020 at 11:06:46AM -0700, Sean Christopherson wrote: > On Thu, Jun 25, 2020 at 06:30:50PM +0100, Matthew Wilcox wrote: > > On Thu, Jun 25, 2020 at 07:14:16PM +0200, Borislav Petkov wrote: > > > On Thu, Jun 18, 2020 at 01:08:32AM +0300, Jarkko Sakkinen wrote: > > > > diff --git a/mm/mprotect.c b/mm/mprotect.c > > > > index ce8b8a5eacbb..f7731dc13ff0 100644 > > > > --- a/mm/mprotect.c > > > > +++ b/mm/mprotect.c > > > > @@ -603,13 +603,21 @@ static int do_mprotect_pkey(unsigned long start, size_t len, > > > > goto out; > > > > } > > > > > > > > + tmp = vma->vm_end; > > > > + if (tmp > end) > > > > + tmp = end; > > > > + > > > > + if (vma->vm_ops && vma->vm_ops->may_mprotect) { > > > > + error = vma->vm_ops->may_mprotect(vma, nstart, tmp, > > > > + prot); > > > > + if (error) > > > > + goto out; > > > > + } > > > > + > > > > error = security_file_mprotect(vma, reqprot, prot); > > > > if (error) > > > > goto out; > > > > > > > > I think the right way to do this is: > > > > error = security_file_mprotect(vma, reqprot, prot); > > if (error) > > goto out; > > > > tmp = vma->vm_end; > > if (tmp > end) > > tmp = end; > > + if (vma->vm_ops->mprotect) > > + error = vma->vm_ops->mprotect(vma, &prev, nstart, tmp, > > + newflags); > > + else > > + error = mprotect_fixup(vma, &prev, nstart, tmp, > > + newflags); > > - error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); > > if (error) > > goto out; > > > > and then the vma owner can do whatever it needs to before calling > > mprotect_fixup(), which is already not static. > > I'm certainly not opposed to a straight ->mprotect() hook. ->may_protect() > came about because I/we thought it would be less objectionable to allow the > vma owner to apply additional restrictions as opposed to a wholesale > replacement. Can you send fixes to associated patches to linux-sgx (i.e. this and driver)? > > (how did we get to v33 with this kind of problem still in the patch set?) > > Because no one from the mm world has looked at it. Which is completely > understandable because it's a giant patch set and the first 25 or so versions > were spent sorting out fundamental architectural/design issue (there have > been a _lot_ of speed bumps), e.g. the need for hooking mprotect() didn't > even come about until v21. Actually also because we did not have an explicit linux-mm CC. /Jarkko