mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Dave Hansen <dave.hansen@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: Wed, 2 Mar 2022 14:57:45 -0800	[thread overview]
Message-ID: <6f65287a-f69c-971e-be2c-929e327e7ff9@intel.com> (raw)
In-Reply-To: <Yh7Q5fbOtr+6YWaS@iki.fi>

Hi Jarkko,

On 3/1/2022 6:05 PM, Jarkko Sakkinen wrote:
> On Tue, Mar 01, 2022 at 09:48:48AM -0800, Reinette Chatre wrote:
>> Hi Jarkko,
>>
>> On 3/1/2022 5:42 AM, Jarkko Sakkinen wrote:
>>>> With EACCEPTCOPY (kudos to Mark S. for reminding me of this version of
>>>> EACCEPT @ chat.enarx.dev) it is possible to make R and RX pages but
>>>> obviously new RX pages are now out of the picture:
>>>>
>>>>
>>>> 	/*
>>>> 	 * Adding a regular page that is architecturally allowed to only
>>>> 	 * be created with RW permissions.
>>>> 	 * TBD: Interface with user space policy to support max permissions
>>>> 	 * of RWX.
>>>> 	 */
>>>> 	prot = PROT_READ | PROT_WRITE;
>>>> 	encl_page->vm_run_prot_bits = calc_vm_prot_bits(prot, 0);
>>>> 	encl_page->vm_max_prot_bits = encl_page->vm_run_prot_bits;
>>>>
>>>> If that TBD is left out to the final version the page augmentation has a
>>>> risk of a API bottleneck, and that risk can realize then also in the page
>>>> permission ioctls.
>>>>
>>>> I.e. now any review comment is based on not fully known territory, we have
>>>> one known unknown, and some unknown unknowns from unpredictable effect to
>>>> future API changes.
>>
>> The plan to complete the "TBD" in the above snippet was to follow this work
>> with user policy integration at this location. On a high level the plan was
>> for this to look something like:
>>
>>
>>  	/*
>>  	 * Adding a regular page that is architecturally allowed to only
>>  	 * be created with RW permissions.
>>  	 * Interface with user space policy to support max permissions
>>  	 * of RWX.
>>  	 */
>>  	prot = PROT_READ | PROT_WRITE;
>>  	encl_page->vm_run_prot_bits = calc_vm_prot_bits(prot, 0);
>>
>>         if (user space policy allows RWX on dynamically added pages)
>> 	 	encl_page->vm_max_prot_bits = calc_vm_prot_bits(PROT_READ | PROT_WRITE | PROT_EXEC, 0);
>> 	else
>> 		encl_page->vm_max_prot_bits = calc_vm_prot_bits(PROT_READ | PROT_WRITE, 0);
>>
>> The work that follows this series aimed to do the integration with user
>> space policy.
> 
> What do you mean by "user space policy" anyway exactly? I'm sorry but I
> just don't fully understand this.

My apologies - I just assumed that you would need no reminder about this contentious
part of SGX history. Essentially it means that, yes, the kernel could theoretically
permit any kind of access to any file/page, but some accesses are known to generally
be a bad idea - like making memory executable as well as writable - and thus there
are additional checks based on what user space permits before the kernel allows
such accesses.

For example,
mm/mprotect.c:do_mprotect_pkey()->security_file_mprotect()

User policy and SGX has seen significant discussion. Some notable threads:
https://lore.kernel.org/linux-security-module/CALCETrXf8mSK45h7sTK5Wf+pXLVn=Bjsc_RLpgO-h-qdzBRo5Q@mail.gmail.com/
https://lore.kernel.org/linux-security-module/20190619222401.14942-1-sean.j.christopherson@intel.com/
 
> It's too big of a risk to accept this series without X taken care of. Patch
> series should neither have TODO nor TBD comments IMHO. I don't want to ack
> a series based on speculation what might happen in the future.

ok

> 
>>> I think the best way to move forward would be to do EAUG's explicitly with
>>> an ioctl that could also include secinfo for permissions. Then you can
>>> easily do the rest with EACCEPTCOPY inside the enclave.
>>
>> SGX_IOC_ENCLAVE_ADD_PAGES already exists and could possibly be used for
>> this purpose. It already includes SECINFO which may also be useful if
>> needing to later support EAUG of PT_SS* pages.
> 
> You could also simply add SGX_IOC_ENCLAVE_AUGMENT_PAGES and call it a day.

I could, yes.

> And if there is plan to extend SGX_IOC_ENCLAVE_ADD_PAGES what is this weird
> thing added to the #PF handler? Why is it added at all then?

