Skip to contentSkip to conversation

Implement cryptographic initialization control.

PATCH In review Dr. Greg 2 participants 2 messages Apr 7, 2020 – Apr 16, 2020

Subsystems (2)
lore
Share & tools
lore

Dr. Greg

author
#0 lore raw

PATCH 1/1 Implement cryptographic initialization control.

This patch introduces the ability of the platform owner to implement cryptographically controlled enclave initialization policy. This functionality provides the platform owner with the ability to use the identity modulus signature of an enclave signer (SHA256 hash of the modulus of the signing key) to gate access to enclave initialization, rather then simply relying on discretionary access controls that are applied to the SGX relevant device driver nodes.

The following policy functionality is introduced in this commit:

1.) Control over which keys are allowed to initialize an enclave.

2.) Control over which keys are allowed to implement launch enclaves.

3.) Control over which keys are allowed to initialize enclaves that have access to the PROVISION_KEY attribute.

For each policy type a plurality of key signatures are allowed.

Absent an intent by the platform owner/administrator to use cryptographic initialization policies, this functionality does not change the standard behavior of the driver, which is to allow any enclave presented to the driver to be initialized.

Cryptographic initialization policy is accessed through the following three pseudo-files that are implemented by this patch:

/sys/kernel/security/signing_keys

/sys/kernel/security/launch_keys

/sys/kernel/security/provisioning_keys

Policy keys are registered with the driver by writing the identity modulus signature to these files in simple hexadecimal format, ie:

0000000000000000000000000000000000000000000000000000000000000000

The current list of policy keys can be displayed by reading the contents of the pseudo-files.

In addition to a key signature, the following keywords are accepted as valid entries for a policy file:

clear

lock

The 'clear' keyword causes all existing entries in a policy list to be deleted.

The 'lock' keyword causes any further modifications or access to a policy list to be denied.

All of the policy code is implemented in a single file, policy.c, with minimal impact to the driver at large. Since the calculation of the identity modulus signature needed to program a launch control register is effectively a policy decision, the code to compute the signature was moved from the ioctl.c file to the policy.c file.

In order to support a plurality of launch keys the code that loops over initialization attempts was pushed downward into a new function that is named as follows:

sgx_try_init()

Primarily to avoid excessive indentation that would otherwise be needed in the sgx_encl_init() function.

---
 arch/x86/Kconfig                 |   1 +
 arch/x86/include/uapi/asm/sgx.h  |   1 +
 arch/x86/kernel/cpu/sgx/Makefile |   3 +-
 arch/x86/kernel/cpu/sgx/driver.c |   8 +
 arch/x86/kernel/cpu/sgx/driver.h |   2 +
 arch/x86/kernel/cpu/sgx/encl.h   |   2 +
 arch/x86/kernel/cpu/sgx/ioctl.c  |  82 ++---
 arch/x86/kernel/cpu/sgx/policy.c | 513 +++++++++++++++++++++++++++++++
 8 files changed, 573 insertions(+), 39 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/sgx/policy.c
arch/x86/Kconfig +1 -0
index 8bbb4313fae3..5cfde1d36dc9 100644
@@ -1955,6 +1955,7 @@ config INTEL_SGX
 	depends on X86_64 && CPU_SUP_INTEL
 	select SRCU
 	select MMU_NOTIFIER
+	select SECURITYFS
 	help
 	  Intel(R) SGX is a set of CPU instructions that can be used by
 	  applications to set aside private regions of code and data, referred
arch/x86/include/uapi/asm/sgx.h +1 -0
index e196cfd44b70..1c3cdbce533d 100644
@@ -63,6 +63,7 @@ struct sgx_enclave_add_pages {
  */
 struct sgx_enclave_init {
 	__u64 sigstruct;
+	__u64 token;
 };
 
 /**
arch/x86/kernel/cpu/sgx/Makefile +2 -1
index f8d32da3a67a..d8ee2a889ca1 100644
@@ -3,4 +3,5 @@ obj-y += \
 	encl.o \
 	ioctl.o \
 	main.o \
-	reclaim.o
+	reclaim.o \
+	policy.o
arch/x86/kernel/cpu/sgx/driver.c +8 -0
index 997a7f4117c5..d4330b32c243 100644
@@ -205,5 +205,13 @@ int __init sgx_drv_init(void)
 		return ret;
 	}
 
+	ret = sgx_policy_fs_init();
+	if (ret) {
+		pr_err("SGX policy fs creation failed with %d.\n", ret);
+		misc_deregister(&sgx_dev_provision);
+		misc_deregister(&sgx_dev_enclave);
+		return ret;
+	}
+
 	return 0;
 }
arch/x86/kernel/cpu/sgx/driver.h +2 -0
index 72747d01c046..8293f4d12e82 100644
@@ -29,4 +29,6 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
 
 int sgx_drv_init(void);
 
+int sgx_policy_fs_init(void);
+u64 *sgx_policy_get_launch_signer(u64 *signature);
 #endif /* __ARCH_X86_SGX_DRIVER_H__ */
arch/x86/kernel/cpu/sgx/encl.h +2 -0
index 44b353aa8866..b5be1f2233ea 100644
@@ -124,4 +124,6 @@ unsigned int sgx_alloc_va_slot(struct sgx_va_page *va_page);
 void sgx_free_va_slot(struct sgx_va_page *va_page, unsigned int offset);
 bool sgx_va_page_full(struct sgx_va_page *va_page);
 
+int sgx_policy_get_params(struct sgx_encl *encl, void *modulus, u64 *signer,
+			  int *signcnt);
 #endif /* _X86_ENCL_H */
arch/x86/kernel/cpu/sgx/ioctl.c +44 -38

117 lines not on this page · raw message

arch/x86/kernel/cpu/sgx/policy.c new file +513 -0

513 lines not on this page · raw message

Signature · 1 line
2.19.2
#1 lore raw
Quoted 67 lines · Dr. Greg

This patch introduces the ability of the platform owner to implement cryptographically controlled enclave initialization policy. This functionality provides the platform owner with the ability to use the identity modulus signature of an enclave signer (SHA256 hash of the modulus of the signing key) to gate access to enclave initialization, rather then simply relying on discretionary access controls that are applied to the SGX relevant device driver nodes.

The following policy functionality is introduced in this commit:

1.) Control over which keys are allowed to initialize an enclave.

2.) Control over which keys are allowed to implement launch enclaves.

3.) Control over which keys are allowed to initialize enclaves that have access to the PROVISION_KEY attribute.

For each policy type a plurality of key signatures are allowed.

Absent an intent by the platform owner/administrator to use cryptographic initialization policies, this functionality does not change the standard behavior of the driver, which is to allow any enclave presented to the driver to be initialized.

Cryptographic initialization policy is accessed through the following three pseudo-files that are implemented by this patch:

/sys/kernel/security/signing_keys

/sys/kernel/security/launch_keys

/sys/kernel/security/provisioning_keys

Policy keys are registered with the driver by writing the identity modulus signature to these files in simple hexadecimal format, ie:

0000000000000000000000000000000000000000000000000000000000000000

The current list of policy keys can be displayed by reading the contents of the pseudo-files.

In addition to a key signature, the following keywords are accepted as valid entries for a policy file:

clear

lock

The 'clear' keyword causes all existing entries in a policy list to be deleted.

The 'lock' keyword causes any further modifications or access to a policy list to be denied.

All of the policy code is implemented in a single file, policy.c, with minimal impact to the driver at large. Since the calculation of the identity modulus signature needed to program a launch control register is effectively a policy decision, the code to compute the signature was moved from the ioctl.c file to the policy.c file.

In order to support a plurality of launch keys the code that loops over initialization attempts was pushed downward into a new function that is named as follows:

Quoted 6 lines

sgx_try_init()

Primarily to avoid excessive indentation that would otherwise be needed in the sgx_encl_init() function.

Sorry, would have responded earlier but forgot to check the folder where fdm pulls mailing list email's. For shorter latency I recommend CC'ing.

This comes down to the fact that we are not doing anything that would prevent doing something similar post upstreaming (e.g. add a new ioctl for token version of EINIT or whatever) but is not something that we want to include right now. It is an additional feature (like other features e.g. virtualization)

/Jarkko