[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <176065159121.709179.14674872837536557005.tip-bot2@tip-bot2>
Date: Thu, 16 Oct 2025 21:53:11 -0000
From: "tip-bot2 for Elena Reshetova" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Elena Reshetova <elena.reshetova@...el.com>,
Dave Hansen <dave.hansen@...ux.intel.com>, Kai Huang <kai.huang@...el.com>,
Jarkko Sakkinen <jarkko@...nel.org>,
Nataliia Bondarevska <bondarn@...gle.com>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [tip: x86/sgx] x86/sgx: Enable automatic SVN updates for SGX enclaves
The following commit has been merged into the x86/sgx branch of tip:
Commit-ID: 0f2753efc5baff2f0b2a921fe77990c7b12955dc
Gitweb: https://git.kernel.org/tip/0f2753efc5baff2f0b2a921fe77990c7b12955dc
Author: Elena Reshetova <elena.reshetova@...el.com>
AuthorDate: Thu, 16 Oct 2025 16:11:08 +03:00
Committer: Dave Hansen <dave.hansen@...ux.intel.com>
CommitterDate: Thu, 16 Oct 2025 14:42:09 -07:00
x86/sgx: Enable automatic SVN updates for SGX enclaves
== 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
(aka. EPC) must be marked as “unused” in the SGX hardware metadata
(aka.EPCM). This requirement ensures that no compromised enclave can
survive the EUPDATESVN procedure and provides an opportunity to generate
new cryptographic assets.
== Solution ==
Attempt to execute ENCLS[EUPDATESVN] every time the first file descriptor
is obtained via sgx_(vepc_)open(). In the most common case the microcode
SVN is already up-to-date, and the operation succeeds without updating SVN.
Note: while in such cases the underlying crypto assets are regenerated, it
does not affect enclaves' visible keys obtained via EGETKEY instruction.
If it fails with any other error code than SGX_INSUFFICIENT_ENTROPY, this
is considered unexpected and the *open() returns an error. This should not
happen in practice.
On contrary, SGX_INSUFFICIENT_ENTROPY might happen due to a pressure on the
system's DRNG (RDSEED) and therefore the *open() can be safely retried to
allow normal enclave operation.
[1] Runtime Microcode Updates with Intel Software Guard Extensions,
https://cdrdv2.intel.com/v1/dl/getContent/648682
Signed-off-by: Elena Reshetova <elena.reshetova@...el.com>
Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
Reviewed-by: Kai Huang <kai.huang@...el.com>
Reviewed-by: Jarkko Sakkinen <jarkko@...nel.org>
Tested-by: Nataliia Bondarevska <bondarn@...gle.com>
---
arch/x86/kernel/cpu/sgx/main.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index ffc7b94..3eda7e7 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -934,7 +934,7 @@ static int sgx_usage_count;
* * entropy in RNG
* * %-EIO: - Unexpected error, retries are not advisable
*/
-static int __maybe_unused sgx_update_svn(void)
+static int sgx_update_svn(void)
{
int ret;
@@ -992,14 +992,30 @@ static int __maybe_unused sgx_update_svn(void)
return -EIO;
}
+/* Mutex to ensure no concurrent EPC accesses during EUPDATESVN */
+static DEFINE_MUTEX(sgx_svn_lock);
+
int sgx_inc_usage_count(void)
{
+ int ret;
+
+ guard(mutex)(&sgx_svn_lock);
+
+ if (!sgx_usage_count) {
+ ret = sgx_update_svn();
+ if (ret)
+ return ret;
+ }
+
+ sgx_usage_count++;
+
return 0;
}
void sgx_dec_usage_count(void)
{
- return;
+ guard(mutex)(&sgx_svn_lock);
+ sgx_usage_count--;
}
static int __init sgx_init(void)
Powered by blists - more mailing lists