Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1679421ybt; Thu, 25 Jun 2020 11:28:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2iYVSI3NTVHNJdDlmjrdf+ha8koEo6IhpJzIgOuW44qbtaLYORC6oWOJojx6aleq/azT/ X-Received: by 2002:aa7:c790:: with SMTP id n16mr34550207eds.54.1593109684297; Thu, 25 Jun 2020 11:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593109684; cv=none; d=google.com; s=arc-20160816; b=b37ojn1Ee63jMIVsQKYF9EP3OehWqSMXT4d8Bi7LiaJYDn6otSd3QAO5v09aLOanzx dghMjIufWG20KE4DKBgiDQmAnaoqOmJOZK+ZT+kniZ3HkCX/Q5JgrsIBKMOV95huye+8 PbQw/SbG4hH05T9z7MBcR1IhQgbv1byyI1dAuW3xoJ21EqNDKiHI19PmgB7NNpQbEUJv QPcQ55hn3ukY4/DTFIydq0BEZ9jW+gtYk63n5TYgKDFYoWB4tZjlNEmYin5ckv0gSCwC 0Kk5Qrxs4C9kt7RpAcfs8Fhs88q2fvYPFOMaKqzahzNR+pVkfHENTBa3OnAzajWuxF+P t0cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=GCepHJh9IvbGOEQER27ddp06egUGwt041SLYlZAWLGQ=; b=OwQb/DevcJeDhnl1dedXg6JWaBHrLkyeHri8FxH1mAzELZp3q5Mj4BtVmYTBtZxfFy MfU5UVoYPgTPE47h+8cgaGEWMwmVYqFMKJy4o03dew+0pwS7qjIPF+v7P8p/0NyjLDn1 ux4u/zlgEUkyaVww+SRPgRCzHAv6BPby2dXrNNw7xqHpDbA28rs2LrmUayd/A377gKi9 6rfyFWOUSYstWl18M8ErYjGJD5p+/grXI0vekXjUCVPp7M5m5Gx5TL7q1ROaf8XHaId1 FlaoWUvfOBp2zjYW/jTqITUd8CTnpP30QhVsFecJOrk984acbeOc+iYpYgqGiEDOYl6K GClA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=LDoeI3L5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n17si15395754ejg.418.2020.06.25.11.27.40; Thu, 25 Jun 2020 11:28:04 -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; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=LDoeI3L5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406776AbgFYRbU (ORCPT + 99 others); Thu, 25 Jun 2020 13:31:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404698AbgFYRbT (ORCPT ); Thu, 25 Jun 2020 13:31:19 -0400 Received: from casper.infradead.org (unknown [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58A32C08C5C1; Thu, 25 Jun 2020 10:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GCepHJh9IvbGOEQER27ddp06egUGwt041SLYlZAWLGQ=; b=LDoeI3L5sL64qfTFZFbfaFhX/j 0+0LzH5jw1ocXadxpn1oRN2Um70u4pffz79BOnas1937BaA+AtbBkQyW+QqLZOkK1LAftXyTojsVJ Tsw3QmjN0k4vt+tbj8Wow5n96aciCp9QP8tdyv1S2x2lydDNyBMc2a3giXkzhYzkqVeSq9T2bCiah YRbE3EwQrKkqXkLioWoo18nE3hCLaAr3ggQChuy91sk3yksfpFhaO57VgLOjnflw9MDRM2QMhGUSy D9Qc5V6MPeZIjXqFap2i6TRu3MkW7t0Y8u4tGe9yoSIkqBUWoW//Cz2M5yzQguhun7ezsJ62rmYE9 y4pNw5WA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1joVi6-00020t-Ru; Thu, 25 Jun 2020 17:30:50 +0000 Date: Thu, 25 Jun 2020 18:30:50 +0100 From: Matthew Wilcox To: Borislav Petkov Cc: Jarkko Sakkinen , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , 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: <20200625173050.GF7703@casper.infradead.org> References: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> <20200617220844.57423-11-jarkko.sakkinen@linux.intel.com> <20200625171416.GI20319@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200625171416.GI20319@zn.tnic> 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 07:14:16PM +0200, Borislav Petkov wrote: > On Thu, Jun 18, 2020 at 01:08:32AM +0300, Jarkko Sakkinen wrote: > > From: Sean Christopherson > > Something ate the Cc:s. Lemme add the mm list, akpm is already on Cc. > > Leaving in the rest for mm folks. Thanks! > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index dc7b87310c10..be40b9c29327 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -542,6 +542,8 @@ struct vm_operations_struct { > > void (*close)(struct vm_area_struct * area); > > int (*split)(struct vm_area_struct * area, unsigned long addr); > > int (*mremap)(struct vm_area_struct * area); > > + int (*may_mprotect)(struct vm_area_struct *vma, unsigned long start, > > + unsigned long end, unsigned long prot); This is unlike any other vm operation. Every other one is a verb. > > 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. (how did we get to v33 with this kind of problem still in the patch set?)