From patchwork Tue Sep 15 11:28:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11776217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C027792C for ; Tue, 15 Sep 2020 11:29:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8100420872 for ; Tue, 15 Sep 2020 11:29:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kapsi.fi header.i=@kapsi.fi header.b="D6Njy2w5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8100420872 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 023E3900034; Tue, 15 Sep 2020 07:29:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F164C90001D; Tue, 15 Sep 2020 07:28:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF5E6900036; Tue, 15 Sep 2020 07:28:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id A190F900034 for ; Tue, 15 Sep 2020 07:28:59 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 530543625 for ; Tue, 15 Sep 2020 11:28:59 +0000 (UTC) X-FDA: 77265073998.08.smile42_110cad327110 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 2BFFA1819E76F for ; Tue, 15 Sep 2020 11:28:59 +0000 (UTC) X-Spam-Summary: 1,0,0,835f7bc25ef1f7cc,d41d8cd98f00b204,jjs@kapsi.fi,,RULES_HIT:41:355:379:541:800:960:973:988:989:1042:1260:1311:1314:1345:1359:1431:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2693:2915:3138:3139:3140:3141:3142:3353:3865:3866:3867:3874:4250:4321:4605:5007:6119:6261:6653:6742:6743:7576:7653:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13053:13846:13894:14096:14181:14394:14721:21080:21451:21627:21772:30003:30054:30055:30064:30069,0,RBL:91.232.154.25:@kapsi.fi:.lbl8.mailshell.net-64.100.201.201 62.2.84.100;04yr6o6mcojxw5gpxd81qpbhsny8bype4e5j1ri1yt3bir5hiff9zmuhqiswxcj.k3cj4kxm3ofxrf5jhapcckfktb8yrgj6otsrgi7esfeygwrm9tp1tukchc877xk.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:107,LUA_SUMMARY:none X-HE-Tag: smile42_110cad327110 X-Filterd-Recvd-Size: 5151 Received: from mail.kapsi.fi (mail.kapsi.fi [91.232.154.25]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 11:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MfOGRytcH2FHakhj47oIMso8mjtUF700XLSJEE9DUHg=; b=D6Njy2w5GBx2AZNi0hg8uJomZA ktTNispwAzhgG8ycM1T5BuNQmd8oEFXtNjjv+mCr/Q85kaidk1sxRJb4dHQPa1yIlqC4oDY1b1bqu 3bTsuqBnGQNW2dlS3wJzlm4NdOwI0BlA+t5UbP9E/D+F7NlhwN0IcOQeErPVhTPzI+VUNpwPZRmHB MOKYktqCQ/65yLxJbebdrQ8T+IBKjuJ1A2QHbj1w6U6CvbF3CNvlnrb+w/A4lz4+SJqlQ0TJ/Z515 alJTPGzJLhBlc00eNzI2oKdY7XBYZRjUSq0jNMhHcJx6Ra0u/XPh+Xojwg5ggsujd+/JpqM9fkBhB 6bDj9x2Q==; Received: from 83-245-197-237.elisa-laajakaista.fi ([83.245.197.237] helo=localhost) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1kI98k-0000ja-1X; Tue, 15 Sep 2020 14:28:50 +0300 From: Jarkko Sakkinen To: x86@kernel.org, linux-sgx@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Jethro Beekman , Darren Kenny , Jarkko Sakkinen , andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, 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 Subject: [PATCH v38 10/24] mm: Add vm_ops->mprotect() Date: Tue, 15 Sep 2020 14:28:28 +0300 Message-Id: <20200915112842.897265-11-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 83.245.197.237 X-SA-Exim-Mail-From: jjs@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-Rspamd-Queue-Id: 2BFFA1819E76F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: From: Sean Christopherson Add vm_ops()->mprotect() for additional constraints for a VMA. Intel Software Guard eXtensions (SGX) will use this callback to add two constraints: 1. Verify that the address range does not have holes: each page address must be filled with an enclave page. 2. Verify that VMA permissions won't surpass the permissions of any enclave page within the address range. Enclave cryptographically sealed permissions for each page address that set the upper limit for possible VMA permissions. Not respecting this can cause #GP's to be emitted. Cc: linux-mm@kvack.org Cc: Andrew Morton Cc: Matthew Wilcox Acked-by: Jethro Beekman Reviewed-by: Darren Kenny Signed-off-by: Sean Christopherson Co-developed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen --- include/linux/mm.h | 3 +++ mm/mprotect.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 97c83773b6f0..717726fcace6 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -547,6 +547,9 @@ 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 (*mprotect)(struct vm_area_struct *vma, + struct vm_area_struct **pprev, unsigned long start, + unsigned long end, unsigned long newflags); vm_fault_t (*fault)(struct vm_fault *vmf); vm_fault_t (*huge_fault)(struct vm_fault *vmf, enum page_entry_size pe_size); diff --git a/mm/mprotect.c b/mm/mprotect.c index ce8b8a5eacbb..f170f3da8a4f 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -610,7 +610,10 @@ static int do_mprotect_pkey(unsigned long start, size_t len, tmp = vma->vm_end; if (tmp > end) tmp = end; - error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); + if (vma->vm_ops && vma->vm_ops->mprotect) + error = vma->vm_ops->mprotect(vma, &prev, nstart, tmp, newflags); + else + error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); if (error) goto out; nstart = tmp;