Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 19:08:58 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:41:52PM +1200, Kai Huang wrote: > > > Ok, I'll make the changes and you can redo the KVM rest ontop. > > > > > > > Thank you! > > I.e., something like this: Looks good. I'll update KVM part patches based on th

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Borislav Petkov
On Tue, Apr 06, 2021 at 09:41:52PM +1200, Kai Huang wrote: > > Ok, I'll make the changes and you can redo the KVM rest ontop. > > > > Thank you! I.e., something like this: --- From: Sean Christopherson Date: Fri, 19 Mar 2021 20:23:08 +1300 Subject: [PATCH] x86/sgx: Add helpers to expose ECREAT

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 11:32:11 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:24:24PM +1200, Kai Huang wrote: > > Such invalid input has already been handled in handle_encls_xx() before > > calling > > the two helpers in this patch. KVM returns to Qemu and let it decide > > whether to > >

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Borislav Petkov
On Tue, Apr 06, 2021 at 09:24:24PM +1200, Kai Huang wrote: > Such invalid input has already been handled in handle_encls_xx() before > calling > the two helpers in this patch. KVM returns to Qemu and let it decide whether > to > kill or not. The access_ok()s here are trying to catch KVM bug. Wha

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 11:09:01 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 08:59:58PM +1200, Kai Huang wrote: > > OK. My thinking was that, returning negative error value basically means > > guest > > will be killed. > > You need to define how you're going to handle invalid input from the

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Borislav Petkov
On Tue, Apr 06, 2021 at 08:59:58PM +1200, Kai Huang wrote: > OK. My thinking was that, returning negative error value basically means guest > will be killed. You need to define how you're going to handle invalid input from the guest. If that guest is considered malicious, then sure, killing it mak

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 09:40:38 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:44:21AM +1200, Kai Huang wrote: > > The intention was to catch KVM bug, since KVM is the only caller, and in > > current > > implementation KVM won't call this function if @secs is not a valid > > userspace > >

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Borislav Petkov
On Tue, Apr 06, 2021 at 09:44:21AM +1200, Kai Huang wrote: > The intention was to catch KVM bug, since KVM is the only caller, and in > current > implementation KVM won't call this function if @secs is not a valid userspace > pointer. But yes we can also return here, but in this case an exception

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-05 Thread Kai Huang
On Mon, 5 Apr 2021 11:07:59 +0200 Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:23:08PM +1300, Kai Huang wrote: > > + /* > > +* @secs is an untrusted, userspace-provided address. It comes from > > +* KVM and is assumed to be a valid pointer which points somewhere in > > +* user

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-05 Thread Borislav Petkov
On Fri, Mar 19, 2021 at 08:23:08PM +1300, Kai Huang wrote: > + /* > + * @secs is an untrusted, userspace-provided address. It comes from > + * KVM and is assumed to be a valid pointer which points somewhere in > + * userspace. This can fault and call SGX or other fault handlers

[PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-03-19 Thread Kai Huang
From: Sean Christopherson The host kernel must intercept ECREATE to impose policies on guests, and intercept EINIT to be able to write guest's virtual SGX_LEPUBKEYHASH MSR values to hardware before running guest's EINIT so it can run correctly according to hardware behavior. Provide wrappers aro