Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp826971ybt; Wed, 17 Jun 2020 15:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXXfIpwRusA9eE8abhXRr9Z8cb1mb/tbGjIgexy9CKVdnEEfyvets7HpP29ZpYU7qfVxLw X-Received: by 2002:a17:906:344c:: with SMTP id d12mr1169426ejb.130.1592432071229; Wed, 17 Jun 2020 15:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592432071; cv=none; d=google.com; s=arc-20160816; b=yfBYoo4QH34A72MiOtLSShA4jOtubaqHfNyPY6YKp8ySWroaYPvVjV4regyks66Y+q 6/kBgyLAEEdMcskCLFcSL0I9rkjc9E9W5ODNwKN5AKkqspIIgqi75syE/Sw8GYzVSSxa u5ip/tkyz6CGzIZ5ppKt2UMSNumUkm0sVYDo7uYrG/XWASAa4zTUjCH49llsI4251MWp n9U9iejfyoCK0OedC4c8eRF/6twOUTQN8FO/RJwizPgrsFSU10dXAWNgN3tEoTPSLgcS 2NPnWu0u87oyjl/t2/RStKicTSfAxWzT+cqmBqBjE4FjdOmnUKJ+m/X+o4c0Mb1THIqE IUdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=da4qDPM0nuISwjebAsWK8fQA2+ufexWi3PxODc6hCvY=; b=pFrXdEpf7REtEm04WbNl3hqdd7GyS/w0+jriW5z78fbzFYB8mlytvWrnJPTBkLcVfu 9/e0d8AS1kXMf24s4lJFowp/07CNiUomvtVAiOhxNiQpUmyhDC7/iIZgBKJwKNUtph6T 9MtpgQdjKLdD8T467O2BItwChSE+FLDa4GDgYalxY6iUfdozsnGCz4UzVTchGmyv8kOJ AGnZBtFQDKxpTmFG1sJK4P1yRlIzldDmFQRDLghBvWWytZtDcssdrjFt7EwGng/J3fQk 8thBKrMQXJl+ENH56aabyMW7Y430x48HuI11wsBR0fC3Hf9WdiS9wbTCUcJjmA8ZEK3H FQ4g== 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 a17si788427edx.507.2020.06.17.15.14.09; Wed, 17 Jun 2020 15:14:31 -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 S1726999AbgFQWLc (ORCPT + 99 others); Wed, 17 Jun 2020 18:11:32 -0400 Received: from mga17.intel.com ([192.55.52.151]:6916 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbgFQWLb (ORCPT ); Wed, 17 Jun 2020 18:11:31 -0400 IronPort-SDR: yYn3Nc1w/+VVd0t7+08lV9fQXaAeZwUEwXG5hGyyGg30wTGK9fOisRqoyetK3dxW1FW8T6H97s cdqT319xX15g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2020 15:11:24 -0700 IronPort-SDR: pLQYGKgFWQ8Su9haHgmEGdu50iOt/t9dSdPbcXkBHhbL+PRijLT58DFEr1oAcJj91EKD/pRSSf q1X3Thwj2Ajw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,523,1583222400"; d="scan'208";a="421288292" Received: from ysharon1-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.49.131]) by orsmga004.jf.intel.com with ESMTP; 17 Jun 2020 15:11:12 -0700 From: Jarkko Sakkinen To: x86@kernel.org, linux-sgx@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Sean Christopherson , Jethro Beekman , Jarkko Sakkinen , akpm@linux-foundation.org, 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 v33 10/21] mm: Introduce vm_ops->may_mprotect() Date: Thu, 18 Jun 2020 01:08:32 +0300 Message-Id: <20200617220844.57423-11-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> References: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Add vm_ops()->may_mprotect() to check additional constraints. SGX uses this callback to add two constraints: 1. Verify that the address range does not have holes: for each page address, there is an actual enclave page created. 2. Mapped permissions do not surpass the lowest enclave page permissions in the address range. linux-mm@kvack.org Andrew Morton Acked-by: Jethro Beekman Signed-off-by: Sean Christopherson Signed-off-by: Jarkko Sakkinen --- include/linux/mm.h | 2 ++ mm/mprotect.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) 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); 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..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; - tmp = vma->vm_end; - if (tmp > end) - tmp = end; error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); if (error) goto out; -- 2.25.1