I was just speculating in my response, there is no plan to extend
SGX_IOC_ENCLAVE_ADD_PAGES (that I am aware of).

>> How this could work is user space calls SGX_IOC_ENCLAVE_ADD_PAGES
>> after enclave initialization on any memory region within the enclave where
>> pages are planned to be added dynamically. This ioctl() calls EAUG to add the
>> new pages with RW permissions and their vm_max_prot_bits can be set to the
>> permissions found in the included SECINFO. This will support later EACCEPTCOPY
>> as well as SGX_IOC_ENCLAVE_RELAX_PERMISSIONS
> 
> I don't like this type of re-use of the existing API.

I could proceed with SGX_IOC_ENCLAVE_AUGMENT_PAGES if there is consensus after
considering the user policy question (above) and performance trade-off (more below).

> 
>> The big question is whether communicating user policy after enclave initialization
>> via the SECINFO within SGX_IOC_ENCLAVE_ADD_PAGES is acceptable to all? I would
>> appreciate a confirmation on this direction considering the significant history
>> behind this topic.
> 
> I have no idea because I don't know what is user space policy.

This discussion is about some enclave usages needing RWX permissions
on dynamically added enclave pages. RWX permissions on dynamically added pages is
not something that should blindly be allowed for all SGX enclaves but instead the user
needs to explicitly allow specific enclaves to have such ability. This is equivalent
to (but not the same as) what exists in Linux today with LSM. As seen in
mm/mprotect.c:do_mprotect_pkey()->security_file_mprotect() Linux is able to make
files and memory be both writable and executable, but it would only do so for those
files and memory that the LSM (which is how user policy is communicated, like SELinux)
indicates it is allowed, not blindly do so for all files and all memory.

>>> Putting EAUG to the #PF handler and implicitly call it just too flakky and
>>> hard to make deterministic for e.g. JIT compiler in our use case (not to
>>> mention that JIT is not possible at all because inability to do RX pages).

I understand how SGX_IOC_ENCLAVE_AUGMENT_PAGES can be more deterministic but from
what I understand it would have a performance impact since it would require all memory
that may be needed by the enclave be pre-allocated from outside the enclave and not
just dynamically allocated from within the enclave at the time it is needed.

Would such a performance impact be acceptable?

>> In this series this is indeed not possible because it lacks the user policy
>> integration. JIT will be possible after user policy integration.
> 
> Like this I don't what this series can be used in practice.
> 
> Majority of practical use cases for EDMM boil down to having a way to add
> new executable code (not just Enarx).
> 

Understood.

On 3/1/2022 8:03 PM, Jarkko Sakkinen wrote:
> I'd actually to leave out permission change madness completely out of this
> patch set, as we all know it is a grazy beast of microarchitecture. For
> user space having that is less critical than having executable pages.
> 
> Simply with EAUG/EACCEPTCOPY you can already populate enclave with any
> permissions you had in mind. Augmenting alone would be logically consistent
> patch set that is actually usable for many workloads.

Support for permission changes is required in order to support dynamically added
pages (EAUG pages) to be made executable. Yes, you could make
a dynamically added page have executable EPCM permissions using EACCEPTCOPY
but the kernel is still required to make the PTE executable.

> Now there is half-broken augmenting (this is even writtend down to the TBD
> comment) and complex code for EMODPR and EMODT that is usable only for
> kselftests and not much else before there is fully working augmenting.
> 
> This way we get actually sound patch set that is easy to review and apply
> to the mainline. It is also factors easier for you to iterate a smaller
> set of patches.
> 
> After this it is so much easier to start to look at remaining functionality,
> and at the same time augmenting part can be stress tested with real-world
> code and it will mature quickly.
> 
> This whole thing *really* needs a serious U-turn on how it is delivered to
> the upstream. Sometimes it is better just to admit that this didn't start
> with the right foot.

As mentioned above, from what I understand the support for (as you state) the
"majority of practical use cases" on dynamically added pages do require
supporting permission changes also. It thus seems to me that it would help
consuming this feature if dynamic addition of pages and permission changes
are presented together. The SGX2 functionality that remains after that is the
changing of page type, which forms part of the page removal flow. In this
regard I also find that presenting the page addition flow at the same time
as the page removal flow would make these features easier to consume. I
think supporting the addition of pages and leaving page removal to
"future work" would be similarly frustrating to consume.

Reinette

  parent reply	other threads:[~2022-03-03  0:11 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 [this message]
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
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=6f65287a-f69c-971e-be2c-929e327e7ff9@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=bp@alien8.de \
    --cc=cathy.zhang@intel.com \
    --cc=cedric.xing@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@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

all inboxes | Powered by JetHome®