From patchwork Tue Sep 15 11:05:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 11776169 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 20E0492C for ; Tue, 15 Sep 2020 11:05:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D693320B1F for ; Tue, 15 Sep 2020 11:05:46 +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="LyOYim7i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D693320B1F 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 5E0DC6B00C0; Tue, 15 Sep 2020 07:05:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 567FB6B00C1; Tue, 15 Sep 2020 07:05:45 -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 3E6EC900017; Tue, 15 Sep 2020 07:05:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0188.hostedemail.com [216.40.44.188]) by kanga.kvack.org (Postfix) with ESMTP id 1A0746B00C0 for ; Tue, 15 Sep 2020 07:05:45 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DBA483638 for ; Tue, 15 Sep 2020 11:05:44 +0000 (UTC) X-FDA: 77265015408.17.side17_370b2de27110 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 6D9DC180D0186 for ; Tue, 15 Sep 2020 11:05:41 +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.201.201.201 62.14.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: side17_370b2de27110 X-Filterd-Recvd-Size: 5189 Received: from mail.kapsi.fi (mail.kapsi.fi [91.232.154.25]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 11:05:39 +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=LyOYim7iV+uZ2cAaQS3ymFHGe5 ZcDCJHizoHyHkJ8hEvIHXQqAuIVu4/xQufwvxq7FihR0oW3c7Ocg4MlUdTnRm6sAh7U7MrvayWLT/ yryqnD2SdNtIOSpXrzLS0R5ZoiLME5Ztog0r6j0oZX3yXe0D3dsC1C9x8WgMe51XKbB/ELasRvUGS 6xpndgEV8H4Y4mjaQt+QKqVHOKAbp1EtcZ95ipIy2N3XP/YVhiEnc1mt3ZFBiW3hwBO+12X3TjKHi XeEKj/FOfLt3sUxUTA6JsHCtd5A1uNuoAw4wks4k7XnSUCreKhihkXxZYBs0CyPukRjw0WHVaElLV ECsMg+Kg==; 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 1kI8mB-0005wA-Og; Tue, 15 Sep 2020 14:05:31 +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:05:08 +0300 Message-Id: <20200915110522.893152-11-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915110522.893152-1-jarkko.sakkinen@linux.intel.com> References: <20200915110522.893152-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 83.245.197.237 X-SA-Exim-Mail-From: jarkko.sakkinen@linux.intel.com X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-Rspamd-Queue-Id: 6D9DC180D0186 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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;