RE: [PATCH v11 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-08-08 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, August 7, 2025 3:24 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v11 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-08-08 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, August 7, 2025 3:15 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v11 3/5] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN]

2025-08-08 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, August 7, 2025 2:42 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v11 3/5] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN]

2025-08-08 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, August 7, 2025 2:50 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v11 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag

2025-08-08 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, August 7, 2025 2:40 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v11 1/5] x86/sgx: Introduce functions to count the sgx_(vepc_)open()

2025-08-08 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, August 7, 2025 2:39 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v10 4/6] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN]

2025-08-05 Thread Reshetova, Elena
> -Original Message- > From: Hansen, Dave > Sent: Monday, August 4, 2025 5:20 PM > To: Reshetova, Elena > Cc: jar...@kernel.org; sea...@google.com; Huang, Kai > ; mi...@kernel.org; linux-...@vger.kernel.org; linux- > ker...@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v10 5/6] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-08-04 Thread Reshetova, Elena
> -Original Message- > From: Hansen, Dave > Sent: Friday, August 1, 2025 8:13 PM > To: Reshetova, Elena > Cc: jar...@kernel.org; sea...@google.com; Huang, Kai > ; mi...@kernel.org; linux-...@vger.kernel.org; linux- > ker...@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v10 4/6] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN]

2025-08-04 Thread Reshetova, Elena
> -Original Message- > From: Hansen, Dave > Sent: Friday, August 1, 2025 7:57 PM > To: Reshetova, Elena > Cc: jar...@kernel.org; sea...@google.com; Huang, Kai > ; mi...@kernel.org; linux-...@vger.kernel.org; linux- > ker...@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v10 2/6] x86/sgx: Introduce functions to count the sgx_(vepc_)open()

2025-08-04 Thread Reshetova, Elena
> -Original Message- > From: Hansen, Dave > Sent: Friday, August 1, 2025 7:45 PM > To: Reshetova, Elena > Cc: jar...@kernel.org; sea...@google.com; Huang, Kai > ; mi...@kernel.org; linux-...@vger.kernel.org; linux- > ker...@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v10 1/6] x86/sgx: Convert sgx_(vepc_)open to __sgx_(vepc_)open

2025-08-04 Thread Reshetova, Elena
> On 8/1/25 04:25, Elena Reshetova wrote: > > In order to introduce the counting of active sgx users on top > > of clean functions that allocate vepc structures, covert existing > > sgx_(vepc_)open to __sgx_(vepc_)open. Later patch will introduce the > > top level wrappers that manage the usage c

RE: [PATCH v9 6/6] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-07-28 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Friday, July 25, 2025 12:43 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; linux-...@vger.kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linu

RE: [PATCH v9 6/6] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-07-24 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, July 24, 2025 2:13 PM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v9 6/6] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-07-24 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, July 24, 2025 1:18 PM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v9 2/6] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-07-24 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Thursday, July 24, 2025 1:25 PM > To: Reshetova, Elena ; Hansen, Dave > > Cc: sea...@google.com; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; jar...@kernel.org; > Annapurve, Vishal ; linux-kernel@vg

RE: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-07-21 Thread Reshetova, Elena
> -Original Message- > From: Hansen, Dave > Sent: Monday, July 21, 2025 7:48 PM > To: Reshetova, Elena > Cc: jar...@kernel.org; sea...@google.com; Huang, Kai > ; mi...@kernel.org; linux-...@vger.kernel.org; linux- > ker...@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v8 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-07-21 Thread Reshetova, Elena
> > On Sat, Jul 19, 2025 at 02:15:16PM +0300, Jarkko Sakkinen wrote: > > On Tue, Jul 15, 2025 at 03:40:18PM +0300, Elena Reshetova wrote: > > > Currently SGX does not have a global counter to count the > > > active users from userspace or hypervisor. Implement such a counter, > > > sgx_usage_count

RE: [PATCH v8 0/5] Enable automatic SVN updates for SGX enclaves

2025-07-18 Thread Reshetova, Elena
> On Tue, 2025-07-15 at 15:40 +0300, Elena Reshetova wrote: > > Changes since v7 following reviews by Dave: > > > > - change sgx_usage_count to be a normal int type > > and greatly simplify the sgx_inc_usage_count func. > > This results in requiring a mutex for each sgx_(vepc_)open > > but giv

RE: [PATCH v7 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-07-14 Thread Reshetova, Elena
> On 7/11/25 09:50, Elena Reshetova wrote: > > == Background == > > > > ENCLS[EUPDATESVN] is a new SGX instruction [1] which allows enclave > > attestation to include information about updated microcode SVN without a > > reboot. Before an EUPDATESVN operation can be successful, all SGX memory > > (

RE: [PATCH v6 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-05-29 Thread Reshetova, Elena
> > > > +/** > > + * sgx_updatesvn() - Attempt to call ENCLS[EUPDATESVN]. > > sgx_updatesvn() -> sgx_update_svn(): > > arch/x86/kernel/cpu/sgx/main.c:941: warning: expecting prototype for > sgx_updatesvn(). Prototype was for sgx_update_svn() instead > > > > + * This instruction attempts to upd

RE: [PATCH v6 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-27 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Tuesday, May 27, 2025 2:20 AM > To: Reshetova, Elena ; jar...@kernel.org > Cc: Raynor, Scott ; Hansen, Dave > ; mi...@kernel.org; Scarlata, Vincent R > ; x...@kernel.org; linux-...@vger.kernel.org; > Annapurv

RE: [PATCH v6 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-26 Thread Reshetova, Elena
> -Original Message- > From: Jarkko Sakkinen > Sent: Saturday, May 24, 2025 2:46 AM > To: Hansen, Dave > Cc: Reshetova, Elena ; sea...@google.com; > Huang, Kai ; mi...@kernel.org; linux- > s...@vger.kernel.org; linux-kernel@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v6 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-26 Thread Reshetova, Elena
> -Original Message- > From: Jarkko Sakkinen > Sent: Friday, May 23, 2025 6:54 PM > To: Reshetova, Elena > Cc: Hansen, Dave ; sea...@google.com; Huang, Kai > ; mi...@kernel.org; linux-...@vger.kernel.org; linux- > ker...@vger.kernel.org; x...@kernel.org; Mallick

RE: [PATCH v6 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-05-26 Thread Reshetova, Elena
> > + /* > > +* SVN was already up-to-date. This is the most > > +* common case. > > +*/ > > + if (ret == SGX_NO_UPDATE) > > + return 0; > > + > > + /* > > +* SVN update failed due to lack of entropy in DRNG. > > +* Indicate to userspace that it should retry. > >

RE: [PATCH v6 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag

2025-05-22 Thread Reshetova, Elena
> -Original Message- > From: Huang, Kai > Sent: Friday, May 23, 2025 3:18 AM > To: Reshetova, Elena ; Hansen, Dave > > Cc: Raynor, Scott ; sea...@google.com; > mi...@kernel.org; Scarlata, Vincent R ; > x...@kernel.org; jar...@kernel.org; Annapurve, Vishal > ; l

RE: [PATCH v5 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-19 Thread Reshetova, Elena
> > On Mon, May 19, 2025 at 10:24:31AM +0300, Elena Reshetova wrote: > > SGX enclaves have an attestation mechanism. An enclave might, > > for instance, need to attest to its state before it is given > > a special decryption key. Since SGX must trust the CPU microcode, > > attestation incorporat

RE: [PATCH v5 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-19 Thread Reshetova, Elena
> > Yes, meaning is different, see above. > > So that's rather convoluted: > > atomic64_inc_not_zero(): returns 1 on successful increase, 0 on > failure > sgx_inc_usage_count(): returns 0 on successful increase, 1 on > failure > sgx_open():returns 0 on

RE: [PATCH v5 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-05-19 Thread Reshetova, Elena
> > > > > Why not just fail sgx_open() (e.g., return -EBUSY, or -EAGAIN) in that > > > case? > > > Userspace can then retry? > > > > The idea on the patch was that such a scenario where we run out of entropy > > should not happen in real life unless RDSEED is under stress (in case we > > accident

RE: [PATCH v5 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-05-19 Thread Reshetova, Elena
> +/** > > + * sgx_updatesvn() - Attempt to call ENCLS[EUPDATESVN] > > + * If EPC is empty, this instruction attempts to update CPUSVN to the > > + * currently loaded microcode update SVN and generate new > > + * cryptographic assets.sgx_updatesvn() Most of the time, there will > > Is there somet

RE: [PATCH v5 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-19 Thread Reshetova, Elena
> Maybe just use raw atomic_inc() and atomic_dec() at the sites? > > IMHO, it makes only sense to wrap, when it makes sense to wrap. You mean for this patch or overall? For overall we discussed in v4 why we would like to raise it to atomic64. Or do I misunderstand your comment? Best Regards, Ele

RE: [PATCH v5 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-19 Thread Reshetova, Elena
> > > > diff --git a/arch/x86/kernel/cpu/sgx/driver.c > > > b/arch/x86/kernel/cpu/sgx/driver.c > > > > index 7f8d1e11dbee..b5ffe104af4c 100644 > > > > --- a/arch/x86/kernel/cpu/sgx/driver.c > > > > +++ b/arch/x86/kernel/cpu/sgx/driver.c > > > > @@ -19,6 +19,7 @@ static int sgx_open(struct inode *in

RE: [PATCH v5 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-19 Thread Reshetova, Elena
> On Mon, 2025-05-19 at 10:24 +0300, Elena Reshetova wrote: > > Currently SGX does not have a global counter to count the > > active users from userspace or hypervisor. Implement such a counter, > > sgx_usage_count. It will be used by the driver when attempting > > to call EUPDATESVN SGX instructio

RE: [PATCH v5 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag

2025-05-19 Thread Reshetova, Elena
> * Elena Reshetova wrote: > > > Add a flag indicating whenever ENCLS[EUPDATESVN] SGX instruction > > is supported. This will be used by SGX driver to perform CPU > > SVN updates. > > > > Signed-off-by: Elena Reshetova > > --- > > arch/x86/include/asm/cpufeatures.h | 1 + > > arch/x86/ke

RE: [PATCH v5 1/5] x86/sgx: Introduce a counter to count the sgx_(vepc_)open()

2025-05-19 Thread Reshetova, Elena
> On Mon, 2025-05-19 at 10:47 +, Huang, Kai wrote: > > > +/* Counter to count the active SGX users */ > > > +static atomic64_t sgx_usage_count; > > > + > > > +int sgx_inc_usage_count(void) > > > +{ > > > + atomic64_inc(&sgx_usage_count); > > > + return 0; > > > +} > > > > What's the purpose of

RE: [PATCH v5 4/5] x86/sgx: Implement ENCLS[EUPDATESVN]

2025-05-19 Thread Reshetova, Elena
> On Mon, 2025-05-19 at 10:24 +0300, Elena Reshetova wrote: > > The SGX attestation architecture assumes a compromise > > of all running enclaves and cryptographic assets > > (like internal SGX encryption keys) whenever a microcode > > update affects SGX. To mitigate the impact of this presumed > >

RE: [PATCH v5 3/5] x86/sgx: Define error codes for use by ENCLS[EUPDATESVN]

2025-05-19 Thread Reshetova, Elena
> On Mon, 2025-05-19 at 10:24 +0300, Elena Reshetova wrote: > > Add error codes for ENCLS[EUPDATESVN], then SGX CPUSVN update > > process can know the execution state of EUPDATESVN and notify > > userspace. > > > > Signed-off-by: Elena Reshetova > > --- > > [...] > > > > > /** > > @@ -73,6 +74,

RE: [PATCH v5 2/5] x86/cpufeatures: Add X86_FEATURE_SGX_EUPDATESVN feature flag

2025-05-19 Thread Reshetova, Elena
> On Mon, 2025-05-19 at 10:24 +0300, Elena Reshetova wrote: > > Add a flag indicating whenever ENCLS[EUPDATESVN] SGX instruction > > is supported. This will be used by SGX driver to perform CPU > > SVN updates. > > > > Signed-off-by: Elena Reshetova > > --- > > arch/x86/include/asm/cpufeatures.

RE: [PATCH v5 5/5] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-19 Thread Reshetova, Elena
> * Elena Reshetova wrote: > > > @@ -19,10 +19,15 @@ static int sgx_open(struct inode *inode, struct file > *file) > > struct sgx_encl *encl; > > int ret; > > > > + ret = sgx_inc_usage_count(); > > + if (ret) > > + return -EBUSY; > > So if sgx_inc_usage_count() returns no

RE: [PATCH v4 1/1] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-14 Thread Reshetova, Elena
> > >>> +static bool sgx_has_eupdatesvn; > > >> > > >> We have CPUID "caches" of sorts. Why open code this? > > > > > > You mean X86_FEATURE_*? > > > > Yes. > > > > > SGX CPUID is only defined in SGX code currently (btw, I am not sure > > > why they are made special) so it doesn’t support this. > >

RE: [PATCH v4 1/1] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-12 Thread Reshetova, Elena
> On Wed, May 07, 2025 at 02:14:00PM +0300, Elena Reshetova wrote: > > > diff --git a/arch/x86/kernel/cpu/sgx/driver.c > b/arch/x86/kernel/cpu/sgx/driver.c > > index 7f8d1e11dbee..669e44d61f9f 100644 > > --- a/arch/x86/kernel/cpu/sgx/driver.c > > +++ b/arch/x86/kernel/cpu/sgx/driver.c > > @@ -19,6

RE: [PATCH v4 1/1] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-12 Thread Reshetova, Elena
> >>> +static bool sgx_has_eupdatesvn; > >> > >> We have CPUID "caches" of sorts. Why open code this? > > > > You mean X86_FEATURE_*? > > Yes. > > > SGX CPUID is only defined in SGX code currently (btw, I am not sure > > why they are made special) so it doesn’t support this. > > It's only used i

RE: [PATCH v4 1/1] x86/sgx: Enable automatic SVN updates for SGX enclaves

2025-05-08 Thread Reshetova, Elena
Thank you very much for your detailed review, Dave! Responses inline below. > On 5/7/25 04:14, Elena Reshetova wrote: > > In case an SGX vulnerability is discovered and TCB recovery > > for SGX is triggered, Intel specifies a process that must be > > followed for a given vulnerability. Steps to

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-05-02 Thread Reshetova, Elena
> > On Wed, Apr 30, 2025 at 06:53:32AM +, Reshetova, Elena wrote: > > 2. Switch to Sean's approach to execute EUPDATESVN during the > sgx_open(). > > Btw, Sean do you agree that we don't gain much doing it second time during > > release() given the mic

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-29 Thread Reshetova, Elena
> On 4/29/25 04:44, Reshetova, Elena wrote: > >> On 4/25/25 14:58, Sean Christopherson wrote: > >>> On Fri, Apr 25, 2025, Dave Hansen wrote: > >>>> On 4/25/25 14:04, Sean Christopherson wrote: > >>>>> Userspace is going to be waiting o

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-29 Thread Reshetova, Elena
> On 4/25/25 14:58, Sean Christopherson wrote: > > On Fri, Apr 25, 2025, Dave Hansen wrote: > >> On 4/25/25 14:04, Sean Christopherson wrote: > >>> Userspace is going to be waiting on ->release() no matter what. > >> Unless it isn't even involved and it happens automatically. > > With my Google h

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-27 Thread Reshetova, Elena
> So then why on earth is the kernel implementing automatic updates? I read > back > through most of the cover letters, and IIUC, we went straight from "destroy > all > enclaves and force an update" to "blindly try to do EUPDATESVN every time > the > number of enclaves goes from 0=>1". Those are

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-24 Thread Reshetova, Elena
> On Thu, Apr 24, 2025, Elena Reshetova wrote: > > > On Thu, Apr 24, 2025, Elena Reshetova wrote: > > > +void sgx_dec_usage_count(void) > > > +{ > > > + if (atomic_dec_return(&sgx_usage_count)) > > > + return; > > > + > > > + guard(mutex)(&sgx_svn_lock); > > > + > > > + if (atomic_read(&sgx

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-24 Thread Reshetova, Elena
> On Thu, Apr 24, 2025, Elena Reshetova wrote: > > > On Tue, Apr 22, 2025, Kai Huang wrote: > > > > On Fri, 2025-04-18 at 07:55 -0700, Sean Christopherson wrote: > > > > > On Tue, Apr 15, 2025, Elena Reshetova wrote: > > > > > That said, handling this deep in the bowels of EPC page allocation > see

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-24 Thread Reshetova, Elena
> On Tue, Apr 22, 2025, Kai Huang wrote: > > On Fri, 2025-04-18 at 07:55 -0700, Sean Christopherson wrote: > > > On Tue, Apr 15, 2025, Elena Reshetova wrote: > > > That said, handling this deep in the bowels of EPC page allocation seems > > > unnecessary. The only way for there to be no active EP

RE: [PATCH v3 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-16 Thread Reshetova, Elena
> On Tue, 2025-04-15 at 14:51 +0300, Elena Reshetova wrote: > > SGX architecture introduced a new instruction called EUPDATESVN > > "a new ENCLS leaf function EUPDATESVN"? Yes, you are right, better wording, will fix. > > > to Ice Lake. It allows updating security SVN version, given that EPC

RE: [PATCH v3 1/2] x86/sgx: Use sgx_nr_used_pages for EPC page count instead of sgx_nr_free_pages

2025-04-16 Thread Reshetova, Elena
> On Tue, 2025-04-15 at 14:51 +0300, Elena Reshetova wrote: > > sgx_nr_free_pages is an atomic that is used to keep track of > > free EPC pages and detect whenever page reclaiming should start. > > Since successful execution of ENCLS[EUPDATESVN] requires empty > > The mentioning of ENCLS[EUPDATE

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-14 Thread Reshetova, Elena
> > On Tue, Apr 08, 2025 at 06:54:14AM +, Reshetova, Elena wrote: > > > > > > On Tue, Apr 08, 2025 at 09:40:14AM +0300, Jarkko Sakkinen wrote: > > > > On Tue, Apr 08, 2025 at 12:06:32AM +, Huang, Kai wrote: > > > > > On Mon

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-07 Thread Reshetova, Elena
> > On Tue, Apr 08, 2025 at 09:40:14AM +0300, Jarkko Sakkinen wrote: > > On Tue, Apr 08, 2025 at 12:06:32AM +, Huang, Kai wrote: > > > On Mon, 2025-04-07 at 08:23 +0000, Reshetova, Elena wrote: > > > > > On Fri, Apr 04, 2025 at 06:53:17AM +, Reshetov

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-07 Thread Reshetova, Elena
> On Fri, Apr 04, 2025 at 06:53:17AM +0000, Reshetova, Elena wrote: > > > On Wed, Apr 02, 2025 at 01:11:25PM +0000, Reshetova, Elena wrote: > > > > > > current SGX kernel code does not handle such errors in any other > way > > > > > > than not

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-05 Thread Reshetova, Elena
> > On Fri, Mar 28, 2025 at 07:50:43PM +0200, Jarkko Sakkinen wrote: > > On Fri, Mar 28, 2025 at 02:57:41PM +0200, Elena Reshetova wrote: > > > SGX architecture introduced a new instruction called EUPDATESVN > > > to Ice Lake. It allows updating security SVN version, given that EPC > > > is comple

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-04 Thread Reshetova, Elena
> On Mon, Mar 31, 2025 at 07:26:45AM +0000, Reshetova, Elena wrote: > > > > > + default: > > > > > + pr_err("EUPDATESVN: unknown error %d\n", ret); > > > > > + break; > > > > > + } > >

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-03 Thread Reshetova, Elena
> On Wed, Apr 02, 2025 at 01:11:25PM +0000, Reshetova, Elena wrote: > > > > current SGX kernel code does not handle such errors in any other way > > > > than notifying that operation failed for other ENCLS leaves. So, I don't > > > > see why ENCLS[E

RE: [PATCH v2 2/2] x86/sgx: Implement EUPDATESVN and opportunistically call it during first EPC page alloc

2025-04-02 Thread Reshetova, Elena
> On Tue, Apr 01, 2025 at 09:35:33AM +0000, Reshetova, Elena wrote: > > > > None of these exceptional conditions are fatal or present an > > > > immediate danger to the system security. So, allowing the re-tries > > > > seems logical in this case.

RE: [PATCH 1/4] x86/sgx: Add total number of EPC pages

2025-03-28 Thread Reshetova, Elena
> oN Thu, Mar 27, 2025 at 03:29:53PM +0000, Reshetova, Elena wrote: > > > > > On Mon, Mar 24, 2025 at 12:12:41PM +, Reshetova, Elena wrote: > > > > > On Fri, Mar 21, 2025 at 02:34:40PM +0200, Elena Reshetova wrote: > > > > > > In order to

RE: [PATCH 1/4] x86/sgx: Add total number of EPC pages

2025-03-28 Thread Reshetova, Elena
> On Fri, Mar 28, 2025 at 08:07:24AM +0000, Reshetova, Elena wrote: > > > Yes but obviously I cannot promise that I'll accept this as it is > > > until I see the final version > > > > Are you saying you prefer *this version with spinlock* vs. > >

RE: [PATCH 4/4] x86/sgx: Implement ENCLS[EUPDATESVN] and opportunistically call it during first EPC page alloc

2025-03-28 Thread Reshetova, Elena
> On Thu, Mar 27, 2025 at 03:42:30PM +0000, Reshetova, Elena wrote: > > > > > > + case SGX_NO_UPDATE: > > > > > > + pr_debug("EUPDATESVN was successful, but CPUSVN > was not > > > > > updated, " > > > > &

RE: [PATCH 4/4] x86/sgx: Implement ENCLS[EUPDATESVN] and opportunistically call it during first EPC page alloc

2025-03-27 Thread Reshetova, Elena
> On Mon, Mar 24, 2025 at 12:26:38PM +0000, Reshetova, Elena wrote: > > > > > On Fri, Mar 21, 2025 at 02:34:43PM +0200, Elena Reshetova wrote: > > > > SGX architecture introduced a new instruction called EUPDATESVN [1] > > > > to Ice Lake. It allows upd

RE: [PATCH 3/4] x86/sgx: Define error codes for ENCLS[EUPDATESVN]

2025-03-27 Thread Reshetova, Elena
> On Mon, Mar 24, 2025 at 12:21:14PM +0000, Reshetova, Elena wrote: > > > > > > > On Fri, Mar 21, 2025 at 02:34:42PM +0200, Elena Reshetova wrote: > > > > Add error codes for ENCLS[EUPDATESVN], then SGX CPUSVN update > > > > pr

RE: [PATCH 2/4] x86/sgx: Change counter sgx_nr_free_pages -> sgx_nr_used_pages

2025-03-27 Thread Reshetova, Elena
> On Mon, Mar 24, 2025 at 12:19:37PM +0000, Reshetova, Elena wrote: > > > > > On Fri, Mar 21, 2025 at 02:34:41PM +0200, Elena Reshetova wrote: > > > > sgx_nr_free_pages is an atomic that is used to keep track of > > > > free EPC pages and detect whenever p

RE: [PATCH 1/4] x86/sgx: Add total number of EPC pages

2025-03-27 Thread Reshetova, Elena
> On Mon, Mar 24, 2025 at 12:12:41PM +0000, Reshetova, Elena wrote: > > > On Fri, Mar 21, 2025 at 02:34:40PM +0200, Elena Reshetova wrote: > > > > In order to successfully execute ENCLS[EUPDATESVN], EPC must be > empty. > > > > SGX already has a vari

RE: [PATCH 3/4] x86/sgx: Define error codes for ENCLS[EUPDATESVN]

2025-03-24 Thread Reshetova, Elena
> On Fri, Mar 21, 2025 at 02:34:42PM +0200, Elena Reshetova wrote: > > Add error codes for ENCLS[EUPDATESVN], then SGX CPUSVN update > > process can know the execution state of EUPDATESVN. > > > > Enumerate the error codes. You mean in the commit message or? > Do we need all of the three ad

RE: [PATCH 4/4] x86/sgx: Implement ENCLS[EUPDATESVN] and opportunistically call it during first EPC page alloc

2025-03-24 Thread Reshetova, Elena
> On Fri, Mar 21, 2025 at 02:34:43PM +0200, Elena Reshetova wrote: > > SGX architecture introduced a new instruction called EUPDATESVN [1] > > to Ice Lake. It allows updating security SVN version, given that EPC > > is completely empty. The latter is required for security reasons > > in order to

RE: [PATCH 2/4] x86/sgx: Change counter sgx_nr_free_pages -> sgx_nr_used_pages

2025-03-24 Thread Reshetova, Elena
> On Fri, Mar 21, 2025 at 02:34:41PM +0200, Elena Reshetova wrote: > > sgx_nr_free_pages is an atomic that is used to keep track of > > free EPC pages and detect whenever page reclaiming should start. > > Since successful execution of ENCLS[EUPDATESVN] requires empty > > EPC and a fast way of che

RE: [PATCH 1/4] x86/sgx: Add total number of EPC pages

2025-03-24 Thread Reshetova, Elena
> On Fri, Mar 21, 2025 at 02:34:40PM +0200, Elena Reshetova wrote: > > In order to successfully execute ENCLS[EUPDATESVN], EPC must be empty. > > SGX already has a variable sgx_nr_free_pages that tracks free > > EPC pages. Add a new variable, sgx_nr_total_pages, that will keep > > track of total nu

RE: [PATCH 0/3] Convert nsproxy, groups, and creds to refcount_t

2020-06-18 Thread Reshetova, Elena
> > I have these ones also here in case anyone is interested: > > https://github.com/ereshetova/linux-stable/commits/refcount_t_fs > > https://github.com/ereshetova/linux-stable/commits/refcount_t_block > > > > They haven't been rebased for a while, but if there is an interest, > > I can certainly

RE: [PATCH 0/3] Convert nsproxy, groups, and creds to refcount_t

2020-06-14 Thread Reshetova, Elena
> On Mon, Jun 15, 2020 at 10:10:08AM +0800, Xiaoming Ni wrote: > > On 2020/6/13 2:34, Kees Cook wrote: > > > This series was never applied[1], and was recently pointed out as > > > missing[2]. If someone has a tree for this, please take it. Otherwise, > > > please Ack and I'll send it to Linus. > >

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-07-31 Thread Reshetova, Elena
>> The in-stack randomization is really a very small change both code wise and >> logic wise. >> It does not affect real workloads and does not require enablement of other >> features (such as GCC plugins). >> So, I think we should really reconsider its inclusion. >I'd agree: the code is tiny and

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-07-29 Thread Reshetova, Elena
Ingo, Andy, I want to summarize here the data (including the performance numbers) and reasoning for the in-stack randomization feature. I have organized it in a simple set of Q&A below. Q: Why do we need in-stack per-syscall randomization when we already have all known attack vectors covered with

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-29 Thread Reshetova, Elena
> I confess I've kind of lost the plot on the performance requirements > at this point. Instead of measuring and evaluating potential > solutions, can we try to approach this from the opposite direction and > ask what the requirements are? > > What's the maximum number of CPU cycles that we are a

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-28 Thread Reshetova, Elena
> > With 5 bits there's a ~96.9% chance of crashing the system in an attempt, > > the exploit cannot be used for a range of attacks, including spear > > attacks and fast-spreading worms, right? A crashed and inaccessible > > system also increases the odds of leaving around unfinished attack code >

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-09 Thread Reshetova, Elena
> > I find it ridiculous that even with 4K blocked get_random_bytes(), which > > gives us 32k bits, which with 5 bits should amortize the RNG call to > > something like "once per 6553 calls", we still see 17% overhead? It's > > either a measurement artifact, or something doesn't compute. > > If

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-09 Thread Reshetova, Elena
> * Reshetova, Elena wrote: > > > > * Reshetova, Elena wrote: > > > > > > > CONFIG_PAGE_TABLE_ISOLATION=n: > > > > > > > > base: Simple syscall: 0.0510 > > > > microsecon

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-08 Thread Reshetova, Elena
> * Reshetova, Elena wrote: > > > CONFIG_PAGE_TABLE_ISOLATION=n: > > > > base: Simple syscall: 0.0510 microseconds > > get_random_bytes(4096 bytes buffer): Simple syscall: 0.0597 microseconds > > > > So, pure speed w

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-08 Thread Reshetova, Elena
.. > > rdrand (calling every 8 syscalls): Simple syscall: 0.0795 microseconds > > You could try something like: > u64 rand_val = cpu_var->syscall_rand > > while (unlikely(rand_val == 0)) > rand_val = rdrand64(); > > stack_offset = rand_val & 0xff; > rand_val

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-06 Thread Reshetova, Elena
> * Andy Lutomirski wrote: > > > Or we decide that calling get_random_bytes() is okay with IRQs off and > > this all gets a bit simpler. > > BTW., before we go down this path any further, is the plan to bind this > feature to a real CPU-RNG capability, i.e. to the RDRAND instruction, > which exc

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-06 Thread Reshetova, Elena
> From: Reshetova, Elena > > Sent: 03 May 2019 17:17 > ... > > rdrand (calling every 8 syscalls): Simple syscall: 0.0795 microseconds > > You could try something like: > u64 rand_val = cpu_var->syscall_rand > > while (unlikely(rand_val == 0))

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-05 Thread Reshetova, Elena
>> On Fri, May 3, 2019 at 9:40 AM David Laight wrote: > > > > That gives you 10 system calls per rdrand instruction > > and mostly takes the latency out of line. > > Do we really want to do this? What is the attack scenario? > > With no VLA's, and the stackleak plugin, what's the upside? Are we

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-03 Thread Reshetova, Elena
> * David Laight wrote: > > > It has already been measured - it is far too slow. > > I don't think proper buffering was tested, was it? Only a per syscall > RDRAND overhead which I can imagine being not too good. > Well, I have some numbers, but I am struggling to understand one aspect there.

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-02 Thread Reshetova, Elena
From: Reshetova, Elena > > Sent: 30 April 2019 18:51 > ... > > +unsigned char random_get_byte(void) > > +{ > > +struct rnd_buffer *buffer = &get_cpu_var(stack_rand_offset); > > +unsigned char res; > > + > > +

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-05-02 Thread Reshetova, Elena
> From: Reshetova, Elena > > Sent: 30 April 2019 18:51 > ... > > I guess this is true, so I did a quick implementation now to estimate the > > performance hits. > > Here are the preliminary numbers (proper ones will take a bit more time): > > > >

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-30 Thread Reshetova, Elena
> > > On Apr 29, 2019, at 12:46 AM, Reshetova, Elena > wrote: > > > > > >>>> On Apr 26, 2019, at 7:01 AM, Theodore Ts'o wrote: > >>> > > > >> It seems to me > >> that we should be using the “fast-erasure” constructi

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-29 Thread Reshetova, Elena
> On Fri, Apr 26, 2019 at 10:01:02AM -0400, Theodore Ts'o wrote: > > On Fri, Apr 26, 2019 at 11:33:09AM +0000, Reshetova, Elena wrote: > > > Adding Eric and Herbert to continue discussion for the chacha part. > > > So, as a short summary I am trying to fi

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-29 Thread Reshetova, Elena
> On Fri, Apr 26, 2019 at 11:33:09AM +0000, Reshetova, Elena wrote: > > Adding Eric and Herbert to continue discussion for the chacha part. > > So, as a short summary I am trying to find out a fast (fast enough to be > > used per > syscall > > invocation) source o

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-29 Thread Reshetova, Elena
> > On Apr 26, 2019, at 7:01 AM, Theodore Ts'o wrote: > > > >> On Fri, Apr 26, 2019 at 11:33:09AM +, Reshetova, Elena wrote: > >> Adding Eric and Herbert to continue discussion for the chacha part. > >> So, as a short summary I am trying to find

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-26 Thread Reshetova, Elena
> Hi, > > Sorry for the delay - Easter holidays + I was trying to arrange my brain > around > proposed options. > Here what I think our options are with regards to the source of randomness: > > 1) rdtsc or variations based on it (David proposed some CRC-based variants for > example) > 2) prandom

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-25 Thread Reshetova, Elena
> From: Reshetova, Elena > > Sent: 24 April 2019 12:43 > > > > Sorry for the delay - Easter holidays + I was trying to arrange my brain > > around > proposed options. > > Here what I think our options are with regards to the source of randomness: > > >

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-24 Thread Reshetova, Elena
Hi, Sorry for the delay - Easter holidays + I was trying to arrange my brain around proposed options. Here what I think our options are with regards to the source of randomness: 1) rdtsc or variations based on it (David proposed some CRC-based variants for example) 2) prandom-based options 3

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-16 Thread Reshetova, Elena
> On Tue, Apr 16, 2019 at 11:10:16AM +0000, Reshetova, Elena wrote: > > > > > > The kernel can execute millions of syscalls per second, I'm pretty sure > > > there's a statistical attack against: > > > > > > * This is a maximally equid

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-16 Thread Reshetova, Elena
> So a couple of comments; I wasn't able to find the full context for > this patch, and looking over the thread on kernel-hardening from late > February still left me confused exactly what attacks this would help > us protect against (since this isn't my area and I didn't take the > time to read al

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-16 Thread Reshetova, Elena
Adding Theodore & Daniel since I guess they are the best positioned to comment on exact strengths of prandom. See my comments below. > * Reshetova, Elena wrote: > > > > 4) > > > > > > But before you tweak the patch, a more fundamental question: > > &

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-15 Thread Reshetova, Elena
Hi Ingo, Thank you for your feedback! See my comments below. > * Elena Reshetova wrote: > > > This is an example of produced assembly code for gcc x86_64: > > > > ... > > add_random_stack_offset(); > > 0x810022e9 callq 0x81459570 > > 0x810022ee movzbl %al,%eax > >

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-11 Thread Reshetova, Elena
> On Wed, Apr 10, 2019 at 3:24 AM Reshetova, Elena > wrote: > > > > > > > > > On Mon, Apr 08, 2019 at 09:13:58AM +0300, Elena Reshetova wrote: > > > > > > diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c > > > > > &g

RE: [PATCH 1/1] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-10 Thread Reshetova, Elena
> * Elena Reshetova wrote: > > > 2) Andy's tests, misc-tests: ./timing_test_64 10M sys_enosys > > base:1000 loops in 1.62224s > > = 162.22 nsec / loop > > random_offset (prandom_u32() every syscall): 1000 loops in 1.64660s > > = > 166.2

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-10 Thread Reshetova, Elena
> > > On Mon, Apr 08, 2019 at 09:13:58AM +0300, Elena Reshetova wrote: > > > > diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c > > > > index 7bc105f47d21..38ddc213a5e9 100644 > > > > --- a/arch/x86/entry/common.c > > > > +++ b/arch/x86/entry/common.c > > > > @@ -35,6 +35,12 @@ > >

RE: [PATCH] x86/entry/64: randomize kernel stack offset upon syscall

2019-04-10 Thread Reshetova, Elena
> * Josh Poimboeuf wrote: > > > On Mon, Apr 08, 2019 at 09:13:58AM +0300, Elena Reshetova wrote: > > > diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c > > > index 7bc105f47d21..38ddc213a5e9 100644 > > > --- a/arch/x86/entry/common.c > > > +++ b/arch/x86/entry/common.c > > > @@ -35,

  1   2   3   >