Skip to content

Commit 0f2753e

Browse files
ereshetovahansendc
authored andcommitted
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@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Tested-by: Nataliia Bondarevska <bondarn@google.com>
1 parent 4e75697 commit 0f2753e

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

arch/x86/kernel/cpu/sgx/main.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ static int sgx_usage_count;
934934
* * entropy in RNG
935935
* * %-EIO: - Unexpected error, retries are not advisable
936936
*/
937-
static int __maybe_unused sgx_update_svn(void)
937+
static int sgx_update_svn(void)
938938
{
939939
int ret;
940940

@@ -992,14 +992,30 @@ static int __maybe_unused sgx_update_svn(void)
992992
return -EIO;
993993
}
994994

995+
/* Mutex to ensure no concurrent EPC accesses during EUPDATESVN */
996+
static DEFINE_MUTEX(sgx_svn_lock);
997+
995998
int sgx_inc_usage_count(void)
996999
{
1000+
int ret;
1001+
1002+
guard(mutex)(&sgx_svn_lock);
1003+
1004+
if (!sgx_usage_count) {
1005+
ret = sgx_update_svn();
1006+
if (ret)
1007+
return ret;
1008+
}
1009+
1010+
sgx_usage_count++;
1011+
9971012
return 0;
9981013
}
9991014

10001015
void sgx_dec_usage_count(void)
10011016
{
1002-
return;
1017+
guard(mutex)(&sgx_svn_lock);
1018+
sgx_usage_count--;
10031019
}
10041020

10051021
static int __init sgx_init(void)

0 commit comments

Comments
 (0)