Intel SGX Driver
Subsystems (5)
v8 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.
v8:
* Check that public key MSRs match the LE public key hash in the driver initialization when the MSRs are read-only.
* Fix the race in VA slot allocation by checking the fullness immediately after succeesful allocation.
* Fix the race in hash mrsigner calculation between the launch enclave and user enclaves by having a separate lock for hash calculation.
v7:
* Fixed offset calculation in sgx_edbgr/wr(). Address was masked with PAGE_MASK when it should have been masked with ~PAGE_MASK.
* Fixed a memory leak in sgx_ioc_enclave_create().
* Simplified swapping code by using a pointer array for a cluster instead of a linked list.
* Squeezed struct sgx_encl_page to 32 bytes.
* Fixed deferencing of an RSA key on OpenSSL 1.1.0.
* Modified TC's CMAC to use kernel AES-NI. Restructured the code
a bit in order to better align with kernel conventions.
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()
Jarkko Sakkinen (6):
intel_sgx: updated MAINTAINERS
intel_sgx: driver for Intel Software Guard Extensions
intel_sgx: ptrace() support
intel_sgx: driver documentation
fs/pipe.c: export create_pipe_files()
intel_sgx: in-kernel launch enclave
Kai Huang (1):
x86: add SGX definitions to cpufeature
Sean Christopherson (1):
x86: add SGX definitions to msr-index.h
Documentation/index.rst | 1 + Documentation/x86/intel_sgx.rst | 101 +++ MAINTAINERS | 7 + arch/x86/include/asm/cpufeatures.h | 2 + arch/x86/include/asm/msr-index.h | 8 + arch/x86/include/asm/sgx.h | 245 +++++ arch/x86/include/asm/sgx_arch.h | 270 ++++++ 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 | 27 + drivers/platform/x86/intel_sgx/le/enclave/Makefile | 46 + .../x86/intel_sgx/le/enclave/aesni-intel_asm.S | 1 + .../platform/x86/intel_sgx/le/enclave/cmac_mode.c | 258 ++++++ .../platform/x86/intel_sgx/le/enclave/cmac_mode.h | 103 +++ .../x86/intel_sgx/le/enclave/encl_bootstrap.S | 163 ++++ drivers/platform/x86/intel_sgx/le/enclave/main.c | 193 ++++ drivers/platform/x86/intel_sgx/le/enclave/main.h | 66 ++ .../platform/x86/intel_sgx/le/enclave/sgx_le.lds | 28 + .../platform/x86/intel_sgx/le/enclave/sgxsign.c | 551 ++++++++++++ drivers/platform/x86/intel_sgx/le/enclave/string.c | 1 + drivers/platform/x86/intel_sgx/le/entry.S | 117 +++ .../platform/x86/intel_sgx/le/include/sgx_asm.h | 64 ++ drivers/platform/x86/intel_sgx/le/main.c | 186 ++++ drivers/platform/x86/intel_sgx/le/main.h | 78 ++ drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S | 15 + drivers/platform/x86/intel_sgx/le/string.c | 77 ++ drivers/platform/x86/intel_sgx/sgx.h | 283 ++++++ drivers/platform/x86/intel_sgx/sgx_encl.c | 992 +++++++++++++++++++++ drivers/platform/x86/intel_sgx/sgx_ioctl.c | 283 ++++++ drivers/platform/x86/intel_sgx/sgx_le.c | 307 +++++++ .../platform/x86/intel_sgx/sgx_le_proxy_piggy.S | 15 + drivers/platform/x86/intel_sgx/sgx_main.c | 483 ++++++++++ drivers/platform/x86/intel_sgx/sgx_page_cache.c | 642 +++++++++++++ drivers/platform/x86/intel_sgx/sgx_util.c | 372 ++++++++ drivers/platform/x86/intel_sgx/sgx_vma.c | 236 +++++ fs/pipe.c | 1 + 39 files changed, 6429 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 120000 drivers/platform/x86/intel_sgx/le/enclave/aesni-intel_asm.S create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.h create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/encl_bootstrap.S create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.c create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.h 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 120000 drivers/platform/x86/intel_sgx/le/enclave/string.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/main.c create mode 100644 drivers/platform/x86/intel_sgx/le/main.h create mode 100644 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S create mode 100644 drivers/platform/x86/intel_sgx/le/string.c 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
PATCH v8 1/8 intel_sgx: updated MAINTAINERS
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -7237,6 +7237,13 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-intel-mid.c +INTEL SGX +M: Jarkko Sakkinen <[email protected]> +L: [email protected] +Q: https://patchwork.kernel.org/project/intel-sgx/list/ +F: drivers/platform/x86/intel_sgx/ +K: \bSGX_ + INVENSENSE MPU-3050 GYROSCOPE DRIVER M: Linus Walleij <[email protected]> L: [email protected]
Signature · 1 line
2.14.1
PATCH v8 2/8 x86: add SGX definitions to cpufeature
In reply to Jarkko SakkinenFrom: Kai Huang <[email protected]>
Added X86_FEATURE_SGX and X86_FEATURE_SGX_LC definitions that define the bits CPUID level 7 bits for determining whether the CPU supports SGX and launch configuration other than the Intel proprietary key. If this the case, IA32_SGXLEPUBKEYHASHn MSRs (0 < n < 4) are available for defining the root key for enclaves.
--- arch/x86/include/asm/cpufeatures.h | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -223,6 +223,7 @@/* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0)/* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE 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 */
@@ -308,6 +309,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
PATCH v8 3/8 x86: add SGX definitions to msr-index.h
In reply to Jarkko SakkinenFrom: Sean Christopherson <[email protected]>
ENCLS and ENCLU are usable if and only if SGX_ENABLE is set and After SGX is activated the IA32_SGXLEPUBKEYHASHn MSRs are writable if SGX_LC_WR is set and the feature control is locked.
SGX related bits in IA32_FEATURE_CONTROL cannot be set before SGX is activated by the pre-boot firmware. SGX activation is triggered by setting bit 0 in the MSR 0x7a. Until SGX is activated, the LE hash MSRs are writable to allow pre-boot firmware to lock down the LE root key with a non-Intel value.
--- arch/x86/include/asm/msr-index.h | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/include/asm/msr-index.h +8 -0
@@ -439,6 +439,8 @@#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_SGX_LE_WR (1<<17)#define FEATURE_CONTROL_LMCE (1<<20)#define MSR_IA32_APICBASE 0x0000001b
@@ -505,6 +507,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
PATCH v8 4/8 intel_sgx: driver for Intel Software Guard Extensions
In reply to Jarkko SakkinenIntel 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 | 270 +++++++ 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 | 259 +++++++ drivers/platform/x86/intel_sgx/sgx_encl.c | 974 ++++++++++++++++++++++++ drivers/platform/x86/intel_sgx/sgx_ioctl.c | 281 +++++++ drivers/platform/x86/intel_sgx/sgx_main.c | 413 ++++++++++ drivers/platform/x86/intel_sgx/sgx_page_cache.c | 642 ++++++++++++++++ drivers/platform/x86/intel_sgx/sgx_util.c | 347 +++++++++ drivers/platform/x86/intel_sgx/sgx_vma.c | 117 +++ 14 files changed, 3709 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
@@ -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 (void *epc) +{ +unsigned long rbx =0 ; +unsigned long rdx =0 ; + +return __encls_ret (EBLOCK , rbx, epc, 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 +270 -0
270 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
@@ -1170,6 +1170,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
@@ -88,3 +88,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
@@ -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
@@ -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 +259 -0
259 lines not on this page · raw message
drivers/platform/x86/intel_sgx/sgx_encl.c new file +974 -0
974 lines not on this page · raw message
drivers/platform/x86/intel_sgx/sgx_ioctl.c new file +281 -0
281 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 +642 -0
388 lines not on this page · raw message
drivers/platform/x86/intel_sgx/sgx_util.c new file +347 -0
347 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.
Re: [PATCH v8 4/8] intel_sgx: driver for Intel Software Guard Extensions
Jarkko, Suresh,
Quoted 4 lines · 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.
[...]
Quoted 2 lines
Signed-off-by Jarkko Sakkinen <[email protected]>Tested-by Serge Ayoun <[email protected]>
[...]
Quoted 49 lines
arch/x86/include/asm/sgx.h new file +46
-0@@ -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,
arch/x86/include/asm/sgx.h line 56
Quoted 10 lines
arch/x86/include/asm/sgx.h new file +10
-0+* 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]> +*/
Would you be kind enough to use the SPDX tags instead of this fine but super long (40+ lines) legalese? This is the new way as documented in Thomas [1] patches and already adopted by other Intel contributors.
Thank you for your kind consideration!
[1] https://lkml.org/lkml/2017/12/4/934
Signature · 2 lines
Cordially Philippe Ombredanne
PATCH v8 5/8 intel_sgx: ptrace() support
In reply to Jarkko SakkinenImplemented 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
@@ -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->desc &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->desc &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,"EDBGWR 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->desc &= ~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->desc &= ~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
PATCH v8 6/8 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
@@ -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
PATCH v8 7/8 fs/pipe.c: export create_pipe_files()
In reply to Jarkko SakkinenExported create_pipe_files() because the SGX driver needs to be able to setup pipes for communicating 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().
--- fs/pipe.c | 1 + 1 file changed, 1 insertion(+)
fs/pipe.c +1 -0
@@ -785,6 +785,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
PATCH v8 8/8 intel_sgx: in-kernel launch enclave
In reply to Jarkko SakkinenThe Launch Enclave (LE) generates cryptographic launch tokens for user enclaves. A launch token is used by EINIT to check whether the enclave is authorized to launch or not. By having its own launch enclave, Linux has full control of the enclave launch process.
LE is wrapped into a user space proxy program that reads enclave signatures outputs launch tokens. The kernel-side glue code is implemented by using the user space helper framework. Pipes are used to communicate with the LE proxy.
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/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.
The CMAC implementation has been derived from TinyCrypt. The kernel AES-NI implementation is used for AES.
[1] https://github.com/01org/tinycrypt
--- arch/x86/include/asm/sgx.h | 12 + drivers/platform/x86/intel_sgx/Kconfig | 15 + drivers/platform/x86/intel_sgx/Makefile | 19 + drivers/platform/x86/intel_sgx/le/Makefile | 27 + drivers/platform/x86/intel_sgx/le/enclave/Makefile | 46 ++ .../x86/intel_sgx/le/enclave/aesni-intel_asm.S | 1 + .../platform/x86/intel_sgx/le/enclave/cmac_mode.c | 258 ++++++++++ .../platform/x86/intel_sgx/le/enclave/cmac_mode.h | 103 ++++ .../x86/intel_sgx/le/enclave/encl_bootstrap.S | 163 ++++++ drivers/platform/x86/intel_sgx/le/enclave/main.c | 193 ++++++++ drivers/platform/x86/intel_sgx/le/enclave/main.h | 66 +++ .../platform/x86/intel_sgx/le/enclave/sgx_le.lds | 28 ++ .../platform/x86/intel_sgx/le/enclave/sgxsign.c | 551 +++++++++++++++++++++ drivers/platform/x86/intel_sgx/le/enclave/string.c | 1 + drivers/platform/x86/intel_sgx/le/entry.S | 117 +++++ .../platform/x86/intel_sgx/le/include/sgx_asm.h | 64 +++ drivers/platform/x86/intel_sgx/le/main.c | 186 +++++++ drivers/platform/x86/intel_sgx/le/main.h | 78 +++ drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S | 15 + drivers/platform/x86/intel_sgx/le/string.c | 77 +++ 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 | 307 ++++++++++++ .../platform/x86/intel_sgx/sgx_le_proxy_piggy.S | 15 + drivers/platform/x86/intel_sgx/sgx_main.c | 78 ++- drivers/platform/x86/intel_sgx/sgx_util.c | 25 + 27 files changed, 2486 insertions(+), 5 deletions(-) create mode 100644 drivers/platform/x86/intel_sgx/le/Makefile create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/Makefile create mode 120000 drivers/platform/x86/intel_sgx/le/enclave/aesni-intel_asm.S create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.h create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/encl_bootstrap.S create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.c create mode 100644 drivers/platform/x86/intel_sgx/le/enclave/main.h 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 120000 drivers/platform/x86/intel_sgx/le/enclave/string.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/main.c create mode 100644 drivers/platform/x86/intel_sgx/le/main.h create mode 100644 drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S create mode 100644 drivers/platform/x86/intel_sgx/le/string.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
arch/x86/include/asm/sgx.h +12 -0
@@ -90,6 +90,18 @@ enum sgx_commands { EMODT = 0xF, }; +#define SGX_LE_PROXY_PATH "/proc/self/fd/3" +#define SGX_LE_PROXY_FD 3 +#define SGX_LE_DEV_FD 4 + +struct sgx_launch_request { +u8 mrenclave[32 ]; +u8 mrsigner[32 ]; +uint64_t attributes; +uint64_t xfrm; +struct sgx_einittoken token; +}; +#ifdef CONFIG_X86_64 #define XAX "%%rax"#else
drivers/platform/x86/intel_sgx/Kconfig +15 -0
@@ -2,11 +2,15 @@ # Intel SGX # +menu "Intel SGX" + config INTEL_SGX tristate "Intel(R) SGX Driver" 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
@@ -17,3 +21,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 +19 -0
@@ -11,3 +11,22 @@ 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)) + +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 +27 -0
@@ -0,0 +1,27 @@ +KASAN_SANITIZE := n +OBJECT_FILES_NON_STANDARD := y +KCOV_INSTRUMENT := n +KBUILD_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fno-builtin \ + -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 string.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/aesni-intel_asm.S new file +1 -0
@@ -0,0 +1 @@ +../../../../../../arch/x86/crypto/aesni-intel_asm.S
drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.c new file +258 -0
258 lines not on this page · raw message
drivers/platform/x86/intel_sgx/le/enclave/cmac_mode.h new file +103 -0
103 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/main.c new file +193 -0
193 lines not on this page · raw message
drivers/platform/x86/intel_sgx/le/enclave/main.h new file +66 -0
66 lines not on this page · raw message
drivers/platform/x86/intel_sgx/le/enclave/sgx_le.lds new file +28 -0
@@ -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 +551 -0
551 lines not on this page · raw message
drivers/platform/x86/intel_sgx/le/enclave/string.c new file +1 -0
@@ -0,0 +1 @@ +../string.c
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/main.c new file +186 -0
186 lines not on this page · raw message
drivers/platform/x86/intel_sgx/le/main.h new file +78 -0
78 lines not on this page · raw message
drivers/platform/x86/intel_sgx/le/sgx_le_piggy.S new file +15 -0
@@ -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/le/string.c new file +77 -0
77 lines not on this page · raw message
drivers/platform/x86/intel_sgx/sgx.h +24 -0
@@ -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>
@@ -178,13 +181,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, ...) \
@@ -244,6 +253,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;
@@ -256,4 +268,16 @@ void sgx_free_page(void *page, struct sgx_encl *encl);void *sgx_get_page (void *page);void sgx_put_page (void *ptr); +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
@@ -860,6 +860,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 *
@@ -895,6 +903,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
@@ -235,7 +235,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 +307 -0
307 lines not on this page · raw message
drivers/platform/x86/intel_sgx/sgx_le_proxy_piggy.S new file +15 -0
@@ -0,0 +1,15 @@ +#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) + +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 +74 -4
129 lines not on this page · raw message
drivers/platform/x86/intel_sgx/sgx_util.c +25 -0
@@ -345,3 +345,28 @@ struct sgx_encl_page *sgx_fault_page(struct vm_area_struct *vma,return entry; } + +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