From: Reinette Chatre <reinette.chatre@intel.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Haitao Huang <haitao.huang@linux.intel.com>,
"Dhanraj, Vijay" <vijay.dhanraj@intel.com>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"bp@alien8.de" <bp@alien8.de>,
"Lutomirski, Andy" <luto@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>, "Christopherson,,
Sean" <seanjc@google.com>, "Huang, Kai" <kai.huang@intel.com>,
"Zhang, Cathy" <cathy.zhang@intel.com>,
"Xing, Cedric" <cedric.xing@intel.com>,
"Huang, Haitao" <haitao.huang@intel.com>,
"Shanahan, Mark" <mark.shanahan@intel.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V2 16/32] x86/sgx: Support restricting of enclave page permissions
Date: Thu, 17 Mar 2022 15:08:04 -0700 [thread overview]
Message-ID: <690d3d8e-6214-dcdd-daaa-48a380114ad7@intel.com> (raw)
In-Reply-To: <YjK5ZWJRQX+lyUxS@iki.fi>
Hi Jarkko,
On 3/16/2022 9:30 PM, Jarkko Sakkinen wrote:
> On Mon, Mar 14, 2022 at 08:32:28AM -0700, Reinette Chatre wrote:
>> Hi Jarkko,
>>
>> On 3/13/2022 8:42 PM, Jarkko Sakkinen wrote:
>>> On Fri, Mar 11, 2022 at 11:28:27AM -0800, Reinette Chatre wrote:
>>>> Supporting permission restriction in an ioctl() enables the runtime to manage
>>>> the enclave memory without needing to map it.
>>>
>>> Which is opposite what you do in EAUG. You can also augment pages without
>>> needing the map them. Sure you get that capability, but it is quite useless
>>> in practice.
>>>
>>>> I have considered the idea of supporting the permission restriction with
>>>> mprotect() but as you can see in this response I did not find it to be
>>>> practical.
>>>
>>> Where is it practical? What is your application? How is it practical to
>>> delegate the concurrency management of a split mprotect() to user space?
>>> How do we get rid off a useless up-call to the host?
>>>
>>
>> The email you responded to contained many obstacles against using mprotect()
>> but you chose to ignore them and snipped them all from your response. Could
>> you please address the issues instead of dismissing them?
>
> I did read the whole email but did not see anything that would make a case
> for fully exposed EMODPR, or having asymmetrical towards how EAUG works.
I believe that on its own each obstacle I shared with you is significant enough
to not follow that approach. You simply respond that I am just not making a
case without acknowledging any obstacle or providing a reason why the obstacles
are not valid.
To help me understand your view, could you please respond to each of the
obstacles I list below and how it is not an issue?
1) ABI change:
mprotect() is currently supported to modify VMA permissions
irrespective of EPCM permissions. Supporting EPCM permission
changes with mprotect() would change this behavior.
For example, currently it is possible to have RW enclave
memory and support multiple tasks accessing the memory. Two
tasks can map the memory RW and later one can run mprotect()
to reduce the VMA permissions to read-only without impacting
the access of the other task.
By moving EPCM permission changes to mprotect() this usage
will no longer be supported and current behavior will change.
2) Only half EPCM permission management:
Moving to mprotect() as a way to set EPCM permissions is
not a clear interface for EPCM permission management because
the kernel can only restrict permissions. Even so, the kernel
has no insight into the current EPCM permissions and thus whether they
actually need to be restricted so every mprotect() call,
all except RWX, will need to be treated as a permission
restriction with all the implementation obstacles
that accompany it (more below).
There are two possible ways to implement permission restriction
as triggered by mprotect(), (a) during the mprotect() call or
(b) during a subsequent #PF (as suggested by you), each has
its own obstacles.
3) mprotect() implementation
When the user calls mprotect() the expectation is that the
call will either succeed or fail. If the call fails the user
expects the system to be unchanged. This is not possible if
permission restriction is done as part of mprotect().
(a) mprotect() may span multiple VMAs and involves VMA splits
that (from what I understand) cannot be undone. SGX memory
does not support VMA merges. If any SGX function
(EMODPR or ETRACK on any page) done after a VMA split fails
then the user will be left with fragmented memory.
(b) The EMODPR/ETRACK pair can fail on any of the pages provided
by the mprotect() call. If there is a failure then the
kernel cannot undo previously executed EMODPR since the kernel
cannot run EMODPE. The EPCM permissions are thus left in inconsistent
state since some of the pages would have changed EPCM permissions
and mprotect() does not have mechanism to communicate
partial success.
The partial success is needed to communicate to user space
(i) which pages need EACCEPT, (ii) which pages need to be
in new request (although user space does not have information
to help the new request succeed - see below).
(c) User space runtime has control over management of EPC memory
and accurate failure information would help it to do so.
Knowing the error code of the EMODPR failure would help
user space to take appropriate action. For example, EMODPR
can return "SGX_PAGE_NOT_MODIFIABLE" that helps the runtime
to learn that it needs to run EACCEPT on that page before
the EMODPR can succeed. Alternatively, if it learns that the
return is "SGX_EPC_PAGE_CONFLICT" then it could determine
that some other part of the runtime attempted an ENCLU
function on that page.
It is not possible to provide such detailed errors to user
space with mprotect().
4) #PF implementation
(a) There is more to restricting permissions than just running
ENCLS[EMODPR]. After running ENCLS[EMODPR] the kernel should
also initiate the ETRACK flow to ensure that any thread within
the enclave is interrupted by sending an IPI to the CPU,
this includes the thread that just triggered the #PF.
(b) Second consideration of the EMODPR and ETRACK flow is that
this has a large "blast radius" in that any thread in the
enclave needs to be interrupted. #PFs may arrive at any time
so setting up a page range where a fault into any page in the
page range will trigger enclave exits for all threads is
a significant yet random impact. I believe it would be better
to update all pages in the range at the same time and in this
way contain the impact of this significant EMODPR/ETRACK/IPIs
flow.
(c) How will the page fault handler know when EMODPR/ETRACK should
be run? Consider that the page fault handler can be called
significantly later than the mprotect() call and that
user space can call EMODPE any time to extend permissions.
This implies that EMODPR/ETRACK/IPIs should be run during
*every* page fault, irrespective of mprotect().
(d) If a page is in pending or modified state then EMODPR will
always fail. This is something that needs to be fixed by
user space runtime but the page fault will not be able
to communicate this.
Considering the above, could you please provide clear guidance on
how you envision permission restriction to be supported by mprotect()?
Reinette
next prev parent reply other threads:[~2022-03-17 22:08 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 0:45 [PATCH V2 00/32] x86/sgx and selftests/sgx: Support SGX2 Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 01/32] x86/sgx: Add short descriptions to ENCLS wrappers Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 02/32] x86/sgx: Add wrapper for SGX2 EMODPR function Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 03/32] x86/sgx: Add wrapper for SGX2 EMODT function Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 04/32] x86/sgx: Add wrapper for SGX2 EAUG function Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 05/32] Documentation/x86: Document SGX permission details Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 06/32] x86/sgx: Support VMA permissions more relaxed than enclave permissions Reinette Chatre
2022-03-07 17:10 ` Jarkko Sakkinen
2022-03-07 17:36 ` Reinette Chatre
2022-03-08 8:14 ` Jarkko Sakkinen
2022-03-08 9:06 ` Jarkko Sakkinen
2022-03-08 9:12 ` Jarkko Sakkinen
2022-03-08 16:04 ` Reinette Chatre
2022-03-08 17:00 ` Jarkko Sakkinen
2022-03-08 17:49 ` Reinette Chatre
2022-03-08 18:46 ` Jarkko Sakkinen
2022-03-11 11:06 ` Dr. Greg
2022-02-08 0:45 ` [PATCH V2 07/32] x86/sgx: Add pfn_mkwrite() handler for present PTEs Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 08/32] x86/sgx: x86/sgx: Add sgx_encl_page->vm_run_prot_bits for dynamic permission changes Reinette Chatre
2022-03-04 8:55 ` Jarkko Sakkinen
2022-03-04 19:19 ` Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 09/32] x86/sgx: Export sgx_encl_ewb_cpumask() Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 10/32] x86/sgx: Rename sgx_encl_ewb_cpumask() as sgx_encl_cpumask() Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 11/32] x86/sgx: Move PTE zap code to new sgx_zap_enclave_ptes() Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 12/32] x86/sgx: Make sgx_ipi_cb() available internally Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 13/32] x86/sgx: Create utility to validate user provided offset and length Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 14/32] x86/sgx: Keep record of SGX page type Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 15/32] x86/sgx: Support relaxing of enclave page permissions Reinette Chatre
2022-03-04 8:59 ` Jarkko Sakkinen
2022-02-08 0:45 ` [PATCH V2 16/32] x86/sgx: Support restricting " Reinette Chatre
2022-02-21 0:49 ` Jarkko Sakkinen
2022-02-22 18:35 ` Reinette Chatre
2022-02-23 15:46 ` Jarkko Sakkinen
2022-02-23 19:55 ` Reinette Chatre
2022-02-28 12:27 ` Jarkko Sakkinen
2022-02-23 19:21 ` Dhanraj, Vijay
2022-02-23 22:42 ` Reinette Chatre
2022-02-28 12:24 ` Jarkko Sakkinen
2022-02-28 13:19 ` Jarkko Sakkinen
2022-02-28 15:16 ` Dave Hansen
2022-02-28 17:44 ` Dhanraj, Vijay
2022-03-01 13:26 ` Jarkko Sakkinen
2022-03-01 13:42 ` Jarkko Sakkinen
2022-03-01 17:48 ` Reinette Chatre
2022-03-02 2:05 ` Jarkko Sakkinen
2022-03-02 2:11 ` Jarkko Sakkinen
2022-03-02 4:03 ` Jarkko Sakkinen
2022-03-02 22:57 ` Reinette Chatre
2022-03-03 16:08 ` Haitao Huang
2022-03-03 21:23 ` Reinette Chatre
2022-03-03 21:44 ` Dave Hansen
2022-03-05 3:19 ` Jarkko Sakkinen
2022-03-06 0:15 ` Jarkko Sakkinen
2022-03-06 0:25 ` Jarkko Sakkinen
2022-03-10 5:43 ` Jarkko Sakkinen
2022-03-10 5:59 ` Jarkko Sakkinen
2022-03-03 23:18 ` Jarkko Sakkinen
2022-03-04 4:03 ` Haitao Huang
2022-03-04 8:30 ` Jarkko Sakkinen
2022-03-04 15:51 ` Haitao Huang
2022-03-05 1:02 ` Jarkko Sakkinen
2022-03-06 14:24 ` Haitao Huang
2022-03-03 23:12 ` Jarkko Sakkinen
2022-03-04 0:48 ` Reinette Chatre
2022-03-10 6:10 ` Jarkko Sakkinen
2022-03-10 18:33 ` Haitao Huang
2022-03-11 12:10 ` Jarkko Sakkinen
2022-03-11 12:16 ` Jarkko Sakkinen
2022-03-11 12:33 ` Jarkko Sakkinen
2022-03-11 17:53 ` Reinette Chatre
2022-03-11 18:11 ` Jarkko Sakkinen
2022-03-11 19:28 ` Reinette Chatre
2022-03-14 3:42 ` Jarkko Sakkinen
2022-03-14 3:45 ` Jarkko Sakkinen
2022-03-14 3:54 ` Jarkko Sakkinen
2022-03-14 15:32 ` Reinette Chatre
2022-03-17 4:30 ` Jarkko Sakkinen
2022-03-17 22:08 ` Reinette Chatre [this message]
2022-03-17 22:51 ` Jarkko Sakkinen
2022-03-18 0:11 ` Reinette Chatre
2022-03-20 0:24 ` Jarkko Sakkinen
2022-03-28 23:22 ` Reinette Chatre
2022-03-30 15:00 ` Jarkko Sakkinen
2022-03-30 15:02 ` Jarkko Sakkinen
2022-03-14 2:49 ` Jarkko Sakkinen
2022-03-14 2:50 ` Jarkko Sakkinen
2022-03-14 2:58 ` Jarkko Sakkinen
2022-03-14 15:39 ` Haitao Huang
2022-03-17 4:34 ` Jarkko Sakkinen
2022-03-17 14:42 ` Haitao Huang
2022-03-17 4:37 ` Jarkko Sakkinen
2022-03-17 14:47 ` Haitao Huang
2022-03-17 7:01 ` Jarkko Sakkinen
2022-03-17 7:11 ` Jarkko Sakkinen
2022-03-17 14:28 ` Haitao Huang
2022-03-17 21:50 ` Jarkko Sakkinen
2022-03-17 22:00 ` Jarkko Sakkinen
2022-03-17 22:23 ` Jarkko Sakkinen
2022-02-08 0:45 ` [PATCH V2 17/32] selftests/sgx: Add test for EPCM permission changes Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 18/32] selftests/sgx: Add test for TCS page " Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 19/32] x86/sgx: Support adding of pages to an initialized enclave Reinette Chatre
2022-02-19 11:57 ` Jarkko Sakkinen
2022-02-19 12:01 ` Jarkko Sakkinen
2022-02-20 18:40 ` Jarkko Sakkinen
2022-02-22 19:19 ` Reinette Chatre
2022-02-23 15:46 ` Jarkko Sakkinen
2022-03-07 16:16 ` Jarkko Sakkinen
2022-02-08 0:45 ` [PATCH V2 20/32] x86/sgx: Tighten accessible memory range after enclave initialization Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 21/32] selftests/sgx: Test two different SGX2 EAUG flows Reinette Chatre
2022-03-07 16:39 ` Jarkko Sakkinen
2022-02-08 0:45 ` [PATCH V2 22/32] x86/sgx: Support modifying SGX page type Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 23/32] x86/sgx: Support complete page removal Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 24/32] Documentation/x86: Introduce enclave runtime management section Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 25/32] selftests/sgx: Introduce dynamic entry point Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 26/32] selftests/sgx: Introduce TCS initialization enclave operation Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 27/32] selftests/sgx: Test complete changing of page type flow Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 28/32] selftests/sgx: Test faulty enclave behavior Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 29/32] selftests/sgx: Test invalid access to removed enclave page Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 30/32] selftests/sgx: Test reclaiming of untouched page Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 31/32] x86/sgx: Free up EPC pages directly to support large page ranges Reinette Chatre
2022-02-08 0:45 ` [PATCH V2 32/32] selftests/sgx: Page removal stress test Reinette Chatre
2022-02-22 20:27 ` [PATCH V2 00/32] x86/sgx and selftests/sgx: Support SGX2 Nathaniel McCallum
2022-02-22 22:39 ` Reinette Chatre
2022-02-23 13:24 ` Nathaniel McCallum
2022-02-23 18:25 ` Reinette Chatre
2022-03-02 16:57 ` Nathaniel McCallum
2022-03-02 21:20 ` Reinette Chatre
2022-03-03 1:13 ` Nathaniel McCallum
2022-03-03 17:49 ` Reinette Chatre
2022-03-04 0:57 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=690d3d8e-6214-dcdd-daaa-48a380114ad7@intel.com \
--to=reinette.chatre@intel.com \
--cc=bp@alien8.de \
--cc=cathy.zhang@intel.com \
--cc=cedric.xing@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=haitao.huang@intel.com \
--cc=haitao.huang@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jarkko@kernel.org \
--cc=kai.huang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sgx@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mark.shanahan@intel.com \
--cc=mingo@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=vijay.dhanraj@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox