Skip to contentSkip to conversation

Intel SGX Driver

PATCH Superseded Jarkko Sakkinen 12 participants 72 messages Nov 25, 2017 – Feb 8, 2018

Subsystems (5)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover Intel SGX Driver

Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. In a way you can think that SGX provides inverted sandbox. It protects the application from a malicious host.

There is a new hardware unit in the processor called Memory Encryption Engine (MEE) starting from the Skylake microacrhitecture. BIOS can define one or many MEE regions that can hold enclave data by configuring them with PRMRR registers.

The MEE automatically encrypts the data leaving the processor package to the MEE regions. The data is encrypted using a random key whose life-time is exactly one power cycle.

You can tell if your CPU supports SGX by looking into /proc/cpuinfo:

cat /proc/cpuinfo | grep sgx

The GIT repositoy for SGX driver resides in

https://github.com/jsakkine-intel/linux-sgx.git

'le' branch contains the upstream candidate patches.

'master' branch contains the same patches with the following differences:

* top-level patch modifies the ioctl API to be SDK compatible
* does not use flexible launch control but instead relies on SDK provided Intel launch enclave.

Backlog:
* AES: how to use arch/x86/crypto/aesni-intel_asm.S from the enclave. I guess these routines should be fairly easy to call directly (haven't investigated deeply). Any advice is appreciated.
* Layout: what and where to place in arch/x86.
* MAINTAINERS: who to add as reviewer.

v6
* Fixed semaphore underrun when accessing /dev/sgx from the launch enclave.
* In sgx_encl_create() s/IS_ERR(secs)/IS_ERR(encl)/.
* Removed virtualization chapter from the documentation.
* Changed the default filename for the signing key as signing_key.pem.
* Reworked EPC management in a way that instead of a linked list of struct sgx_epc_page instances there is an array of integers that encodes address and bank of an EPC page (the same data as 'pa' field earlier). The locking has been moved to the EPC bank level instead of a global lock.
* Relaxed locking requirements for EPC management. EPC pages can be released back to the EPC bank concurrently.
* Cleaned up ptrace() code.
* Refined commit messages for new architectural constants.
* Sorted includes in every source file.
* Sorted local variable declarations according to the line length in every function.
* Style fixes based on Darren's comments to sgx_le.c.

v5:
* Described IPC between the Launch Enclave and kernel in the commit messages.
* Fixed all relevant checkpatch.pl issues that I have forgot fix in earlier versions except those that exist in the imported TinyCrypt code.
* Fixed spelling mistakes in the documentation.
* Forgot to check the return value of sgx_drv_subsys_init().
* Encapsulated properly page cache init and teardown.
* Collect epc pages to a temp list in sgx_add_epc_bank
* Removed SGX_ENCLAVE_INIT_ARCH constant.

v4:
* Tied life-cycle of the sgx_le_proxy process to /dev/sgx.
* Removed __exit annotation from sgx_drv_subsys_exit().
* Fixed a leak of a backing page in sgx_process_add_page_req() in the case when vm_insert_pfn() fails.
* Removed unused symbol exports for sgx_page_cache.c.
* Updated sgx_alloc_page() to require encl parameter and documented the behavior (Sean Christopherson).
* Refactored a more lean API for sgx_encl_find() and documented the behavior.
* Moved #PF handler to sgx_fault.c.
* Replaced subsys_system_register() with plain bus_register().
* Retry EINIT 2nd time only if MSRs are not locked.

v3:
* Check that FEATURE_CONTROL_LOCKED and FEATURE_CONTROL_SGX_ENABLE are set.
* Return -ERESTARTSYS in __sgx_encl_add_page() when sgx_alloc_page() fails.
* Use unused bits in epc_page->pa to store the bank number.
* Removed #ifdef for WQ_NONREENTRANT.
* If mmu_notifier_register() fails with -EINTR, return -ERESTARTSYS.
* Added --remove-section=.got.plt to objcopy flags in order to prevent a dummy .got.plt, which will cause an inconsistent size for the LE.
* Documented sgx_encl_* functions.
* Added remark about AES implementation used inside the LE.
* Removed redundant sgx_sys_exit() from le/main.c.
* Fixed struct sgx_secinfo alignment from 128 to 64 bytes.
* Validate miscselect in sgx_encl_create().
* Fixed SSA frame size calculation to take the misc region into account.
* Implemented consistent exception handling to __encls() and __encls_ret().
* Implemented a proper device model in order to allow sysfs attributes and in-kernel API.
* Cleaned up various "find enclave" implementations to the unified sgx_encl_find().
* Validate that vm_pgoff is zero.
* Discard backing pages with shmem_truncate_range() after EADD.
* Added missing EEXTEND operations to LE signing and launch.
* Fixed SSA size for GPRS region from 168 to 184 bytes.
* Fixed the checks for TCS flags. Now DBGOPTIN is allowed.
* Check that TCS addresses are in ELRANGE and not just page aligned.
* Require kernel to be compiled with X64_64 and CPU_SUP_INTEL.
* Fixed an incorrect value for SGX_ATTR_DEBUG from 0x01 to 0x02.

v2:
* get_rand_uint32() changed the value of the pointer instead of value where it is pointing at.
* Launch enclave incorrectly used sigstruct attributes-field instead of enclave attributes-field.
* Removed unused struct sgx_add_page_req from sgx_ioctl.c
* Removed unused sgx_has_sgx2.
* Updated arch/x86/include/asm/sgx.h so that it provides stub implementations when sgx in not enabled.
* Removed cruft rdmsr-calls from sgx_set_pubkeyhash_msrs().
* return -ENOMEM in sgx_alloc_page() when VA pages consume too much space
* removed unused global sgx_nr_pids
* moved sgx_encl_release to sgx_encl.c
* return -ERESTARTSYS instead of -EINTR in sgx_encl_init()

Haim Cohen (1):
x86: add SGX MSRs to msr-index.h

Jarkko Sakkinen (8):
intel_sgx: updated MAINTAINERS
x86: define IA32_FEATUE_CONTROL.SGX_LC
intel_sgx: driver for Intel Software Guard Extensions
intel_sgx: ptrace() support
intel_sgx: in-kernel launch enclave fs/pipe.c: export create_pipe_files() and replace_fd()
intel_sgx: glue code for in-kernel LE
intel_sgx: driver documentation

Kai Huang (1):
x86: add SGX definition to cpufeature

Sean Christopherson (1):
x86: define IA32_FEATURE_CONTROL.SGX_ENABLE

 Documentation/index.rst                            |   1 +
 Documentation/x86/intel_sgx.rst                    | 101 +++
 MAINTAINERS                                        |   5 +
 arch/x86/include/asm/cpufeatures.h                 |   2 +
 arch/x86/include/asm/msr-index.h                   |   8 +
 arch/x86/include/asm/sgx.h                         | 233 +++++
 arch/x86/include/asm/sgx_arch.h                    | 268 ++++++
 arch/x86/include/uapi/asm/sgx.h                    | 138 +++
 drivers/platform/x86/Kconfig                       |   2 +
 drivers/platform/x86/Makefile                      |   1 +
 drivers/platform/x86/intel_sgx/Kconfig             |  34 +
 drivers/platform/x86/intel_sgx/Makefile            |  32 +
 drivers/platform/x86/intel_sgx/le/Makefile         |  26 +
 drivers/platform/x86/intel_sgx/le/enclave/Makefile |  46 +
 .../x86/intel_sgx/le/enclave/aes_encrypt.c         | 191 ++++
 .../platform/x86/intel_sgx/le/enclave/cmac_mode.c  | 254 ++++++
 .../x86/intel_sgx/le/enclave/encl_bootstrap.S      | 163 ++++
 .../intel_sgx/le/enclave/include/tinycrypt/aes.h   | 133 +++
 .../le/enclave/include/tinycrypt/cmac_mode.h       | 194 ++++
 .../le/enclave/include/tinycrypt/constants.h       |  59 ++
 .../intel_sgx/le/enclave/include/tinycrypt/utils.h |  95 ++
 drivers/platform/x86/intel_sgx/le/enclave/main.c   | 203 +++++
 .../platform/x86/intel_sgx/le/enclave/sgx_le.lds   |  28 +
 .../platform/x86/intel_sgx/le/enclave/sgxsign.c    | 538 +++++++++++
 drivers/platform/x86/intel_sgx/le/enclave/utils.c  |  78 ++
 drivers/platform/x86/intel_sgx/le/entry.S          | 117 +++
 .../platform/x86/intel_sgx/le/include/sgx_asm.h    |  64 ++
 .../platform/x86/intel_sgx/le/include/sgx_encl.h   | 110 +++
 drivers/platform/x86/intel_sgx/le/main.c           | 214 +++++
 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S   |  15 +
 drivers/platform/x86/intel_sgx/sgx.h               | 268 ++++++
 drivers/platform/x86/intel_sgx/sgx_encl.c          | 999 +++++++++++++++++++++
 drivers/platform/x86/intel_sgx/sgx_ioctl.c         | 282 ++++++
 drivers/platform/x86/intel_sgx/sgx_le.c            | 319 +++++++
 .../platform/x86/intel_sgx/sgx_le_proxy_piggy.S    |  15 +
 drivers/platform/x86/intel_sgx/sgx_main.c          | 456 ++++++++++
 drivers/platform/x86/intel_sgx/sgx_page_cache.c    | 619 +++++++++++++
 drivers/platform/x86/intel_sgx/sgx_util.c          | 394 ++++++++
 drivers/platform/x86/intel_sgx/sgx_vma.c           | 236 +++++
 fs/file.c                                          |   1 +
 fs/pipe.c                                          |   1 +
 41 files changed, 6943 insertions(+)
 create mode 100644 Documentation/x86/intel_sgx.rst
 create mode 100644 arch/x86/include/asm/sgx.h
 create mode 100644 arch/x86/include/asm/sgx_arch.h
 create mode 100644 arch/x86/include/uapi/asm/sgx.h
 create mode 100644 drivers/platform/x86/intel_sgx/Kconfig
 create mode 100644 drivers/platform/x86/intel_sgx/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/aes_encrypt.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/encl_bootstrap.S
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/aes.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/cmac_mode.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/constants.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/utils.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/sgx_le.lds
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/sgxsign.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/utils.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/entry.S
 create mode 100644 drivers/platform/x86/intel_sgx/le/include/sgx_asm.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/include/sgx_encl.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/main.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S
 create mode 100644 drivers/platform/x86/intel_sgx/sgx.h
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_encl.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_ioctl.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_le.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_le_proxy_piggy.S
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_main.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_page_cache.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_util.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_vma.c
Signature · 1 line
2.14.1
#1 lore raw

PATCH v6 1/11 intel_sgx: updated MAINTAINERS

---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 2d3d750b19c0..30a4b7f97a93 100644
@@ -14932,6 +14932,11 @@ L:	[email protected]
 S:	Maintained
 F:	mm/zswap.c
 
+INTEL SGX
+M:	Jarkko Sakkinen <[email protected]>
+L:	[email protected]
+Q:	https://patchwork.kernel.org/project/intel-sgx/list/
+
 THE REST
 M:	Linus Torvalds <[email protected]>
 L:	[email protected]
Signature · 1 line
2.14.1
#2 lore raw

Re: [PATCH v6 01/11] intel_sgx: updated MAINTAINERS

MAINTAINERS

Quoted 1 line · Jarkko Sakkinen
MAINTAINERS +0 -0

[]

MAINTAINERS L: [email protected] · line 14938

Quoted 8 lines
MAINTAINERS +4 -0
@@ -14932,6 +14932,11 @@ L:	[email protected]
 S:	Maintained
 F:	mm/zswap.c
 
+INTEL SGX
+M:	Jarkko Sakkinen <[email protected]>
+L:	[email protected]
+Q:	https://patchwork.kernel.org/project/intel-sgx/list/

Alphabetical order please and this should
have at least an "F:" pattern like:

F: drivers/platform/x86/intel_sgx/

and maybe a "K: pattern like:

K: \bSGX_

The lower case version matches too many other subsystems

$ git grep -i -P --name-only "\b_?sgx_"
arch/arm/boot/dts/omap36xx-am35xx-omap3430es2plus-clocks.dtsi
arch/arm/boot/dts/omap44xx-clocks.dtsi
arch/arm/mach-omap2/clockdomains3xxx_data.c
arch/arm/mach-omap2/clockdomains81xx_data.c
arch/arm/mach-omap2/cm3xxx.c
arch/arm/mach-omap2/omap_hwmod_44xx_data.c
arch/arm/mach-omap2/powerdomains3xxx_data.c
drivers/clk/ti/clk-3xxx-legacy.c
drivers/clk/ti/clk-3xxx.c
drivers/clk/ti/clk-44xx.c
drivers/gpu/drm/gma500/cdv_device.c
drivers/gpu/drm/gma500/mdfld_device.c
drivers/gpu/drm/gma500/oaktrail_device.c
drivers/gpu/drm/gma500/psb_device.c
drivers/gpu/drm/gma500/psb_drv.c
drivers/gpu/drm/gma500/psb_drv.h
drivers/gpu/drm/gma500/psb_irq.c
Quoted 4 lines
MAINTAINERS +1 -0
+
 THE REST
 M:	Linus Torvalds <[email protected]>
 L:	[email protected]
#3 lore raw

Re: [PATCH v6 01/11] intel_sgx: updated MAINTAINERS

Quoted 15 lines · Joe Perches

MAINTAINERS

Quoted 1 line · Jarkko Sakkinen
MAINTAINERS +0 -0

[]

MAINTAINERS L: [email protected] · line 14938

Quoted 8 lines
MAINTAINERS +4 -0
@@ -14932,6 +14932,11 @@ L:	[email protected]
 S:	Maintained
 F:	mm/zswap.c
 
+INTEL SGX
+M:	Jarkko Sakkinen <[email protected]>
+L:	[email protected]
+Q:	https://patchwork.kernel.org/project/intel-sgx/list/

Alphabetical order please and this should
have at least an "F:" pattern like:

Quoted 1 line

F: drivers/platform/x86/intel_sgx/

FYI: Darren already requested that when reviewing v5:
https://www.spinics.net/lists/kernel/msg2651743.html

Bjørn

#4 lore raw

Re: [PATCH v6 01/11] intel_sgx: updated MAINTAINERS

Quoted 16 lines · Bjørn Mork
Quoted 15 lines · Joe Perches

MAINTAINERS

Quoted 1 line · Jarkko Sakkinen
MAINTAINERS +0 -0

[]

MAINTAINERS L: [email protected] · line 14938

Quoted 8 lines
MAINTAINERS +4 -0
@@ -14932,6 +14932,11 @@ L:	[email protected]
 S:	Maintained
 F:	mm/zswap.c
 
+INTEL SGX
+M:	Jarkko Sakkinen <[email protected]>
+L:	[email protected]
+Q:	https://patchwork.kernel.org/project/intel-sgx/list/

Alphabetical order please and this should
have at least an "F:" pattern like:

Quoted 4 lines
Quoted 1 line

F: drivers/platform/x86/intel_sgx/

FYI: Darren already requested that when reviewing v5:
https://www.spinics.net/lists/kernel/msg2651743.html

Joe, Bjørn, thank you for your feedback. I kind of left the MAINTAINERS update open because I wanted to get feedback who to add as reviewers and forgot to add "F:". I'll definitely fix this for v7. I'm sorry for ingoring it for v6.

You might have noticed that v6 was not CC'd to mailing list defined in "M:". The reason for this is that I've lost the admin password for the ML so I could not reconfigure it (see tglx's complains for v5). I'll get this fixed early next week.

/Jarkko

#5 lore raw

PATCH v6 2/11 x86: add SGX definition to cpufeature

In reply to Jarkko Sakkinen

From: Kai Huang <[email protected]>

Added X86_FEATURE_SGX, which identifies that CPU supports software guard extensions (SGX).

---
 arch/x86/include/asm/cpufeatures.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +1 -0
index 2519c6c801c9..31a7d1c0f204 100644
@@ -219,6 +219,7 @@
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
 #define X86_FEATURE_FSGSBASE	( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
 #define X86_FEATURE_TSC_ADJUST	( 9*32+ 1) /* TSC adjustment MSR 0x3b */
+#define X86_FEATURE_SGX		( 9*32+ 2) /* Software Guard Extensions */
 #define X86_FEATURE_BMI1	( 9*32+ 3) /* 1st group bit manipulation extensions */
 #define X86_FEATURE_HLE		( 9*32+ 4) /* Hardware Lock Elision */
 #define X86_FEATURE_AVX2	( 9*32+ 5) /* AVX2 instructions */
Signature · 1 line
2.14.1
#6 lore raw

PATCH v6 3/11 x86: define IA32_FEATURE_CONTROL.SGX_ENABLE

In reply to Jarkko Sakkinen

From: Sean Christopherson <[email protected]>

When IA32_FEATURE_CONTROL.SGX_ENABLE and IA32_FEATURE_CONTROL.LOCK are set by the pre-boot firmware, SGX is usable by the OS.

---
 arch/x86/include/asm/msr-index.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/msr-index.h +1 -0
index 17f5c12e1afd..b35cb98b5d60 100644
@@ -435,6 +435,7 @@
 #define FEATURE_CONTROL_LOCKED				(1<<0)
 #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX	(1<<1)
 #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX	(1<<2)
+#define FEATURE_CONTROL_SGX_ENABLE                      (1<<18)
 #define FEATURE_CONTROL_LMCE				(1<<20)
 
 #define MSR_IA32_APICBASE		0x0000001b
Signature · 1 line
2.14.1
#7 lore raw

Re: [PATCH v6 03/11] x86: define IA32_FEATURE_CONTROL.SGX_ENABLE

Quoted 4 lines · Jarkko Sakkinen

From: Sean Christopherson <[email protected]>

When IA32_FEATURE_CONTROL.SGX_ENABLE and IA32_FEATURE_CONTROL.LOCK are set by the pre-boot firmware, SGX is usable by the OS.

This implies that only pre-boot firmware can write feature control, which is not true.  What about:

    SGX instructions (ENCLS and ENCLU) are usable if and only if SGX_ENABLE is set in the IA32_FEATURE_CONTROL MSR and said MSR is locked.

Quoted 19 lines

---
 arch/x86/include/asm/msr-index.h | 1 +

 1 file changed, 1 insertion(+)
arch/x86/include/asm/msr- renamed from arch/x86/include/asm/msr-index.h +0 -0

index.h
index 17f5c12e1afd..b35cb98b5d60 100644

arch/x86/include/asm/msr-index.h +1 -0
@@ -435,6 +435,7 @@
  #define FEATURE_CONTROL_LOCKED				(1<<0)
  #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX	(1<<1)
  #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX	(1<<2)
+#define FEATURE_CONTROL_SGX_ENABLE                      (1<<18)
  #define FEATURE_CONTROL_LMCE				(1<<20)


 #define MSR_IA32_APICBASE 0x0000001b

#8 lore raw

Re: [PATCH v6 03/11] x86: define IA32_FEATURE_CONTROL.SGX_ENABLE

Quoted 11 lines · Sean Christopherson
Quoted 4 lines · Jarkko Sakkinen

From: Sean Christopherson <[email protected]>

When IA32_FEATURE_CONTROL.SGX_ENABLE and IA32_FEATURE_CONTROL.LOCK are set by the pre-boot firmware, SGX is usable by the OS.

This implies that only pre-boot firmware can write feature control, which is not true.  What about:

    SGX instructions (ENCLS and ENCLU) are usable if and only if SGX_ENABLE is set in the IA32_FEATURE_CONTROL MSR and said MSR is locked.

You are correct, thanks. I'll fix this for v7.

/Jarkko

#9 lore raw

PATCH v6 4/11 x86: define IA32_FEATUE_CONTROL.SGX_LC

In reply to Jarkko Sakkinen

When IA32_FEATURE_CONTROL.SGX_LC identifies that the root key for enclave signatures can be configured either by the OS or pre-boot firmware.

If this the case, IA32_SGXLEPUBKEYHASHn MSRs (0 < n < 4) can be used to set the SHA256 of the root key. IA32_FEATURE_CONTROL bit 17 controls whether the MSRs are writable by the OS. The pre-boot firmware can decided whether to set this bit before setting IA32_FEATURE_CONTROL.LOCK.

---
 arch/x86/include/asm/cpufeatures.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +1 -0
index 31a7d1c0f204..43130f3c18a1 100644
@@ -298,6 +298,7 @@
 #define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */
 #define X86_FEATURE_LA57	(16*32+16) /* 5-level page tables */
 #define X86_FEATURE_RDPID	(16*32+22) /* RDPID instruction */
+#define X86_FEATURE_SGX_LC	(16*32+30) /* supports SGX launch configuration */
 
 /* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */
 #define X86_FEATURE_OVERFLOW_RECOV (17*32+0) /* MCA overflow recovery support */
Signature · 1 line
2.14.1
#10 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 10 lines · Jarkko Sakkinen

When IA32_FEATURE_CONTROL.SGX_LC identifies that the root key for enclave signatures can be configured either by the OS or pre-boot firmware.

If this the case, IA32_SGXLEPUBKEYHASHn MSRs (0 < n < 4) can be used to
set the SHA256 of the root key. IA32_FEATURE_CONTROL bit 17 controls whether the MSRs are writable by the OS. The pre-boot firmware can decided whether to  set this bit before setting IA32_FEATURE_CONTROL.LOCK.

The commit message (feature control bit) doesn't match the patch (CPUID bit).

Quoted 22 lines

---
 arch/x86/include/asm/cpufeatures.h | 1 +

 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +0 -0
index 31a7d1c0f204..43130f3c18a1 100644
@@ -298,6 +298,7 @@
  #define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors

of DW/QW */
 #define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */
 #define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */
+#define X86_FEATURE_SGX_LC (16*32+30) /* supports SGX launch
configuration */

 /* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */ #define X86_FEATURE_OVERFLOW_RECOV (17*32+0) /* MCA overflow recovery support */

#11 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 6 lines · Sean Christopherson
Quoted 5 lines · Jarkko Sakkinen

When IA32_FEATURE_CONTROL.SGX_LC identifies that the root key for enclave signatures can be configured either by the OS or pre-boot firmware.

Quoted 8 lines
Quoted 6 lines

If this the case, IA32_SGXLEPUBKEYHASHn MSRs (0 < n < 4) can be used to
set the SHA256 of the root key. IA32_FEATURE_CONTROL bit 17 controls whether the MSRs are writable by the OS. The pre-boot firmware can decided whether to  set this bit before setting IA32_FEATURE_CONTROL.LOCK.

The commit message (feature control bit) doesn't match the patch (CPUID bit).

Also, assuming this message is destined for the commit that adds SGX_LC to feature control, I think it should first and foremost describe the hardware behavior.  The firmware vs OS interaction and use cases are valuable to document but IMO should come after the hardware description.

And though it's not documented in the SDM, I think it's worthwhile to describe the SGX activation sequence and its relationship with the SGX MSRs, e.g. the LE hash MSRs are writable prior to SGX activation. Without that information, it's unclear as to how the LE hash MSRs could be different than Intel's reset value.

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Quoted 23 lines
Quoted 23 lines

---
 arch/x86/include/asm/cpufeatures.h | 1 +

 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +0 -0
index 31a7d1c0f204..43130f3c18a1 100644
@@ -298,6 +298,7 @@
  #define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors

of DW/QW */
 #define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */
 #define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */
+#define X86_FEATURE_SGX_LC (16*32+30) /* supports SGX launch
configuration */

 /* AMD-defined CPU features, CPUID level 0x80000007 (ebx), word 17 */ #define X86_FEATURE_OVERFLOW_RECOV (17*32+0) /* MCA overflow recovery support */

#12 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 41 lines · Sean Christopherson
Quoted 6 lines · Sean Christopherson
Quoted 5 lines · Jarkko Sakkinen

When IA32_FEATURE_CONTROL.SGX_LC identifies that the root key for enclave signatures can be configured either by the OS or pre-boot firmware.

Quoted 8 lines
Quoted 6 lines

If this the case, IA32_SGXLEPUBKEYHASHn MSRs (0 < n < 4) can be used to
set the SHA256 of the root key. IA32_FEATURE_CONTROL bit 17 controls whether the MSRs are writable by the OS. The pre-boot firmware can decided whether to  set this bit before setting IA32_FEATURE_CONTROL.LOCK.

The commit message (feature control bit) doesn't match the patch (CPUID bit).

Also, assuming this message is destined for the commit that adds SGX_LC to feature control, I think it should first and foremost describe the hardware behavior.  The firmware vs OS interaction and use cases are valuable to document but IMO should come after the hardware description.

And though it's not documented in the SDM, I think it's worthwhile to describe the SGX activation sequence and its relationship with the SGX MSRs, e.g. the LE hash MSRs are writable prior to SGX activation. Without that information, it's unclear as to how the LE hash MSRs could be different than Intel's reset value.

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

/Jarkko

#13 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 14 lines · Jarkko Sakkinen
Quoted 14 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 8 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

/Jarkko

#14 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 24 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 16 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 7 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Quoted 7 lines

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

/Jarkko

My comments were referring to improving the commit message for defining IA32_FEATURE_CONTROL.SGX_LC, i.e. bit 17, not the CPUID bit.

#15 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 27 lines · Sean Christopherson
Quoted 26 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 16 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 7 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Not sure after all if I'm following this.

Quoted 8 lines
Quoted 5 lines

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

/Jarkko

My comments were referring to improving the commit message for defining IA32_FEATURE_CONTROL.SGX_LC, i.e. bit 17, not the CPUID bit.

My bad but SGX_LC is referring here to the CPUID bit.

In SGX chapters there is no specific name for IA32_FEATURE_CONTROL[17]. I would call it something else than SGX_LC. Maybe SGX_LC_WRITABLE.

/Jarkko

#16 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 37 lines · Jarkko Sakkinen
Quoted 36 lines · Sean Christopherson
Quoted 34 lines · Jarkko Sakkinen
Quoted 18 lines · Jarkko Sakkinen
Quoted 18 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 7 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

/Jarkko

Quoted 8 lines
Quoted 2 lines

My comments were referring to improving the commit message for defining IA32_FEATURE_CONTROL.SGX_LC, i.e. bit 17, not the CPUID bit.

My bad but SGX_LC is referring here to the CPUID bit.

In SGX chapters there is no specific name for IA32_FEATURE_CONTROL[17]. I would call it something else than SGX_LC. Maybe SGX_LC_WRITABLE.

/Jarkko

What about SGX_LC_ENABLE?  The title in the MSR section of the SDM is "SGX Launch Control Enable", and it's more consistent with the other bits defined in feature control.  I'd also prefer that name for the actual #define too, SGX_LAUNCH_CONTROL_ENABLE is overly verbose IMO.

#17 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 4 lines · Sean Christopherson

What about SGX_LC_ENABLE?  The title in the MSR section of the SDM is "SGX Launch Control Enable", and it's more consistent with the other bits defined in feature control.  I'd also prefer that name for the actual #define too, SGX_LAUNCH_CONTROL_ENABLE is overly verbose IMO.

This is a bit ugly name but it is also very clear:

FEATURE_CONTROL_SGX_LEPUBKEYHASH_WRITE_ENABLE

Just pushed update to the le branch. SGX_LC_ENABLE is a nice short name but it does not reflect the semantics.

Maybe we could combine these and name it as

FEATURE_CONTROL_SGX_LC_WRITE_ENABLE

It is not as ugly and is very clear what it does.

/Jarkko

#18 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 10 lines · Jarkko Sakkinen
Quoted 4 lines · Sean Christopherson

What about SGX_LC_ENABLE?  The title in the MSR section of the SDM is "SGX Launch Control Enable", and it's more consistent with the other bits defined in feature control.  I'd also prefer that name for the actual #define too, SGX_LAUNCH_CONTROL_ENABLE is overly verbose IMO.

This is a bit ugly name but it is also very clear:

FEATURE_CONTROL_SGX_LEPUBKEYHASH_WRITE_ENABLE

Quoted 8 lines

Just pushed update to the le branch. SGX_LC_ENABLE is a nice short name but it does not reflect the semantics.

Maybe we could combine these and name it as

FEATURE_CONTROL_SGX_LC_WRITE_ENABLE

It is not as ugly and is very clear what it does.

I ended up with FEATURE_CONTROL_SGX_LC_WR. I think that is fairly reasonable name for bit 17.

/Jarkko

#19 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 20 lines · Jarkko Sakkinen
Quoted 19 lines · Jarkko Sakkinen
Quoted 8 lines · Sean Christopherson

What about SGX_LC_ENABLE? The title in the MSR section of the SDM is
"SGX Launch Control Enable", and it's more consistent with the other
bits defined in feature control. I'd also prefer that name for the
actual #define too, SGX_LAUNCH_CONTROL_ENABLE is overly verbose IMO.

This is a bit ugly name but it is also very clear:

FEATURE_CONTROL_SGX_LEPUBKEYHASH_WRITE_ENABLE

Just pushed update to the le branch. SGX_LC_ENABLE is a nice short name
but it does not reflect the semantics.

Quoted 8 lines
Quoted 5 lines

Maybe we could combine these and name it as

FEATURE_CONTROL_SGX_LC_WRITE_ENABLE

It is not as ugly and is very clear what it does.

I ended up with FEATURE_CONTROL_SGX_LC_WR. I think that is fairly reasonable name for bit 17.

Why not using FEATURE_CONTROL_SGX_LE_WR? "LE_WR" is even used in SDM 41.2.2 Intel SGX Launch Control Configuration:

If IA32_FEATURE_CONTROL.LE_WR (bit 17) is set to 1 and IA32_FEATURE_CONTROL is locked on that logical processor, IA32_SGXLEPUBKEYHASH MSRs on that logical processor then the IA32_SGXLEPUBKEYHASHn MSR are writeable.

Thanks,
-Kai

Quoted 2 lines

/Jarkko

#20 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 30 lines · Kai Huang
Quoted 20 lines · Jarkko Sakkinen
Quoted 19 lines · Jarkko Sakkinen
Quoted 8 lines · Sean Christopherson

What about SGX_LC_ENABLE? The title in the MSR section of the SDM is
"SGX Launch Control Enable", and it's more consistent with the other
bits defined in feature control. I'd also prefer that name for the
actual #define too, SGX_LAUNCH_CONTROL_ENABLE is overly verbose IMO.

This is a bit ugly name but it is also very clear:

FEATURE_CONTROL_SGX_LEPUBKEYHASH_WRITE_ENABLE

Just pushed update to the le branch. SGX_LC_ENABLE is a nice short name
but it does not reflect the semantics.

Quoted 8 lines
Quoted 5 lines

Maybe we could combine these and name it as

FEATURE_CONTROL_SGX_LC_WRITE_ENABLE

It is not as ugly and is very clear what it does.

I ended up with FEATURE_CONTROL_SGX_LC_WR. I think that is fairly reasonable name for bit 17.

Quoted 7 lines

Why not using FEATURE_CONTROL_SGX_LE_WR? "LE_WR" is even used in SDM 41.2.2 Intel SGX Launch Control Configuration:

If IA32_FEATURE_CONTROL.LE_WR (bit 17) is set to 1 and IA32_FEATURE_CONTROL is locked on that logical processor, IA32_SGXLEPUBKEYHASH MSRs on that logical processor then the IA32_SGXLEPUBKEYHASHn MSR are writeable.

I'm fine with that name and since the spec uses it I think with lock to that :-) Thanks for noting this!

/Jarkko

#21 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

In reply to Jarkko Sakkinen
Quoted 24 lines · Jarkko Sakkinen
Quoted 14 lines · Jarkko Sakkinen
Quoted 14 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 8 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Quoted 7 lines

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

/Jarkko

I used this commit message with some minor editing in the commit that defines the MSRs and squashed commits that define cpuid level 7 bits. Can you peer check the commit messages? They are in the le branch.

/Jarkko

#22 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 32 lines · Jarkko Sakkinen
Quoted 31 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 16 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 7 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

Quoted 6 lines
Quoted 1 line

/Jarkko

I used this commit message with some minor editing in the commit that defines the MSRs and squashed commits that define cpuid level 7 bits. Can you peer check the commit messages? They are in the le branch.

/Jarkko

The commit defines FEATURE_CONTROL_SGX_LAUNCH_CONTROL_ENABLE in addition to the LE hash MSRs, which is why my suggestion referred to "SGX_LC" and not simply bit 17.  I used "SGX_LC" instead of the full name because that's what your original commit messaged used (though it was attached to the CPUID patch, thus all the confusion).

Anyways, I think the commit should have a blurb about defining bit 17, and then refer to SGX_LAUNCH_CONTROL_ENABLE (or some variation) rather than bit 17 when talking about its effects on SGX.

#23 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 46 lines · Sean Christopherson
Quoted 32 lines · Jarkko Sakkinen
Quoted 31 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 16 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 7 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

Quoted 6 lines
Quoted 1 line

/Jarkko

I used this commit message with some minor editing in the commit that defines the MSRs and squashed commits that define cpuid level 7 bits. Can you peer check the commit messages? They are in the le branch.

/Jarkko

The commit defines FEATURE_CONTROL_SGX_LAUNCH_CONTROL_ENABLE in addition to the LE hash MSRs, which is why my suggestion referred to "SGX_LC" and not simply bit 17.  I used "SGX_LC" instead of the full name because that's what your original commit messaged used (though it was attached to the CPUID patch, thus all the confusion).

Quoted 3 lines

Anyways, I think the commit should have a blurb about defining bit 17, and then refer to SGX_LAUNCH_CONTROL_ENABLE (or some variation) rather than bit 17 when talking about its effects on SGX.

Not sure I'm following because this commit only defines the CPUID feature bits. I think it woul be a bad idea to refer to bit 17 with SGX_LC because CPUID chapter in the instruction reference uses the same acronym.

/Jarkko

#24 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

Quoted 51 lines · Jarkko Sakkinen
Quoted 46 lines · Sean Christopherson
Quoted 32 lines · Jarkko Sakkinen
Quoted 31 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 16 lines

So, maybe something like this?

    After SGX is activated[1] the IA32_SGXLEPUBKEYHASHn MSRs are writable if and only if SGX_LC is set in the IA32_FEATURE_CONTROL MSR and the IA32_FEATURE_CONTROL MSR is locked, otherwise they are read-only.

    For example, firmware can allow the OS to change the launch enclave root key by setting IA32_FEATURE_CONTROL.SGX_LC, and thus give the OS complete control over the enclaves it runs.  Alternatively, firmware can clear IA32_FEATURE_CONTROL.SGX_LC to lock down the root key and restrict the OS to running enclaves signed with the root key or whitelisted/trusted by a launch enclave (which must be signed with the root key).

Quoted 7 lines
Quoted 5 lines

    [1] SGX related bits in IA32_FEATURE_CONTROL cannot be set until SGX is activated, e.g. by firmware.  SGX activation is triggered by setting bit 0 in MSR 0x7a.  Until SGX is activated, the LE hash MSRs are writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value.

Thanks I'll use this as a basis and move most of the crappy commit message to the commit (with some editing) that defines the MSRs.

Not sure after all if I'm following this.

IA32_FEATURE_CONTROL[17] contols whether the MSRs are writable or not after the feature control MSR is locked. SGX_LC means just that the CPU supports the launch configuration.

Quoted 6 lines
Quoted 1 line

/Jarkko

I used this commit message with some minor editing in the commit that defines the MSRs and squashed commits that define cpuid level 7 bits. Can you peer check the commit messages? They are in the le branch.

/Jarkko

The commit defines FEATURE_CONTROL_SGX_LAUNCH_CONTROL_ENABLE in addition to the LE hash MSRs, which is why my suggestion referred to "SGX_LC" and not simply bit 17.  I used "SGX_LC" instead of the full name because that's what your original commit messaged used (though it was attached to the CPUID patch, thus all the confusion).

Quoted 3 lines

Anyways, I think the commit should have a blurb about defining bit 17, and then refer to SGX_LAUNCH_CONTROL_ENABLE (or some variation) rather than bit 17 when talking about its effects on SGX.

Quoted 6 lines

Not sure I'm following because this commit only defines the CPUID feature bits. I think it woul be a bad idea to refer to bit 17 with SGX_LC because CPUID chapter in the instruction reference uses the same acronym.

/Jarkko

I guess you are point this to the commit that adds LE keyhash MSRS and adds FEATURE_CONTROL_SGX_LAUNCH_CONTROL_ENABLE :-)

I will squash that commit to the one that defines FEATURE_CONTROL_SGX_ENABLE and rename the constant as FEATURE_CONTROL_SGX_LAUNCH_CONTROL_WRITABLE.

Then it is obvious what it does and also commits and commit messages are better self-contained and make sense. One commit for CPUID updates and for MSR updates.

How does this sound?

/Jarkko

#25 lore raw

Re: [PATCH v6 04/11] x86: define IA32_FEATUE_CONTROL.SGX_LC

In reply to Sean Christopherson
Quoted 12 lines · Sean Christopherson
Quoted 10 lines · Jarkko Sakkinen

When IA32_FEATURE_CONTROL.SGX_LC identifies that the root key for enclave signatures can be configured either by the OS or pre-boot firmware.

If this the case, IA32_SGXLEPUBKEYHASHn MSRs (0 < n < 4) can be used to
set the SHA256 of the root key. IA32_FEATURE_CONTROL bit 17 controls whether the MSRs are writable by the OS. The pre-boot firmware can decided whether to  set this bit before setting IA32_FEATURE_CONTROL.LOCK.

Quoted 2 lines

The commit message (feature control bit) doesn't match the patch (CPUID bit).

Oops. I'll move most of this the patch that defines the MSRs. I think the latter part was meant for that I had been awake for too long time :-) I'll fix these commit messages with extra care for v7. Thank you.

/Jarkko

#26 lore raw

PATCH v6 5/11 x86: add SGX MSRs to msr-index.h

In reply to Jarkko Sakkinen

From: Haim Cohen <[email protected]>

These MSRs hold the SHA256 checksum of the currently configured root key for enclave signatures.

---
 arch/x86/include/asm/msr-index.h | 7 +++++++
 1 file changed, 7 insertions(+)
arch/x86/include/asm/msr-index.h +7 -0
index b35cb98b5d60..22e27d46d046 100644
@@ -436,6 +436,7 @@
 #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX	(1<<1)
 #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX	(1<<2)
 #define FEATURE_CONTROL_SGX_ENABLE                      (1<<18)
+#define FEATURE_CONTROL_SGX_LAUNCH_CONTROL_ENABLE	(1<<17)
 #define FEATURE_CONTROL_LMCE				(1<<20)
 
 #define MSR_IA32_APICBASE		0x0000001b
@@ -502,6 +503,12 @@
 #define PACKAGE_THERM_INT_LOW_ENABLE		(1 << 1)
 #define PACKAGE_THERM_INT_PLN_ENABLE		(1 << 24)
 
+/* Intel SGX MSRs */
+#define MSR_IA32_SGXLEPUBKEYHASH0	0x0000008C
+#define MSR_IA32_SGXLEPUBKEYHASH1	0x0000008D
+#define MSR_IA32_SGXLEPUBKEYHASH2	0x0000008E
+#define MSR_IA32_SGXLEPUBKEYHASH3	0x0000008F
+
 /* Thermal Thresholds Support */
 #define THERM_INT_THRESHOLD0_ENABLE    (1 << 15)
 #define THERM_SHIFT_THRESHOLD0        8
Signature · 1 line
2.14.1
#27 lore raw

Re: [PATCH v6 05/11] x86: add SGX MSRs to msr-index.h

Quoted 4 lines · Jarkko Sakkinen

From: Haim Cohen <[email protected]>

These MSRs hold the SHA256 checksum of the currently configured root key for enclave signatures.

The commit message doesn't talk about the launch control bit in the feature control MSR.

Quoted 33 lines

---
 arch/x86/include/asm/msr-index.h | 7 +++++++

 1 file changed, 7 insertions(+)
arch/x86/include/asm/msr-index.h +1 -0
index b35cb98b5d60..22e27d46d046 100644
@@ -436,6 +436,7 @@
  #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX	(1<<1)
  #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX	(1<<2)
  #define FEATURE_CONTROL_SGX_ENABLE                      (1<<18)
+#define FEATURE_CONTROL_SGX_LAUNCH_CONTROL_ENABLE	(1<<17)
  #define FEATURE_CONTROL_LMCE				(1<<20)


 #define MSR_IA32_APICBASE 0x0000001b

arch/x86/include/asm/msr-index.h +0 -0
@@ -502,6 +503,12 @@
  #define PACKAGE_THERM_INT_LOW_ENABLE		(1 << 1)
  #define PACKAGE_THERM_INT_PLN_ENABLE		(1 << 24)

arch/x86/include/asm/msr-index.h +6 -0
+/* Intel SGX MSRs */
+#define MSR_IA32_SGXLEPUBKEYHASH0	0x0000008C
+#define MSR_IA32_SGXLEPUBKEYHASH1	0x0000008D
+#define MSR_IA32_SGXLEPUBKEYHASH2	0x0000008E
+#define MSR_IA32_SGXLEPUBKEYHASH3	0x0000008F
+

 /* Thermal Thresholds Support */
 #define THERM_INT_THRESHOLD0_ENABLE    (1 << 15)
 #define THERM_SHIFT_THRESHOLD0        8

#28 lore raw

Re: [PATCH v6 05/11] x86: add SGX MSRs to msr-index.h

Quoted 8 lines · Sean Christopherson
Quoted 4 lines · Jarkko Sakkinen

From: Haim Cohen <[email protected]>

These MSRs hold the SHA256 checksum of the currently configured root key for enclave signatures.

The commit message doesn't talk about the launch control bit in the feature control MSR.

Correct, would make sense to refine this further.

/Jarkko

#29 lore raw

PATCH v6 6/11 intel_sgx: driver for Intel Software Guard Extensions

In reply to Jarkko Sakkinen

Intel SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control.

SGX driver provides a ioctl API for loading and initializing enclaves. Address range for enclaves is reserved with mmap() and they are destroyed with munmap(). Enclave construction, measurement and initialization is done with the provided the ioctl API.

The driver implements also a swapper thread ksgxswapd for EPC pages backed by a private shmem file. Currently it has a limitation of not swapping VA pages but there is nothing preventing to implement it later on. Now it was scoped out in order to keep the implementation simple.

The parameter struct for SGX_IOC_ENCLAVE_INIT does not contain a parameter to supply a launch token. Generating and using tokens is best to be kept in the control of the kernel because it has direct binding to the IA32_SGXPUBKEYHASHx MSRs (a core must have MSRs set to the same value as the signer of token).

By giving user space any role in the launch process is a risk for introducing bottlenecks as kernel must exhibit behavior that user space launch daemon depends on, properietary risks (closed launch daemons on closed platforms) and stability risks as there would be division of semantics between user space and kernel.

---
 arch/x86/include/asm/sgx.h                      | 233 ++++++
 arch/x86/include/asm/sgx_arch.h                 | 268 +++++++
 arch/x86/include/uapi/asm/sgx.h                 | 138 ++++
 drivers/platform/x86/Kconfig                    |   2 +
 drivers/platform/x86/Makefile                   |   1 +
 drivers/platform/x86/intel_sgx/Kconfig          |  19 +
 drivers/platform/x86/intel_sgx/Makefile         |  13 +
 drivers/platform/x86/intel_sgx/sgx.h            | 244 ++++++
 drivers/platform/x86/intel_sgx/sgx_encl.c       | 981 ++++++++++++++++++++++++
 drivers/platform/x86/intel_sgx/sgx_ioctl.c      | 280 +++++++
 drivers/platform/x86/intel_sgx/sgx_main.c       | 413 ++++++++++
 drivers/platform/x86/intel_sgx/sgx_page_cache.c | 619 +++++++++++++++
 drivers/platform/x86/intel_sgx/sgx_util.c       | 369 +++++++++
 drivers/platform/x86/intel_sgx/sgx_vma.c        | 117 +++
 14 files changed, 3697 insertions(+)
 create mode 100644 arch/x86/include/asm/sgx.h
 create mode 100644 arch/x86/include/asm/sgx_arch.h
 create mode 100644 arch/x86/include/uapi/asm/sgx.h
 create mode 100644 drivers/platform/x86/intel_sgx/Kconfig
 create mode 100644 drivers/platform/x86/intel_sgx/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/sgx.h
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_encl.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_ioctl.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_main.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_page_cache.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_util.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_vma.c
arch/x86/include/asm/sgx.h new file +233 -0
new file mode 100644
index 000000000000..6539ae4f398e
@@ -0,0 +1,233 @@
+/*
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2016-2017 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * Contact Information:
+ * Jarkko Sakkinen <[email protected]>
+ * Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2016-2017 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *   * Neither the name of Intel Corporation nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors:
+ *
+ * Jarkko Sakkinen <[email protected]>
+ * Suresh Siddha <[email protected]>
+ */
+
+#ifndef _ASM_X86_SGX_H
+#define _ASM_X86_SGX_H
+
+#include <asm/sgx_arch.h>
+#include <asm/asm.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/types.h>
+
+#define SGX_CPUID 0x12
+
+enum sgx_cpuid {
+	SGX_CPUID_CAPABILITIES	= 0,
+	SGX_CPUID_ATTRIBUTES	= 1,
+	SGX_CPUID_EPC_BANKS	= 2,
+};
+
+enum sgx_commands {
+	ECREATE	= 0x0,
+	EADD	= 0x1,
+	EINIT	= 0x2,
+	EREMOVE	= 0x3,
+	EDGBRD	= 0x4,
+	EDGBWR	= 0x5,
+	EEXTEND	= 0x6,
+	ELDU	= 0x8,
+	EBLOCK	= 0x9,
+	EPA	= 0xA,
+	EWB	= 0xB,
+	ETRACK	= 0xC,
+	EAUG	= 0xD,
+	EMODPR	= 0xE,
+	EMODT	= 0xF,
+};
+
+#ifdef CONFIG_X86_64
+#define XAX "%%rax"
+#else
+#define XAX "%%eax"
+#endif
+
+#define __encls_ret(rax, rbx, rcx, rdx)			\
+	({						\
+	int ret;					\
+	asm volatile(					\
+	"1: .byte 0x0f, 0x01, 0xcf;\n\t"		\
+	"2:\n"						\
+	".section .fixup,\"ax\"\n"			\
+	"3: mov $-14,"XAX"\n"				\
+	"   jmp 2b\n"					\
+	".previous\n"					\
+	_ASM_EXTABLE(1b, 3b)				\
+	: "=a"(ret)					\
+	: "a"(rax), "b"(rbx), "c"(rcx), "d"(rdx)	\
+	: "memory");					\
+	ret;						\
+	})
+
+#define __encls(rax, rbx, rcx, rdx...)			\
+	({						\
+	int ret;					\
+	asm volatile(					\
+	"1: .byte 0x0f, 0x01, 0xcf;\n\t"		\
+	"   xor "XAX","XAX"\n"				\
+	"2:\n"						\
+	".section .fixup,\"ax\"\n"			\
+	"3: mov $-14,"XAX"\n"				\
+	"   jmp 2b\n"					\
+	".previous\n"					\
+	_ASM_EXTABLE(1b, 3b)				\
+	: "=a"(ret), "=b"(rbx), "=c"(rcx)		\
+	: "a"(rax), "b"(rbx), "c"(rcx), rdx		\
+	: "memory");					\
+	ret;						\
+	})
+
+static inline unsigned long __ecreate(struct sgx_pageinfo *pginfo, void *secs)
+{
+	return __encls(ECREATE, pginfo, secs, "d"(0));
+}
+
+static inline int __eextend(void *secs, void *epc)
+{
+	return __encls(EEXTEND, secs, epc, "d"(0));
+}
+
+static inline int __eadd(struct sgx_pageinfo *pginfo, void *epc)
+{
+	return __encls(EADD, pginfo, epc, "d"(0));
+}
+
+static inline int __einit(void *sigstruct, struct sgx_einittoken *einittoken,
+			  void *secs)
+{
+	return __encls_ret(EINIT, sigstruct, secs, einittoken);
+}
+
+static inline int __eremove(void *epc)
+{
+	unsigned long rbx = 0;
+	unsigned long rdx = 0;
+
+	return __encls_ret(EREMOVE, rbx, epc, rdx);
+}
+
+static inline int __edbgwr(unsigned long addr, unsigned long *data)
+{
+	return __encls(EDGBWR, *data, addr, "d"(0));
+}
+
+static inline int __edbgrd(unsigned long addr, unsigned long *data)
+{
+	unsigned long rbx = 0;
+	int ret;
+
+	ret = __encls(EDGBRD, rbx, addr, "d"(0));
+	if (!ret)
+		*(unsigned long *) data = rbx;
+
+	return ret;
+}
+
+static inline int __etrack(void *epc)
+{
+	unsigned long rbx = 0;
+	unsigned long rdx = 0;
+
+	return __encls_ret(ETRACK, rbx, epc, rdx);
+}
+
+static inline int __eldu(unsigned long rbx, unsigned long rcx,
+			 unsigned long rdx)
+{
+	return __encls_ret(ELDU, rbx, rcx, rdx);
+}
+
+static inline int __eblock(unsigned long rcx)
+{
+	unsigned long rbx = 0;
+	unsigned long rdx = 0;
+
+	return __encls_ret(EBLOCK, rbx, rcx, rdx);
+}
+
+static inline int __epa(void *epc)
+{
+	unsigned long rbx = SGX_PAGE_TYPE_VA;
+
+	return __encls(EPA, rbx, epc, "d"(0));
+}
+
+static inline int __ewb(struct sgx_pageinfo *pginfo, void *epc, void *va)
+{
+	return __encls_ret(EWB, pginfo, epc, va);
+}
+
+static inline int __eaug(struct sgx_pageinfo *pginfo, void *epc)
+{
+	return __encls(EAUG, pginfo, epc, "d"(0));
+}
+
+static inline int __emodpr(struct sgx_secinfo *secinfo, void *epc)
+{
+	unsigned long rdx = 0;
+
+	return __encls_ret(EMODPR, secinfo, epc, rdx);
+}
+
+static inline int __emodt(struct sgx_secinfo *secinfo, void *epc)
+{
+	unsigned long rdx = 0;
+
+	return __encls_ret(EMODT, secinfo, epc, rdx);
+}
+
+#endif /* _ASM_X86_SGX_H */
arch/x86/include/asm/sgx_arch.h new file +268 -0

268 lines not on this page · raw message

arch/x86/include/uapi/asm/sgx.h new file +138 -0

138 lines not on this page · raw message

drivers/platform/x86/Kconfig +2 -0
index 80b87954f6dd..51d429751235 100644
@@ -1139,6 +1139,8 @@ config SILEAD_DMI
 	  with the OS-image for the device. This option supplies the missing
 	  information. Enable this for x86 tablets with Silead touchscreens.
 
+source "drivers/platform/x86/intel_sgx/Kconfig"
+
 endif # X86_PLATFORM_DEVICES
 
 config PMC_ATOM
drivers/platform/x86/Makefile +1 -0
index 91cec1751461..b3a75ee512d2 100644
@@ -83,3 +83,4 @@ obj-$(CONFIG_PMC_ATOM)		+= pmc_atom.o
 obj-$(CONFIG_MLX_PLATFORM)	+= mlx-platform.o
 obj-$(CONFIG_MLX_CPLD_PLATFORM)	+= mlxcpld-hotplug.o
 obj-$(CONFIG_INTEL_TURBO_MAX_3) += intel_turbo_max_3.o
+obj-$(CONFIG_INTEL_SGX) += intel_sgx/
drivers/platform/x86/intel_sgx/Kconfig new file +19 -0
new file mode 100644
index 000000000000..5c7e61ecb524
@@ -0,0 +1,19 @@
+#
+# Intel SGX
+#
+
+config INTEL_SGX
+	tristate "Intel(R) SGX Driver"
+	default n
+	depends on X86_64 && CPU_SUP_INTEL
+	select MMU_NOTIFIER
+	---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.  The code
+	outside the enclave is disallowed to access the memory inside the
+	enclave by the CPU access control.
+
+	The firmware uses PRMRR registers to reserve an area of physical memory
+	called Enclave Page Cache (EPC). There is a hardware unit in the
+	processor called Memory Encryption Engine. The MEE encrypts and decrypts
+	the EPC pages as they enter and leave the processor package.
drivers/platform/x86/intel_sgx/Makefile new file +13 -0
new file mode 100644
index 000000000000..92af94668508
@@ -0,0 +1,13 @@
+#
+# Intel SGX
+#
+
+obj-$(CONFIG_INTEL_SGX) += intel_sgx.o
+
+intel_sgx-$(CONFIG_INTEL_SGX) += \
+	sgx_ioctl.o \
+	sgx_encl.o \
+	sgx_main.o \
+	sgx_page_cache.o \
+	sgx_util.o \
+	sgx_vma.o \
drivers/platform/x86/intel_sgx/sgx.h new file +244 -0

244 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_encl.c new file +981 -0

981 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_ioctl.c new file +280 -0

280 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_main.c new file +413 -0

413 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_page_cache.c new file +619 -0

399 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_util.c new file +369 -0

369 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_vma.c new file +117 -0

117 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.14.1

Part of the diff is not shown here. View the raw message.

#30 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

drivers/platform/x86/intel_sgx/sgx.h line 123

Quoted 8 lines
drivers/platform/x86/intel_sgx/sgx.h new file +8 -0
+struct sgx_encl_page {
+	unsigned long addr;
+	unsigned int flags;
+	void *epc_page;
+	struct sgx_va_page *va_page;
+	unsigned int va_offset;
+	struct list_head list;
+};

This can be without major streches hoops packed way more. There are 12 bits free for use in the addr field. I can use low three bits for flags and upper nine bits for va_offset.

I think I can also quite easily union epc_page and va_page fields.

With these changes the struct would shrink to:

struct sgx_encl_page {
	unsigned long addr;
	union {
		void *epc_page;
		struct sgx_va_page *va_page;
	};
	struct list_head list;
};

I can rework this for v7.

/Jarkko

#31 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

Quoted 17 lines · Jarkko Sakkinen

drivers/platform/x86/intel_sgx/sgx.h line 123

Quoted 8 lines
drivers/platform/x86/intel_sgx/sgx.h new file +8 -0
+struct sgx_encl_page {
+	unsigned long addr;
+	unsigned int flags;
+	void *epc_page;
+	struct sgx_va_page *va_page;
+	unsigned int va_offset;
+	struct list_head list;
+};

This can be without major streches hoops packed way more. There are 12 bits free for use in the addr field. I can use low three bits for flags and upper nine bits for va_offset.

I think I can also quite easily union epc_page and va_page fields.

With these changes the struct would shrink to:

Quoted 8 lines
struct sgx_encl_page {
	unsigned long addr;
	union {
		void *epc_page;
		struct sgx_va_page *va_page;
	};
	struct list_head list;
};

Once I started to thinking more about this I realized that this can be shrunk even further. I can drop the list field and use a tag for loaded pages in the radix tree where these are stored. The end result would be

struct sgx_encl_page {
	unsigned long addr;

union {
void *epc_page;
struct sgx_va_page *va_page;
};
};

/Jarkko

#32 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

Quoted 37 lines · Jarkko Sakkinen
Quoted 17 lines · Jarkko Sakkinen

drivers/platform/x86/intel_sgx/sgx.h line 123

Quoted 8 lines
drivers/platform/x86/intel_sgx/sgx.h new file +8 -0
+struct sgx_encl_page {
+	unsigned long addr;
+	unsigned int flags;
+	void *epc_page;
+	struct sgx_va_page *va_page;
+	unsigned int va_offset;
+	struct list_head list;
+};

This can be without major streches hoops packed way more. There are 12 bits free for use in the addr field. I can use low three bits for flags and upper nine bits for va_offset.

I think I can also quite easily union epc_page and va_page fields.

With these changes the struct would shrink to:

Quoted 8 lines
struct sgx_encl_page {
	unsigned long addr;
	union {
		void *epc_page;
		struct sgx_va_page *va_page;
	};
	struct list_head list;
};

Once I started to thinking more about this I realized that this can be shrunk even further. I can drop the list field and use a tag for loaded pages in the radix tree where these are stored. The end result would be

struct sgx_encl_page {
	unsigned long addr;
(quoted diff) +0 -0
 	union {
 		void *epc_page;
 		struct sgx_va_page *va_page;
 	};
Quoted 1 line

};

With this last size optimization there is an issue that it would be nice to select the pages to be swapped out in FIFO order. That kind of means that tag would not work quite well.

I could try an approach where I have a pointer array to present a queue inside struct sgx_encl for loaded pages and in that way get rid of the 'list' field.

/Jarkko

#33 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

Quoted 40 lines · Jarkko Sakkinen
Quoted 37 lines · Jarkko Sakkinen
Quoted 17 lines · Jarkko Sakkinen

drivers/platform/x86/intel_sgx/sgx.h line 123

Quoted 8 lines
drivers/platform/x86/intel_sgx/sgx.h new file +8 -0
+struct sgx_encl_page {
+	unsigned long addr;
+	unsigned int flags;
+	void *epc_page;
+	struct sgx_va_page *va_page;
+	unsigned int va_offset;
+	struct list_head list;
+};

This can be without major streches hoops packed way more. There are 12 bits free for use in the addr field. I can use low three bits for flags and upper nine bits for va_offset.

I think I can also quite easily union epc_page and va_page fields.

With these changes the struct would shrink to:

Quoted 8 lines
struct sgx_encl_page {
	unsigned long addr;
	union {
		void *epc_page;
		struct sgx_va_page *va_page;
	};
	struct list_head list;
};

Once I started to thinking more about this I realized that this can be shrunk even further. I can drop the list field and use a tag for loaded pages in the radix tree where these are stored. The end result would be

struct sgx_encl_page {
	unsigned long addr;
(quoted diff) +0 -0
 	union {
 		void *epc_page;
 		struct sgx_va_page *va_page;
 	};
Quoted 1 line

};

Quoted 7 lines

With this last size optimization there is an issue that it would be nice to select the pages to be swapped out in FIFO order. That kind of means that tag would not work quite well.

I could try an approach where I have a pointer array to present a queue inside struct sgx_encl for loaded pages and in that way get rid of the 'list' field.

I did other optimizations except taking the list field away so it's now a 32 byte structure. I guess sufficient for the first mainline version.

/Jarkko

#34 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

In reply to Jarkko Sakkinen
Quoted 6 lines
arch/x86/include/asm/sgx_arch.h new file +0 -0
new file mode 100644
index 000000000000..515676031006
@@ -0,0 +1,268 @@

[...]

arch/x86/include/asm/sgx_arch.h line 58

Quoted 3 lines
arch/x86/include/asm/sgx_arch.h new file +3 -0
+
+#ifndef _ASM_X86_SGX_ARCH_H
+#define _ASM_X86_SGX_ARCH_H

Still missing #include <linux/types.h>.

Quoted 3 lines
arch/x86/include/asm/sgx_arch.h new file +3 -0
+
+#define SGX_SSA_GPRS_SIZE              182
+#define SGX_SSA_MISC_EXINFO_SIZE       16
#35 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

In reply to Jarkko Sakkinen

drivers/platform/x86/intel_sgx/sgx_page_cache.c line 511

Quoted 10 lines · Jarkko Sakkinen
drivers/platform/x86/intel_sgx/sgx_page_cache.c new file +10 -0
+static void *sgx_try_alloc_page(void)
+{
+       struct sgx_epc_bank *bank;
+       void *page = NULL;
+       int i;
+
+       for (i = 0; i < sgx_nr_epc_banks; i++) {
+               bank = &sgx_epc_banks[i];
+
+               down_write(&bank->lock);

Is a R/W semaphore actually preferable to a spinlock? Concurrent free calls don't seem that interesting/beneficial because freeing an enclave's pages isn't multiplexed across multiple CPUs, unlike the allocation of EPC pages.

As a whole, I'm not a fan of packing the EPC page pointers into an array rather than encapsulating them in a struct+list. The primary benefit I see for the array approach is that it saves ~8 bytes per free EPC page, but at a cost of increased memory usage for in-use pages and severely restricting the ability to enhance/modify how EPC pages are tracked, reclaimed, etc...

The main issue is that the array approach relies on the caller to handle reclaim. This effectively makes it impossible to reclaim pages from multiple processes, requires other consumers e.g. KVM to implement their own reclaim logic and kthread, and prevents cgroup accounting because the cgroup can't initiate reclaim.

Quoted 15 lines
drivers/platform/x86/intel_sgx/sgx_page_cache.c new file +15 -0
+
+               if (atomic_read(&bank->free_cnt))
+                       page = bank->pages[atomic_dec_return(&bank->free_cnt)];
+
+               up_write(&bank->lock);
+
+               if (page)
+                       break;
+       }
+
+       if (page)
+               atomic_dec(&sgx_nr_free_pages);
+
+       return page;
+}
#36 lore raw

Re: [PATCH v6 06/11] intel_sgx: driver for Intel Software Guard Extensions

Quoted 16 lines · Sean Christopherson

drivers/platform/x86/intel_sgx/sgx_page_cache.c line 511

Quoted 10 lines · Jarkko Sakkinen
drivers/platform/x86/intel_sgx/sgx_page_cache.c new file +10 -0
+static void *sgx_try_alloc_page(void)
+{
+       struct sgx_epc_bank *bank;
+       void *page = NULL;
+       int i;
+
+       for (i = 0; i < sgx_nr_epc_banks; i++) {
+               bank = &sgx_epc_banks[i];
+
+               down_write(&bank->lock);

Is a R/W semaphore actually preferable to a spinlock? Concurrent free calls don't seem that interesting/beneficial because freeing an enclave's pages isn't multiplexed across multiple CPUs, unlike the allocation of EPC pages.

I get about ~10-15% performance increase on high stress. It is benefical to spinlock.

Quoted 6 lines

As a whole, I'm not a fan of packing the EPC page pointers into an array rather than encapsulating them in a struct+list. The primary benefit I see for the array approach is that it saves ~8 bytes per free EPC page, but at a cost of increased memory usage for in-use pages and severely restricting the ability to enhance/modify how EPC pages are tracked, reclaimed, etc...

This is not true. You can put EPC page descriptor to any structure you want.

list_head can be dropped from struct sgx_enc_page too.

Quoted 5 lines

The main issue is that the array approach relies on the caller to handle reclaim. This effectively makes it impossible to reclaim pages from multiple processes, requires other consumers e.g. KVM to implement their own reclaim logic and kthread, and prevents cgroup accounting because the cgroup can't initiate reclaim.

Not really following here.

/Jarkko

#37 lore raw

PATCH v6 7/11 intel_sgx: ptrace() support

In reply to Jarkko Sakkinen

Implemented VMA callbacks in order to ptrace() debug enclaves. With debug enclaves data can be read and write the memory word at a time by using ENCLS(EDBGRD) and ENCLS(EDBGWR) leaf instructions.

---
 drivers/platform/x86/intel_sgx/sgx_vma.c | 119 +++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
drivers/platform/x86/intel_sgx/sgx_vma.c +119 -0
index 481f671f10ca..a8f58ea65dd5 100644
@@ -110,8 +110,127 @@ static int sgx_vma_fault(struct vm_fault *vmf)
 		return VM_FAULT_SIGBUS;
 }
 
+static int sgx_edbgrd(struct sgx_encl *encl, struct sgx_encl_page *page,
+		      unsigned long addr, void *data)
+{
+	unsigned long offset;
+	void *ptr;
+	int ret;
+
+	offset = addr & PAGE_MASK;
+
+	if ((page->flags & SGX_ENCL_PAGE_TCS) &&
+	    (offset + sizeof(unsigned long)) >
+	    offsetof(struct sgx_tcs, reserved))
+		return -ECANCELED;
+
+	ptr = sgx_get_page(page->epc_page);
+	ret = __edbgrd((unsigned long)ptr + offset, data);
+	sgx_put_page(ptr);
+	if (ret) {
+		sgx_dbg(encl, "EDBGRD returned %d\n", ret);
+		return -EFAULT;
+	}
+
+	return 0;
+}
+
+static int sgx_edbgwr(struct sgx_encl *encl, struct sgx_encl_page *page,
+		      unsigned long addr, void *data)
+{
+	unsigned long offset;
+	void *ptr;
+	int ret;
+
+	offset = addr & PAGE_MASK;
+
+	/* Writing anything else than flags will cause #GP */
+	if ((page->flags & SGX_ENCL_PAGE_TCS) &&
+	    offset < offsetof(struct sgx_tcs, flags) &&
+	    (offset + sizeof(unsigned long)) >
+	    offsetof(struct sgx_tcs, flags))
+		return -ECANCELED;
+
+	ptr = sgx_get_page(page->epc_page);
+	ret = __edbgwr((unsigned long)ptr + offset, data);
+	sgx_put_page(ptr);
+	if (ret) {
+		sgx_dbg(encl, "EDBGRD returned %d\n", ret);
+		return -EFAULT;
+	}
+
+	return 0;
+}
+
+static int sgx_vma_access(struct vm_area_struct *vma, unsigned long addr,
+			  void *buf, int len, int write)
+{
+	struct sgx_encl *encl = vma->vm_private_data;
+	struct sgx_encl_page *entry = NULL;
+	unsigned long align;
+	char data[sizeof(unsigned long)];
+	int offset;
+	int cnt;
+	int ret = 0;
+	int i;
+
+	/* If process was forked, VMA is still there but vm_private_data is set
+	 * to NULL.
+	 */
+	if (!encl)
+		return -EFAULT;
+
+	if (!(encl->flags & SGX_ENCL_DEBUG) ||
+	    !(encl->flags & SGX_ENCL_INITIALIZED) ||
+	    (encl->flags & SGX_ENCL_DEAD))
+		return -EFAULT;
+
+	for (i = 0; i < len; i += cnt) {
+		if (!entry || !((addr + i) & (PAGE_SIZE - 1))) {
+			if (entry)
+				entry->flags &= ~SGX_ENCL_PAGE_RESERVED;
+
+			entry = sgx_fault_page(vma, (addr + i) & PAGE_MASK,
+					       SGX_FAULT_RESERVE);
+			if (IS_ERR(entry)) {
+				ret = PTR_ERR(entry);
+				entry = NULL;
+				break;
+			}
+		}
+
+		/* Locking is not needed because only immutable fields of the
+		 * page are accessed and page itself is reserved so that it
+		 * cannot be swapped out in the middle.
+		 */
+
+		align = ALIGN_DOWN(addr + i, sizeof(unsigned long));
+		offset = (addr + i) & (sizeof(unsigned long) - 1);
+		cnt = sizeof(unsigned long) - offset;
+		cnt = min(cnt, len - i);
+
+		ret = sgx_edbgrd(encl, entry, align, data);
+		if (ret)
+			return ret;
+
+		memcpy(data + offset, buf + i, cnt);
+
+		if (write) {
+			ret = sgx_edbgwr(encl, entry, align, data);
+			if (ret)
+				return ret;
+		}
+	}
+
+	if (entry)
+		entry->flags &= ~SGX_ENCL_PAGE_RESERVED;
+
+	return (ret < 0 && ret != -ECANCELED) ? ret : i;
+}
+
 const struct vm_operations_struct sgx_vm_ops = {
 	.close = sgx_vma_close,
 	.open = sgx_vma_open,
 	.fault = sgx_vma_fault,
+	.access = sgx_vma_access,
 };
Signature · 1 line
2.14.1
#38 lore raw

Re: [PATCH v6 07/11] intel_sgx: ptrace() support

drivers/platform/x86/intel_sgx/sgx_vma.c static int sgx_vma_fault(struct vm_fault *vmf) · line 131

Quoted 5 lines · Jarkko Sakkinen
drivers/platform/x86/intel_sgx/sgx_vma.c +5 -0
+	ptr = sgx_get_page(page->epc_page);
+	ret = __edbgrd((unsigned long)ptr + offset, data);
+	sgx_put_page(ptr);
+	if (ret) {
+		sgx_dbg(encl, "EDBGRD returned %d\n", ret);
                               ~~~~~~
			       EDBGWR

/Jarkko

#39 lore raw

Re: [PATCH v6 07/11] intel_sgx: ptrace() support

Quoted 3 lines · Jarkko Sakkinen

drivers/platform/x86/intel_sgx/sgx_vma.c static int sgx_vma_fault(struct vm_fault *vmf) · line 128

Quoted 2 lines · Jarkko Sakkinen
drivers/platform/x86/intel_sgx/sgx_vma.c +2 -0
+	ptr = sgx_get_page(page->epc_page);
+	ret = __edbgrd((unsigned long)ptr + offset, data);
	        ^^^^^^
Quoted 5 lines

drivers/platform/x86/intel_sgx/sgx_vma.c static int sgx_vma_fault(struct vm_fault *vmf) · line 131

Quoted 3 lines
drivers/platform/x86/intel_sgx/sgx_vma.c +3 -0
+	sgx_put_page(ptr);
+	if (ret) {
+		sgx_dbg(encl, "EDBGRD returned %d\n", ret);
                               ~~~~~~
			       EDBGWR

?

#40 lore raw

Re: [PATCH v6 07/11] intel_sgx: ptrace() support

Quoted 6 lines · Joe Perches
Quoted 3 lines · Jarkko Sakkinen

drivers/platform/x86/intel_sgx/sgx_vma.c static int sgx_vma_fault(struct vm_fault *vmf) · line 128

Quoted 2 lines · Jarkko Sakkinen
drivers/platform/x86/intel_sgx/sgx_vma.c +2 -0
+	ptr = sgx_get_page(page->epc_page);
+	ret = __edbgrd((unsigned long)ptr + offset, data);
	        ^^^^^^
Quoted 7 lines
Quoted 5 lines

drivers/platform/x86/intel_sgx/sgx_vma.c static int sgx_vma_fault(struct vm_fault *vmf) · line 131

Quoted 3 lines
drivers/platform/x86/intel_sgx/sgx_vma.c +3 -0
+	sgx_put_page(ptr);
+	if (ret) {
+		sgx_dbg(encl, "EDBGRD returned %d\n", ret);
                               ~~~~~~
			       EDBGWR

?

D'oh I meant to quote this part:

	ptr = sgx_get_page(page->epc_page);
	ret = __edbgwr((unsigned long)ptr + offset, data);
	sgx_put_page(ptr);
	if (ret) {
		sgx_dbg(encl, "EDBGRD returned %d\n", ret);
		return -EFAULT;
	}

There's a typo in sgx_dbg().

/Jarkko

#41 lore raw

Re: [PATCH v6 07/11] intel_sgx: ptrace() support

In reply to Jarkko Sakkinen

Review

Quoted 1 line · Jarkko Sakkinen
(quoted diff) +1 -0
+	offset = addr & PAGE_MASK;

Should be addr & ~PAGE_MASK. Had fixup for this but it ended up not be squashed to the series :-(

/Jarkko

#42 lore raw

PATCH v6 8/11 intel_sgx: in-kernel launch enclave

In reply to Jarkko Sakkinen

This commits implements the in-kernel launch enclave. It is wrapped into a user space program that reads SIGSTRUCT instances from stdin and outputs launch tokens to stdout.

The commit also adds enclave signing tool that is used by kbuild to measure and sign the launch enclave.

CONFIG_INTEL_SGX_SIGNING_KEY points to a PEM-file for the 3072-bit RSA key that is used as the LE public key pair. The default location is:

drivers/platform/x86/intel_sgx/intel_sgx_signing_key.pem

If the default key does not exist kbuild will generate a random key and place it to this location. KBUILD_SGX_SIGN_PIN can be used to specify the passphrase for the LE public key.

TinyCrypt (https://github.com/01org/tinycrypt) is used as AES implementation, which is not timing resistant. Eventually this needs to be replaced with AES-NI based implementation that could be either

- re-use existing AES-NI code in the kernel
- have its own hand written code

---
 drivers/platform/x86/intel_sgx/Kconfig             |  13 +
 drivers/platform/x86/intel_sgx/Makefile            |  18 +
 drivers/platform/x86/intel_sgx/le/Makefile         |  26 +
 drivers/platform/x86/intel_sgx/le/enclave/Makefile |  46 ++
 .../x86/intel_sgx/le/enclave/aes_encrypt.c         | 191 ++++++++
 .../platform/x86/intel_sgx/le/enclave/cmac_mode.c  | 254 ++++++++++
 .../x86/intel_sgx/le/enclave/encl_bootstrap.S      | 163 +++++++
 .../intel_sgx/le/enclave/include/tinycrypt/aes.h   | 133 +++++
 .../le/enclave/include/tinycrypt/cmac_mode.h       | 194 ++++++++
 .../le/enclave/include/tinycrypt/constants.h       |  59 +++
 .../intel_sgx/le/enclave/include/tinycrypt/utils.h |  95 ++++
 drivers/platform/x86/intel_sgx/le/enclave/main.c   | 203 ++++++++
 .../platform/x86/intel_sgx/le/enclave/sgx_le.lds   |  28 ++
 .../platform/x86/intel_sgx/le/enclave/sgxsign.c    | 538 +++++++++++++++++++++
 drivers/platform/x86/intel_sgx/le/enclave/utils.c  |  78 +++
 drivers/platform/x86/intel_sgx/le/entry.S          | 117 +++++
 .../platform/x86/intel_sgx/le/include/sgx_asm.h    |  64 +++
 .../platform/x86/intel_sgx/le/include/sgx_encl.h   | 110 +++++
 drivers/platform/x86/intel_sgx/le/main.c           | 214 ++++++++
 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S   |  15 +
 .../platform/x86/intel_sgx/sgx_le_proxy_piggy.S    |  11 +
 21 files changed, 2570 insertions(+)
 create mode 100644 drivers/platform/x86/intel_sgx/le/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/aes_encrypt.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/encl_bootstrap.S
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/aes.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/cmac_mode.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/constants.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/utils.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/sgx_le.lds
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/sgxsign.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/utils.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/entry.S
 create mode 100644 drivers/platform/x86/intel_sgx/le/include/sgx_asm.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/include/sgx_encl.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/main.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_le_proxy_piggy.S
drivers/platform/x86/intel_sgx/Kconfig +13 -0
index 5c7e61ecb524..050861bb5229 100644
@@ -2,6 +2,8 @@
 # Intel SGX
 #
 
+menu "Intel SGX"
+
 config INTEL_SGX
 	tristate "Intel(R) SGX Driver"
 	default n
@@ -17,3 +19,14 @@ config INTEL_SGX
 	called Enclave Page Cache (EPC). There is a hardware unit in the
 	processor called Memory Encryption Engine. The MEE encrypts and decrypts
 	the EPC pages as they enter and leave the processor package.
+
+
+config INTEL_SGX_SIGNING_KEY
+	string "Path to the Intel SGX LE signing key"
+	default "drivers/platform/x86/intel_sgx/signing_key.pem"
+	depends on INTEL_SGX
+	---help---
+	Provide a path to a 3072-bit RSA private key that will be used to
+	sign the launch enclave.
+
+endmenu
drivers/platform/x86/intel_sgx/Makefile +18 -0
index 92af94668508..fc76f3c923ce 100644
@@ -11,3 +11,21 @@ intel_sgx-$(CONFIG_INTEL_SGX) += \
 	sgx_page_cache.o \
 	sgx_util.o \
 	sgx_vma.o \
+	sgx_le_proxy_piggy.o
+
+$(eval $(call config_filename,INTEL_SGX_SIGNING_KEY))
+
+INTEL_SGX_SIGNING_KEY_PATH := \
+	$(INTEL_SGX_SIGNING_KEY_SRCPREFIX)$(INTEL_SGX_SIGNING_KEY_FILENAME)
+
+ifeq ($(CONFIG_INTEL_SGX_SIGNING_KEY),"drivers/platform/x86/intel_sgx/signing_key.pem")
+$(INTEL_SGX_SIGNING_KEY_PATH):
+	$(Q)openssl genrsa -3 -out $(INTEL_SGX_SIGNING_KEY_PATH) 3072
+endif
+
+$(obj)/sgx_le_proxy_piggy.o: $(INTEL_SGX_SIGNING_KEY_PATH) \
+			     $(obj)/le/sgx_le_proxy
+$(obj)/le/sgx_le_proxy: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/le $@
+
+export INTEL_SGX_SIGNING_KEY_PATH
drivers/platform/x86/intel_sgx/le/Makefile new file +26 -0
new file mode 100644
index 000000000000..50fe1849f6ca
@@ -0,0 +1,26 @@
+KASAN_SANITIZE := n
+OBJECT_FILES_NON_STANDARD := y
+KCOV_INSTRUMENT := n
+KBUILD_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -I$(obj)/include
+KBUILD_AFLAGS += -I$(obj)/include
+
+subdir- := enclave
+
+always := sgx_le_proxy
+clean-files := sgx_le_proxy
+
+#
+# sgx_le_proxy
+#
+
+sgx_le_proxy-y += main.o entry.o sgx_le_piggy.o
+targets += $(sgx_le_proxy-y)
+SGX_LE_PROXY_OBJS = $(addprefix $(obj)/,$(sgx_le_proxy-y))
+
+$(obj)/sgx_le_piggy.o: $(obj)/enclave/sgx_le.bin $(obj)/enclave/sgx_le.ss
+$(obj)/enclave/sgx_le.bin $(obj)/enclave/sgx_le.ss: FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/enclave $@
+
+targets += sgx_le_proxy
+$(obj)/sgx_le_proxy: $(SGX_LE_PROXY_OBJS)
+	$(call if_changed,ld)
drivers/platform/x86/intel_sgx/le/enclave/Makefile new file +46 -0

46 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/aes_encrypt.c new file +191 -0

191 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c new file +254 -0

254 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/encl_bootstrap.S new file +163 -0

163 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/aes.h new file +133 -0

133 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/cmac_mode.h new file +194 -0

194 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/constants.h new file +59 -0

59 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/utils.h new file +95 -0

95 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/main.c new file +203 -0

203 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/sgx_le.lds new file +28 -0
new file mode 100644
index 000000000000..56b694c15ebe
@@ -0,0 +1,28 @@
+OUTPUT_FORMAT(elf64-x86-64)
+
+SECTIONS
+{
+	. = 0;
+	.tcs : {
+		*(.tcs*)
+	}
+
+	. = ALIGN(4096);
+	.text : {
+		*(.text*)
+		*(.rodata*)
+	}
+
+	. = ALIGN(4096);
+	.data : {
+		*(.data*)
+	}
+
+	/DISCARD/ : {
+		*(.data*)
+		*(.comment*)
+		*(.note*)
+		*(.debug*)
+		*(.eh_frame*)
+	}
+}
drivers/platform/x86/intel_sgx/le/enclave/sgxsign.c new file +538 -0

538 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/enclave/utils.c new file +78 -0

78 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/entry.S new file +117 -0

117 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/include/sgx_asm.h new file +64 -0

64 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/include/sgx_encl.h new file +110 -0

110 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/main.c new file +214 -0

214 lines not on this page · raw message

drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S new file +15 -0
new file mode 100644
index 000000000000..e5631e8a755d
@@ -0,0 +1,15 @@
+#include <linux/linkage.h>
+#include <asm/page_types.h>
+
+	.section ".rodata","a"
+	.balign PAGE_SIZE
+
+GLOBAL(sgx_le_blob)
+	.incbin	"drivers/platform/x86/intel_sgx/le/enclave/sgx_le.bin"
+END(sgx_le_blob)
+
+GLOBAL(sgx_le_blob_end);
+
+GLOBAL(sgx_le_ss)
+	.incbin	"drivers/platform/x86/intel_sgx/le/enclave/sgx_le.ss"
+END(sgx_le_ss)
drivers/platform/x86/intel_sgx/sgx_le_proxy_piggy.S new file +11 -0
new file mode 100644
index 000000000000..faced8a9a75a
@@ -0,0 +1,11 @@
+#include <linux/linkage.h>
+#include <asm/export.h>
+#include <asm/page_types.h>
+
+	.section ".rodata","a"
+
+GLOBAL(sgx_le_proxy)
+	.incbin	"drivers/platform/x86/intel_sgx/le/sgx_le_proxy"
+END(sgx_le_proxy)
+
+GLOBAL(sgx_le_proxy_end)
Signature · 1 line
2.14.1
#43 lore raw

Re: [PATCH v6 08/11] intel_sgx: in-kernel launch enclave

Quoted 11 lines · Jarkko Sakkinen

This commits implements the in-kernel launch enclave. It is wrapped into a user space program that reads SIGSTRUCT instances from stdin and outputs launch tokens to stdout.

The commit also adds enclave signing tool that is used by kbuild to measure and sign the launch enclave.

CONFIG_INTEL_SGX_SIGNING_KEY points to a PEM-file for the 3072-bit RSA key that is used as the LE public key pair. The default location is:

drivers/platform/x86/intel_sgx/intel_sgx_signing_key.pem

                                   ^
                                   signing_key.pem

You forgot to change the name of the pem file in the commit message.

Quoted 5 lines

If the default key does not exist kbuild will generate a random key and place it to this location. KBUILD_SGX_SIGN_PIN can be used to specify the passphrase for the LE public key.

Quoted 8 lines

TinyCrypt (https://github.com/01org/tinycrypt) is used as AES implementation, which is not timing resistant. Eventually this needs to be replaced with AES-NI based implementation that could be either

- re-use existing AES-NI code in the kernel
- have its own hand written code

[...]

Cheers
Till

#44 lore raw

Re: [PATCH v6 08/11] intel_sgx: in-kernel launch enclave

Quoted 5 lines · Till Smejkal
Quoted 1 line

drivers/platform/x86/intel_sgx/intel_sgx_signing_key.pem

                                   ^
                                   signing_key.pem

You forgot to change the name of the pem file in the commit message.

Thanks for catching this :-) Will fix it for the next version.

/Jarkko

#45 lore raw

Re: [PATCH v6 08/11] intel_sgx: in-kernel launch enclave

In reply to Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen

This commits implements the in-kernel launch enclave. It is wrapped into a user space program that reads SIGSTRUCT instances from stdin and outputs launch tokens to stdout.

The commit also adds enclave signing tool that is used by kbuild to measure and sign the launch enclave.

CONFIG_INTEL_SGX_SIGNING_KEY points to a PEM-file for the 3072-bit RSA key that is used as the LE public key pair. The default location is:

drivers/platform/x86/intel_sgx/intel_sgx_signing_key.pem

If the default key does not exist kbuild will generate a random key and place it to this location. KBUILD_SGX_SIGN_PIN can be used to specify the passphrase for the LE public key.

Quoted 6 lines

TinyCrypt (https://github.com/01org/tinycrypt) is used as AES implementation, which is not timing resistant. Eventually this needs to be replaced with AES-NI based implementation that could be either

- re-use existing AES-NI code in the kernel
- have its own hand written code

The AES is the biggest remaining open I think.

I'm starting look at how to re-use kernel aesni code by linking it as part of the enclave binary i.e. aesni-intel_asm.S. This will render away TinyCrypt's AES code that is used ATM.

I still need TinyCrypt CMAC, which I will modify to call CBC AES encryption routine.

Does this sound like a sufficient plan?

/Jarkko

#46 lore raw

Re: [PATCH v6 08/11] intel_sgx: in-kernel launch enclave

Quoted 26 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen

This commits implements the in-kernel launch enclave. It is wrapped into a user space program that reads SIGSTRUCT instances from stdin and outputs launch tokens to stdout.

The commit also adds enclave signing tool that is used by kbuild to measure and sign the launch enclave.

CONFIG_INTEL_SGX_SIGNING_KEY points to a PEM-file for the 3072-bit RSA key that is used as the LE public key pair. The default location is:

drivers/platform/x86/intel_sgx/intel_sgx_signing_key.pem

If the default key does not exist kbuild will generate a random key and place it to this location. KBUILD_SGX_SIGN_PIN can be used to specify the passphrase for the LE public key.

Quoted 6 lines

TinyCrypt (https://github.com/01org/tinycrypt) is used as AES implementation, which is not timing resistant. Eventually this needs to be replaced with AES-NI based implementation that could be either

- re-use existing AES-NI code in the kernel
- have its own hand written code

The AES is the biggest remaining open I think.

Quoted 8 lines

I'm starting look at how to re-use kernel aesni code by linking it as part of the enclave binary i.e. aesni-intel_asm.S. This will render away TinyCrypt's AES code that is used ATM.

I still need TinyCrypt CMAC, which I will modify to call CBC AES encryption routine.

Does this sound like a sufficient plan?

I'm successfully using now kernel provided aesni_enc and aesni_set_key. Only CMAC comes from TC. I think refactor stuff in cmac_mode.c to kernel coding style and call it as derived works from TC since already calls have replaced (AES). Makes sense to clean it up and make it pass checkpatch.pl.

/Jarkko

#47 lore raw

PATCH v6 9/11 fs/pipe.c: export create_pipe_files() and replace_fd()

In reply to Jarkko Sakkinen

Exported create_pipe_files() and replace_fd() because the SGX driver needs to be able to setup pipes in order to communicate with the helper process that hosts the Launch Enclave (LE). The pipe creation will be done in the init-callback supplied to call_usermodehelper_setup().

The driver will use two pipes for communication with the LE hosting process:

* One for writing SIGSTRUCT blobs.
* One for reading EINITTOKEN blobs.

---
 fs/file.c | 1 +
 fs/pipe.c | 1 +
 2 files changed, 2 insertions(+)
fs/file.c +1 -0
index 1fc7fbbb4510..b1fa28919b22 100644
@@ -871,6 +871,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
 	spin_unlock(&files->file_lock);
 	return err;
 }
+EXPORT_SYMBOL_GPL(replace_fd);
 
 SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
 {
fs/pipe.c +1 -0
index 97e5be897753..ee33a84127e7 100644
@@ -784,6 +784,7 @@ int create_pipe_files(struct file **res, int flags)
 	iput(inode);
 	return err;
 }
+EXPORT_SYMBOL_GPL(create_pipe_files);
 
 static int __do_pipe_flags(int *fd, struct file **files, int flags)
 {
Signature · 1 line
2.14.1
#48 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Repeated NAK - any interface that deals with raw file descriptor table entries has absolutely no business in a driver.

Please fix your API already.

#49 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 4 lines · Christoph Hellwig

Repeated NAK - any interface that deals with raw file descriptor table entries has absolutely no business in a driver.

Please fix your API already.

Does it make a differnece if the code is moved to arch/x86, which could potentially happen (see Darren's and tglx's comments on v5)? Then the need for export will be gone.

/Jarkko

#50 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 9 lines · Jarkko Sakkinen
Quoted 4 lines · Christoph Hellwig

Repeated NAK - any interface that deals with raw file descriptor table entries has absolutely no business in a driver.

Please fix your API already.

Does it make a differnece if the code is moved to arch/x86, which could potentially happen (see Darren's and tglx's comments on v5)? Then the need for export will be gone.

Yes. You still shall not play nasty games with file descriptors.

#51 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Jarkko Sakkinen
Quoted 3 lines · Christoph Hellwig

Repeated NAK - any interface that deals with raw file descriptor table entries has absolutely no business in a driver.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Please fix your API already.

Does it make a differnece if the code is moved to arch/x86, which could potentially happen (see Darren's and tglx's comments on v5)? Then the need for export will be gone.

Yes. You still shall not play nasty games with file descriptors.

I need to put something to file descriptors in order to have a IO channels for the launch enclave hosting process.

/Jarkko

#52 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 4 lines · Jarkko Sakkinen
Quoted 1 line

Yes. You still shall not play nasty games with file descriptors.

I need to put something to file descriptors in order to have a IO channels for the launch enclave hosting process.

Just do it like any other program - open it from your userspace program using open() and related syscalls.

#53 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Jarkko Sakkinen
Quoted 1 line

Yes. You still shall not play nasty games with file descriptors.

I need to put something to file descriptors in order to have a IO channels for the launch enclave hosting process.

Just do it like any other program - open it from your userspace program using open() and related syscalls.

In this case it would not work as the launch enclave is still part of the kernel and it would create a dependency how the user space defines paths. If using pipe specifically is an issue, I could easily use shmem file as a mean for communiation.

The way I implemented is much like how I did arch/x86/realmode with HPA and it has kind of comparable requirements, part of the kernel but not exactly code living in the kernel namespace.

/Jarkko

#54 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 11 lines · Jarkko Sakkinen
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Jarkko Sakkinen
Quoted 4 lines

Yes.  You still shall not play nasty games with file descriptors.

I need to put something to file descriptors in order to have a IO channels for the launch enclave hosting process.

Quoted 7 lines
Quoted 2 lines

Just do it like any other program - open it from your userspace program using open() and related syscalls.

In this case it would not work as the launch enclave is still part of the kernel and it would create a dependency how the user space defines paths. If using pipe specifically is an issue, I could easily use shmem file as a mean for communiation.

Can't you simply use

sys_pipe2()
sys_close()
sys_dup2()

To achieve the same effect as replace_fd()/create_pipe_files()?

The point Christoph is making is that you can call sys_ interfaces from within the kernel (carefully) and have them operate like direct invocations.  Look at main.c:kernel_init_freeable() it's doing something similar to what you want, except with the console, not a pipe and it begins with the file table empty.

James

#55 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 26 lines · James Bottomley
Quoted 11 lines · Jarkko Sakkinen
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Jarkko Sakkinen
Quoted 4 lines

Yes.  You still shall not play nasty games with file descriptors.

I need to put something to file descriptors in order to have a IO channels for the launch enclave hosting process.

Quoted 7 lines
Quoted 2 lines

Just do it like any other program - open it from your userspace program using open() and related syscalls.

In this case it would not work as the launch enclave is still part of the kernel and it would create a dependency how the user space defines paths. If using pipe specifically is an issue, I could easily use shmem file as a mean for communiation.

Can't you simply use

sys_pipe2()
sys_close()
sys_dup2()

Quoted 7 lines

To achieve the same effect as replace_fd()/create_pipe_files()?

The point Christoph is making is that you can call sys_ interfaces from within the kernel (carefully) and have them operate like direct invocations.  Look at main.c:kernel_init_freeable() it's doing something similar to what you want, except with the console, not a pipe and it begins with the file table empty.

Thank you. I'll take a peek.

/Jarkko

#56 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 29 lines · Jarkko Sakkinen
Quoted 28 lines · James Bottomley
Quoted 11 lines · Jarkko Sakkinen
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Jarkko Sakkinen
Quoted 4 lines

Yes.  You still shall not play nasty games with file descriptors.

I need to put something to file descriptors in order to have a IO channels for the launch enclave hosting process.

Quoted 7 lines
Quoted 2 lines

Just do it like any other program - open it from your userspace program using open() and related syscalls.

In this case it would not work as the launch enclave is still part of the kernel and it would create a dependency how the user space defines paths. If using pipe specifically is an issue, I could easily use shmem file as a mean for communiation.

Can't you simply use

sys_pipe2()
sys_close()
sys_dup2()

To achieve the same effect as replace_fd()/create_pipe_files()?

Quoted 7 lines
Quoted 5 lines

The point Christoph is making is that you can call sys_ interfaces from within the kernel (carefully) and have them operate like direct invocations.  Look at main.c:kernel_init_freeable() it's doing something similar to what you want, except with the console, not a pipe and it begins with the file table empty.

Thank you. I'll take a peek.

It doesn't apply here as it depends of the filesystem paths.

I think I could replace pipes with anonymous inodes. Is that a better idea than pipes? I can work on that v8 if the export is a show stopper as it seems. We are using that to do some other stuff in tpm_vtpm_proxy.

I submitted v7 of the patch set still as a self-contained driver. For that I'm looking forward to get feedback on:

1. Could the first upstream version be a self-contained driver even if some stuff would be eventually moved to arch/x86? There is nothing preventing on doing that and that would be a non-intrusive way to upstream such a large piece of functionality.
2. If for the first upstream version something needs to be placed to arch/x86, I would like to get some guidelines on deployment. I guess it would go under arch/x86/kernel/cpu/sgx?
3. I fixed the AES issue. Is there anything else BIG that needs to be fixed?

/Jarkko

#57 lore raw

Re: [PATCH v6 09/11] fs/pipe.c: export create_pipe_files() and replace_fd()

Quoted 3 lines · Jarkko Sakkinen

I think I could replace pipes with anonymous inodes. Is that a better idea than pipes? I can work on that v8 if the export is a show stopper as it seems. We are using that to do some other stuff in tpm_vtpm_proxy.

I'll go with the anon inode solution. It should be fairly easy to implement.

/Jarkko

#58 lore raw

PATCH v6 10/11 intel_sgx: glue code for in-kernel LE

In reply to Jarkko Sakkinen

Glue code for hosting in-kernel Launch Enclave (LE) by using the user space helper framework.

Tokens for launching enclaves are generated with by the following protocol:

1. The driver sends a SIGSTRUCT blob to the LE hosting process to the input pipe.
2. The LE hosting process reads the SIGSTRUCT blob from the input pipe.
3. After generating a EINITTOKEN blob, the LE hosting process writes it to the output pipe.
4. The driver reads the EINITTOKEN blob from the output pipe.

If IA32_SGXLEPUBKEYHASH* MSRs are writable and they don't have the public key hash of the LE they will be updated.

---
 drivers/platform/x86/intel_sgx/Kconfig             |   2 +
 drivers/platform/x86/intel_sgx/Makefile            |   1 +
 drivers/platform/x86/intel_sgx/sgx.h               |  24 ++
 drivers/platform/x86/intel_sgx/sgx_encl.c          |  18 ++
 drivers/platform/x86/intel_sgx/sgx_ioctl.c         |   4 +-
 drivers/platform/x86/intel_sgx/sgx_le.c            | 319 +++++++++++++++++++++
 .../platform/x86/intel_sgx/sgx_le_proxy_piggy.S    |   4 +
 drivers/platform/x86/intel_sgx/sgx_main.c          |  49 +++-
 drivers/platform/x86/intel_sgx/sgx_util.c          |  25 ++
 9 files changed, 442 insertions(+), 4 deletions(-)
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_le.c
drivers/platform/x86/intel_sgx/Kconfig +2 -0
index 050861bb5229..a0daccbc1036 100644
@@ -9,6 +9,8 @@ config INTEL_SGX
 	default n
 	depends on X86_64 && CPU_SUP_INTEL
 	select MMU_NOTIFIER
+	select CRYPTO
+	select CRYPTO_SHA256
 	---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.  The code
drivers/platform/x86/intel_sgx/Makefile +1 -0
index fc76f3c923ce..7ca1a7c6ab77 100644
@@ -11,6 +11,7 @@ intel_sgx-$(CONFIG_INTEL_SGX) += \
 	sgx_page_cache.o \
 	sgx_util.o \
 	sgx_vma.o \
+	sgx_le.o \
 	sgx_le_proxy_piggy.o
 
 $(eval $(call config_filename,INTEL_SGX_SIGNING_KEY))
drivers/platform/x86/intel_sgx/sgx.h +24 -0
index 384e25244d92..d0cb8d5dd53a 100644
@@ -60,8 +60,11 @@
 #ifndef __ARCH_INTEL_SGX_H__
 #define __ARCH_INTEL_SGX_H__
 
+#include <crypto/hash.h>
 #include <linux/kref.h>
 #include <linux/mmu_notifier.h>
+#include <linux/mmu_notifier.h>
+#include <linux/radix-tree.h>
 #include <linux/radix-tree.h>
 #include <linux/rbtree.h>
 #include <linux/rwsem.h>
@@ -161,13 +164,19 @@ struct sgx_encl {
 	struct mmu_notifier mmu_notifier;
 };
 
+extern unsigned char sgx_le_proxy[];
+extern unsigned char sgx_le_proxy_end[];
+extern struct sgx_sigstruct sgx_le_ss;
 extern struct workqueue_struct *sgx_add_page_wq;
 extern u64 sgx_encl_size_max_32;
 extern u64 sgx_encl_size_max_64;
 extern u64 sgx_xfrm_mask;
 extern u32 sgx_misc_reserved;
 extern u32 sgx_xsave_size_tbl[64];
+extern u64 sgx_le_pubkeyhash[4];
+extern bool sgx_unlocked_msrs;
 
+extern const struct file_operations sgx_fops;
 extern const struct vm_operations_struct sgx_vm_ops;
 
 #define sgx_pr_ratelimited(level, encl, fmt, ...)			  \
@@ -227,6 +236,9 @@ struct sgx_encl_page *sgx_fault_page(struct vm_area_struct *vma,
 				     unsigned int flags);
 
 
+int sgx_get_key_hash(struct crypto_shash *tfm, const void *modulus, void *hash);
+int sgx_get_key_hash_simple(const void *modulus, void *hash);
+
 extern struct mutex sgx_tgid_ctx_mutex;
 extern struct list_head sgx_tgid_ctx_list;
 extern atomic_t sgx_va_pages_cnt;
@@ -241,4 +253,16 @@ void sgx_put_page(void *ptr);
 void sgx_eblock(struct sgx_encl *encl, void *epc_page);
 void sgx_etrack(struct sgx_encl *encl);
 
+extern struct sgx_le_ctx sgx_le_ctx;
+
+int sgx_le_init(struct sgx_le_ctx *ctx);
+void sgx_le_exit(struct sgx_le_ctx *ctx);
+void sgx_le_stop(struct sgx_le_ctx *ctx);
+int sgx_le_start(struct sgx_le_ctx *ctx);
+
+int sgx_le_get_token(struct sgx_le_ctx *ctx,
+		     const struct sgx_encl *encl,
+		     const struct sgx_sigstruct *sigstruct,
+		     struct sgx_einittoken *token);
+
 #endif /* __ARCH_X86_INTEL_SGX_H__ */
drivers/platform/x86/intel_sgx/sgx_encl.c +18 -0
index 57dc1f90f4dc..0ffae3c02342 100644
@@ -866,6 +866,14 @@ static int sgx_einit(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
 	return ret;
 }
 
+static void sgx_update_pubkeyhash(void)
+{
+	wrmsrl(MSR_IA32_SGXLEPUBKEYHASH0, sgx_le_pubkeyhash[0]);
+	wrmsrl(MSR_IA32_SGXLEPUBKEYHASH1, sgx_le_pubkeyhash[1]);
+	wrmsrl(MSR_IA32_SGXLEPUBKEYHASH2, sgx_le_pubkeyhash[2]);
+	wrmsrl(MSR_IA32_SGXLEPUBKEYHASH3, sgx_le_pubkeyhash[3]);
+}
+
 /**
  * sgx_encl_init - perform EINIT for the given enclave
  *
@@ -901,6 +909,16 @@ int sgx_encl_init(struct sgx_encl *encl, struct sgx_sigstruct *sigstruct,
 		for (j = 0; j < SGX_EINIT_SPIN_COUNT; j++) {
 			ret = sgx_einit(encl, sigstruct, token);
 
+			if (ret == SGX_INVALID_ATTRIBUTE ||
+			    ret == SGX_INVALID_EINITTOKEN) {
+				if (sgx_unlocked_msrs) {
+					preempt_disable();
+					sgx_update_pubkeyhash();
+					ret = sgx_einit(encl, sigstruct, token);
+					preempt_enable();
+				}
+			}
+
 			if (ret == SGX_UNMASKED_EVENT)
 				continue;
 			else
drivers/platform/x86/intel_sgx/sgx_ioctl.c +3 -1
index 7e75c917048f..15c1d86983b6 100644
@@ -234,7 +234,9 @@ static long sgx_ioc_enclave_init(struct file *filep, unsigned int cmd,
 	if (ret)
 		goto out;
 
-	ret = sgx_encl_init(encl, sigstruct, einittoken);
+	ret = sgx_le_get_token(&sgx_le_ctx, encl, sigstruct, einittoken);
+	if (!ret)
+		ret = sgx_encl_init(encl, sigstruct, einittoken);
 
 	kref_put(&encl->refcount, sgx_encl_release);
 
drivers/platform/x86/intel_sgx/sgx_le.c new file +319 -0

319 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_le_proxy_piggy.S +4 -0
index faced8a9a75a..e1e3742a0c93 100644
@@ -9,3 +9,7 @@ GLOBAL(sgx_le_proxy)
 END(sgx_le_proxy)
 
 GLOBAL(sgx_le_proxy_end)
+
+GLOBAL(sgx_le_ss)
+	.incbin	"drivers/platform/x86/intel_sgx/le/enclave/sgx_le.ss"
+END(sgx_le_ss)
drivers/platform/x86/intel_sgx/sgx_main.c +46 -3

102 lines not on this page · raw message

drivers/platform/x86/intel_sgx/sgx_util.c +25 -0
index bf2fe5d4ad2e..8756ca15e24b 100644
@@ -367,3 +367,28 @@ void sgx_etrack(struct sgx_encl *encl)
 		sgx_invalidate(encl, true);
 	}
 }
+
+int sgx_get_key_hash(struct crypto_shash *tfm, const void *modulus, void *hash)
+{
+	SHASH_DESC_ON_STACK(shash, tfm);
+
+	shash->tfm = tfm;
+	shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+	return crypto_shash_digest(shash, modulus, SGX_MODULUS_SIZE, hash);
+}
+
+int sgx_get_key_hash_simple(const void *modulus, void *hash)
+{
+	struct crypto_shash *tfm;
+	int ret;
+
+	tfm = crypto_alloc_shash("sha256", 0, CRYPTO_ALG_ASYNC);
+	if (IS_ERR(tfm))
+		return PTR_ERR(tfm);
+
+	ret = sgx_get_key_hash(tfm, modulus, hash);
+
+	crypto_free_shash(tfm);
+	return ret;
+}
Signature · 1 line
2.14.1
#59 lore raw

RE: [PATCH v6 10/11] intel_sgx: glue code for in-kernel LE

On Sat, Nov 25, 2017 at 09:29:27PM +0200, Jarkko Sakkinen wrote:
+static int __sgx_le_get_token(struct sgx_le_ctx *ctx,

+			      const struct sgx_encl *encl,
+			      const struct sgx_sigstruct *sigstruct,
+			      struct sgx_einittoken *token)

+{
+ u8 mrsigner[32];
+ ssize_t ret;
+
+ if (!ctx->tgid)
+ return -EIO;
+
+ ret = sgx_get_key_hash(ctx->tfm, sigstruct->modulus, mrsigner);
+ if (ret)
+ return ret;
+
+ if (!memcmp(mrsigner, sgx_le_pubkeyhash, 32))
+ return 0;

Not sure what other code would need to be juggled to make it happen, but checking the enclave's signer against sgx_le_pubkeyhash needs to be moved outside of the sgx_le_ctx mutex, e.g. to sgx_le_get_token. Deadlocks can occur because the kernel's LE uses the same EINIT flow as normal enclaves. If a userspace enclave is created immediately after opening /dev/sgx it can race with the LE to acquire the lock. If the userspace enclave wins, it will block indefinitely waiting for the LE to generate the token, while the LE is blocked waiting for the lock.

This bug is trivial to reproduce on a single threaded system/VM.

Hung task trace for the in-kernel enclave:

[  484.330510] INFO: task 3:972 blocked for more than 120 seconds.
[  484.331111]       Not tainted 4.14.0+ #21
[  484.331507] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[  484.332244] 3               D    0   972      2 0x00000000
[  484.332248] Call Trace:
[  484.332265]  __schedule+0x3c2/0x890
[  484.332267]  schedule+0x36/0x80
[  484.332268]  schedule_preempt_disabled+0xe/0x10
[  484.332269]  __mutex_lock.isra.2+0x2b1/0x4e0
[  484.332274]  __mutex_lock_slowpath+0x13/0x20
[  484.332276]  mutex_lock+0x2f/0x40
[  484.332278]  sgx_le_get_token+0x3e/0x166 [intel_sgx]
[  484.332282]  sgx_ioc_enclave_init+0xd2/0x120 [intel_sgx]
[  484.332283]  sgx_ioctl+0xdc/0x180 [intel_sgx]
[  484.332306]  do_vfs_ioctl+0xa1/0x5e0
[  484.332308]  SyS_ioctl+0x79/0x90
[  484.332310]  entry_SYSCALL_64_fastpath+0x1e/0xa9

+
+ ret = sgx_le_write(ctx->pipes[0], sigstruct->body.mrenclave, 32);
+ if (ret)
+ return ret;
+
+ ret = sgx_le_write(ctx->pipes[0], mrsigner, 32);
+ if (ret)
+ return ret;
+
+ ret = sgx_le_write(ctx->pipes[0], &encl->attributes, sizeof(uint64_t));
+ if (ret)
+ return ret;
+
+ ret = sgx_le_write(ctx->pipes[0], &encl->xfrm, sizeof(uint64_t));
+ if (ret)
+ return ret;
+
+ return sgx_le_read(ctx->pipes[1], token, sizeof(*token));
+}
+
+int sgx_le_get_token(struct sgx_le_ctx *ctx,

+		     const struct sgx_encl *encl,
+		     const struct sgx_sigstruct *sigstruct,
+		     struct sgx_einittoken *token)

+{
+ int ret;
+
+ mutex_lock(&ctx->lock);
+ ret = __sgx_le_get_token(ctx, encl, sigstruct, token);
+ mutex_unlock(&ctx->lock);
+
+ return ret;
+}

#60 lore raw

PATCH v6 11/11 intel_sgx: driver documentation

In reply to Jarkko Sakkinen
---
 Documentation/index.rst         |   1 +
 Documentation/x86/intel_sgx.rst | 101 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100644 Documentation/x86/intel_sgx.rst
Documentation/index.rst +1 -0
index cb7f1ba5b3b1..ccfebc260e04 100644
@@ -86,6 +86,7 @@ implementation.
    :maxdepth: 2
 
    sh/index
+   x86/index
 
 Korean translations
 -------------------
Documentation/x86/intel_sgx.rst new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.14.1
#61 lore raw
In reply to Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen

Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. In a way you can think that SGX provides inverted sandbox. It protects the application from a malicious host.

Would you list guarantees provided by SGX?

For example, host can still observe timing of cachelines being accessed by "protected" app, right? Can it also introduce bit flips?

Pavel

#62 lore raw
Quoted 7 lines · Pavel Machek
Quoted 5 lines · Jarkko Sakkinen

Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. In a way you can think that SGX provides inverted sandbox. It protects the application from a malicious host.

Quoted 6 lines

Would you list guarantees provided by SGX?

For example, host can still observe timing of cachelines being accessed by "protected" app, right? Can it also introduce bit flips?

Pavel

I'll put this in my backlog. Thank you.

/Jarkko

#63 lore raw
In reply to Pavel Machek
Quoted 7 lines · Pavel Machek
Quoted 5 lines · Jarkko Sakkinen

Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. In a way you can think that SGX provides inverted sandbox. It protects the application from a malicious host.

Quoted 6 lines

Would you list guarantees provided by SGX?

For example, host can still observe timing of cachelines being accessed by "protected" app, right? Can it also introduce bit flips?

Pavel

I'll give a more proper response to this now that all the reported major issues in the code have been fixed in v9.

Yes, SGX is vulnerable to the L1 cacheline timing attacks. Jethro Beekman wrote a great summary about this on early March:

https://jbeekman.nl/blog/2017/03/sgx-side-channel-attacks/

The counter measures are the same as without SGX. It really does not add or degrade security in this area.

/Jarkko

#64 lore raw
Quoted 18 lines · Jarkko Sakkinen
Quoted 7 lines · Pavel Machek
Quoted 5 lines · Jarkko Sakkinen

Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. In a way you can think that SGX provides inverted sandbox. It protects the application from a malicious host.

Quoted 6 lines

Would you list guarantees provided by SGX?

For example, host can still observe timing of cachelines being accessed by "protected" app, right? Can it also introduce bit flips?

Pavel

I'll give a more proper response to this now that all the reported major issues in the code have been fixed in v9.

Quoted 7 lines

Yes, SGX is vulnerable to the L1 cacheline timing attacks. Jethro Beekman wrote a great summary about this on early March:

https://jbeekman.nl/blog/2017/03/sgx-side-channel-attacks/

The counter measures are the same as without SGX. It really does not add or degrade security in this area.

This came up even in my patch set :-) I.e. I switched to kernel AES-NI from TinyCrypt's AES because the latter is not timing resistant.

/Jarkko

#65 lore raw
In reply to Jarkko Sakkinen

So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

Ced

Quoted 222 lines · Jarkko Sakkinen

Intel(R) SGX is a set of CPU instructions that can be used by applications to set aside private regions of code and data. The code outside the enclave is disallowed to access the memory inside the enclave by the CPU access control. In a way you can think that SGX provides inverted sandbox. It protects the application from a malicious host.

There is a new hardware unit in the processor called Memory Encryption Engine (MEE) starting from the Skylake microacrhitecture. BIOS can define one or many MEE regions that can hold enclave data by configuring them with PRMRR registers.

The MEE automatically encrypts the data leaving the processor package to the MEE regions. The data is encrypted using a random key whose life-time is exactly one power cycle.

You can tell if your CPU supports SGX by looking into /proc/cpuinfo:

cat /proc/cpuinfo | grep sgx

The GIT repositoy for SGX driver resides in

https://github.com/jsakkine-intel/linux-sgx.git

'le' branch contains the upstream candidate patches.

'master' branch contains the same patches with the following differences:

* top-level patch modifies the ioctl API to be SDK compatible
* does not use flexible launch control but instead relies on SDK provided Intel launch enclave.

Backlog:
* AES: how to use arch/x86/crypto/aesni-intel_asm.S from the enclave. I guess these routines should be fairly easy to call directly (haven't investigated deeply). Any advice is appreciated.
* Layout: what and where to place in arch/x86.
* MAINTAINERS: who to add as reviewer.

v6
* Fixed semaphore underrun when accessing /dev/sgx from the launch enclave.
* In sgx_encl_create() s/IS_ERR(secs)/IS_ERR(encl)/.
* Removed virtualization chapter from the documentation.
* Changed the default filename for the signing key as signing_key.pem.
* Reworked EPC management in a way that instead of a linked list of struct sgx_epc_page instances there is an array of integers that encodes address and bank of an EPC page (the same data as 'pa' field earlier). The locking has been moved to the EPC bank level instead of a global lock.
* Relaxed locking requirements for EPC management. EPC pages can be released back to the EPC bank concurrently.
* Cleaned up ptrace() code.
* Refined commit messages for new architectural constants.
* Sorted includes in every source file.
* Sorted local variable declarations according to the line length in every function.
* Style fixes based on Darren's comments to sgx_le.c.

v5:
* Described IPC between the Launch Enclave and kernel in the commit messages.
* Fixed all relevant checkpatch.pl issues that I have forgot fix in earlier versions except those that exist in the imported TinyCrypt code.
* Fixed spelling mistakes in the documentation.
* Forgot to check the return value of sgx_drv_subsys_init().
* Encapsulated properly page cache init and teardown.
* Collect epc pages to a temp list in sgx_add_epc_bank
* Removed SGX_ENCLAVE_INIT_ARCH constant.

v4:
* Tied life-cycle of the sgx_le_proxy process to /dev/sgx.
* Removed __exit annotation from sgx_drv_subsys_exit().
* Fixed a leak of a backing page in sgx_process_add_page_req() in the case when vm_insert_pfn() fails.
* Removed unused symbol exports for sgx_page_cache.c.
* Updated sgx_alloc_page() to require encl parameter and documented the behavior (Sean Christopherson).
* Refactored a more lean API for sgx_encl_find() and documented the behavior.
* Moved #PF handler to sgx_fault.c.
* Replaced subsys_system_register() with plain bus_register().
* Retry EINIT 2nd time only if MSRs are not locked.

v3:
* Check that FEATURE_CONTROL_LOCKED and FEATURE_CONTROL_SGX_ENABLE are set.
* Return -ERESTARTSYS in __sgx_encl_add_page() when sgx_alloc_page() fails.
* Use unused bits in epc_page->pa to store the bank number.
* Removed #ifdef for WQ_NONREENTRANT.
* If mmu_notifier_register() fails with -EINTR, return -ERESTARTSYS.
* Added --remove-section=.got.plt to objcopy flags in order to prevent a dummy .got.plt, which will cause an inconsistent size for the LE.
* Documented sgx_encl_* functions.
* Added remark about AES implementation used inside the LE.
* Removed redundant sgx_sys_exit() from le/main.c.
* Fixed struct sgx_secinfo alignment from 128 to 64 bytes.
* Validate miscselect in sgx_encl_create().
* Fixed SSA frame size calculation to take the misc region into account.
* Implemented consistent exception handling to __encls() and __encls_ret().
* Implemented a proper device model in order to allow sysfs attributes and in-kernel API.
* Cleaned up various "find enclave" implementations to the unified sgx_encl_find().
* Validate that vm_pgoff is zero.
* Discard backing pages with shmem_truncate_range() after EADD.
* Added missing EEXTEND operations to LE signing and launch.
* Fixed SSA size for GPRS region from 168 to 184 bytes.
* Fixed the checks for TCS flags. Now DBGOPTIN is allowed.
* Check that TCS addresses are in ELRANGE and not just page aligned.
* Require kernel to be compiled with X64_64 and CPU_SUP_INTEL.
* Fixed an incorrect value for SGX_ATTR_DEBUG from 0x01 to 0x02.

v2:
* get_rand_uint32() changed the value of the pointer instead of value where it is pointing at.
* Launch enclave incorrectly used sigstruct attributes-field instead of enclave attributes-field.
* Removed unused struct sgx_add_page_req from sgx_ioctl.c
* Removed unused sgx_has_sgx2.
* Updated arch/x86/include/asm/sgx.h so that it provides stub implementations when sgx in not enabled.
* Removed cruft rdmsr-calls from sgx_set_pubkeyhash_msrs().
* return -ENOMEM in sgx_alloc_page() when VA pages consume too much space
* removed unused global sgx_nr_pids
* moved sgx_encl_release to sgx_encl.c
* return -ERESTARTSYS instead of -EINTR in sgx_encl_init()

Haim Cohen (1):
x86: add SGX MSRs to msr-index.h

Jarkko Sakkinen (8):
intel_sgx: updated MAINTAINERS
x86: define IA32_FEATUE_CONTROL.SGX_LC
intel_sgx: driver for Intel Software Guard Extensions
intel_sgx: ptrace() support
intel_sgx: in-kernel launch enclave fs/pipe.c: export create_pipe_files() and replace_fd()
intel_sgx: glue code for in-kernel LE
intel_sgx: driver documentation

Kai Huang (1):
x86: add SGX definition to cpufeature

Sean Christopherson (1):
x86: define IA32_FEATURE_CONTROL.SGX_ENABLE

 Documentation/index.rst                            |   1 +
 Documentation/x86/intel_sgx.rst                    | 101 +++
 MAINTAINERS                                        |   5 +
 arch/x86/include/asm/cpufeatures.h                 |   2 +
 arch/x86/include/asm/msr-index.h                   |   8 +
 arch/x86/include/asm/sgx.h                         | 233 +++++
 arch/x86/include/asm/sgx_arch.h                    | 268 ++++++
 arch/x86/include/uapi/asm/sgx.h                    | 138 +++
 drivers/platform/x86/Kconfig                       |   2 +
 drivers/platform/x86/Makefile                      |   1 +
 drivers/platform/x86/intel_sgx/Kconfig             |  34 +
 drivers/platform/x86/intel_sgx/Makefile            |  32 +
 drivers/platform/x86/intel_sgx/le/Makefile         |  26 +
 drivers/platform/x86/intel_sgx/le/enclave/Makefile |  46 +
 .../x86/intel_sgx/le/enclave/aes_encrypt.c         | 191 ++++
 .../platform/x86/intel_sgx/le/enclave/cmac_mode.c  | 254 ++++++
 .../x86/intel_sgx/le/enclave/encl_bootstrap.S      | 163 ++++
 .../intel_sgx/le/enclave/include/tinycrypt/aes.h   | 133 +++
 .../le/enclave/include/tinycrypt/cmac_mode.h       | 194 ++++
 .../le/enclave/include/tinycrypt/constants.h       |  59 ++
 .../intel_sgx/le/enclave/include/tinycrypt/utils.h |  95 ++
 drivers/platform/x86/intel_sgx/le/enclave/main.c   | 203 +++++
 .../platform/x86/intel_sgx/le/enclave/sgx_le.lds   |  28 +
 .../platform/x86/intel_sgx/le/enclave/sgxsign.c    | 538 +++++++++++
 drivers/platform/x86/intel_sgx/le/enclave/utils.c  |  78 ++
 drivers/platform/x86/intel_sgx/le/entry.S          | 117 +++
 .../platform/x86/intel_sgx/le/include/sgx_asm.h    |  64 ++
 .../platform/x86/intel_sgx/le/include/sgx_encl.h   | 110 +++
 drivers/platform/x86/intel_sgx/le/main.c           | 214 +++++
 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S   |  15 +
 drivers/platform/x86/intel_sgx/sgx.h               | 268 ++++++
 drivers/platform/x86/intel_sgx/sgx_encl.c          | 999 +++++++++++++++++++++
 drivers/platform/x86/intel_sgx/sgx_ioctl.c         | 282 ++++++
 drivers/platform/x86/intel_sgx/sgx_le.c            | 319 +++++++
 .../platform/x86/intel_sgx/sgx_le_proxy_piggy.S    |  15 +
 drivers/platform/x86/intel_sgx/sgx_main.c          | 456 ++++++++++
 drivers/platform/x86/intel_sgx/sgx_page_cache.c    | 619 +++++++++++++
 drivers/platform/x86/intel_sgx/sgx_util.c          | 394 ++++++++
 drivers/platform/x86/intel_sgx/sgx_vma.c           | 236 +++++
 fs/file.c                                          |   1 +
 fs/pipe.c                                          |   1 +
 41 files changed, 6943 insertions(+)
 create mode 100644 Documentation/x86/intel_sgx.rst
 create mode 100644 arch/x86/include/asm/sgx.h
 create mode 100644 arch/x86/include/asm/sgx_arch.h
 create mode 100644 arch/x86/include/uapi/asm/sgx.h
 create mode 100644 drivers/platform/x86/intel_sgx/Kconfig
 create mode 100644 drivers/platform/x86/intel_sgx/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/Makefile
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/aes_encrypt.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/encl_bootstrap.S
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/aes.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/cmac_mode.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/constants.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/include/tinycrypt/utils.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/sgx_le.lds
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/sgxsign.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/utils.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/entry.S
 create mode 100644 drivers/platform/x86/intel_sgx/le/include/sgx_asm.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/include/sgx_encl.h
 create mode 100644 drivers/platform/x86/intel_sgx/le/main.c
 create mode 100644 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S
 create mode 100644 drivers/platform/x86/intel_sgx/sgx.h
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_encl.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_ioctl.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_le.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_le_proxy_piggy.S
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_main.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_page_cache.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_util.c
 create mode 100644 drivers/platform/x86/intel_sgx/sgx_vma.c

--
2.14.1

Signature · 3 lines
Cedric Blancher <[email protected]>
[https://plus.google.com/u/0/+CedricBlancher/]
Institute Pasteur
#66 lore raw
Quoted 2 lines · Cedric Blancher

So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

It has nothing to do with it at all, sorry.

greg k-h

#67 lore raw

04.01.2018, 17:30, "Greg Kroah-Hartman" <[email protected]>:

Quoted 3 lines · Cedric Blancher
Quoted 2 lines

 So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

Hello,

I think this exploit work Intel x64 and only Debian/Redhat/Suse distributions. The read function was in effect terminating the memory in kernel space.

All distributions teams are published to updates, please keeps up-to-date.

Ozgur

Quoted 3 lines

It has nothing to do with it at all, sorry.

greg k-h

#68 lore raw
In reply to Cedric Blancher
Quoted 2 lines · Cedric Blancher

So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

Actually, a data exfiltration attack against SGX, using page tables has already been documented:

https://www.usenix.org/conference/usenixsecurity17/technical-sessions/presentation/van-bulck

It doesn't exploit speculation as the mechanism for gathering data (it exploits page faults), but the structure of the side channel attack used to exfiltrate data from the supposedly secure enclave is very similar to Spectre.  The targetting mechanism is very different,
though: the page table exploit assumes you can control the page tables, so you must be highly privileged on the platform but with Spectre you merely have to be an ordinary user.

James

#69 lore raw
In reply to Cedric Blancher
Quoted 4 lines · Cedric Blancher

So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

Ced

Everything going out of L1 gets encrypted. This is done to defend against peripheral like adversaries and should work also against meltdown.

/Jarkko

#70 lore raw
Quoted 9 lines · Jarkko Sakkinen
Quoted 4 lines · Cedric Blancher

So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

Ced

Everything going out of L1 gets encrypted. This is done to defend against peripheral like adversaries and should work also against meltdown.

Yeah, but useless against spectre and ability to introduce bit flips means this is generally useless...

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#71 lore raw
Quoted 5 lines · Pavel Machek
Quoted 4 lines · Jarkko Sakkinen
Quoted 3 lines · Cedric Blancher

So how does this protect against the MELTDOWN attack (CVE-2017-5754) and the MELTATOMBOMBA4 worm which uses this exploit?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Ced

Everything going out of L1 gets encrypted. This is done to defend against peripheral like adversaries and should work also against meltdown.

Yeah, but useless against spectre and ability to introduce bit flips means this is generally useless...

You are right.

And what I said was simply false. In fact, the encryption is done in LCC. I'm sorry that I didn't response to my response and gave incorrect info. I simply forgot to do this, no other excuses.

/Jarkko