x86/sgx: Adding eextend ioctl
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH RESEND 1/3 x86/sgx: Adding eextend ioctl
The current sgx driver can only launch enclaves that always measure 4K pages. That may not necessarily be the case. This patch adds an ioctl to enable users to add the enclave measurement per 256 byte.
--- arch/x86/include/uapi/asm/sgx.h | 11 ++++++ arch/x86/kernel/cpu/sgx/ioctl.c | 81 +++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 11 deletions(-)
arch/x86/include/uapi/asm/sgx.h +11 -0
@@ -27,6 +27,8 @@ enum sgx_page_flags { _IOW(SGX_MAGIC, 0x02, struct sgx_enclave_init)#define SGX_IOC_ENCLAVE_PROVISION \ _IOW(SGX_MAGIC, 0x03, struct sgx_enclave_provision) +#define SGX_IOC_ENCLAVE_EXTEND \ + _IOW(SGX_MAGIC, 0x04, struct sgx_enclave_extend)/** * struct sgx_enclave_create - parameter structure for the
@@ -57,6 +59,15 @@ struct sgx_enclave_add_pages { };/** +* struct sgx_enclave_extend - parameter structure for the +* %SGX_IOC_ENCLAVE_MEASURE ioctl +* @offset: offset of the data from the start address for the data +*/ +struct sgx_enclave_extend { +__u64 offset; +}; + +/** * struct sgx_enclave_init - parameter structure for the * %SGX_IOC_ENCLAVE_INIT ioctl * @sigstruct: address for the SIGSTRUCT data
arch/x86/kernel/cpu/sgx/ioctl.c +70 -11
115 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH RESEND 2/3 x86/sgx: Fix compatibility issue with OPENSSL < 1.1.0
In reply to a message not in the archiveThe RSA_get0_key function only got introduced in OpenSSL 1.1.0. This makes compilation fail with older versions.
--- tools/testing/selftests/sgx/sigstruct.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/sgx/sigstruct.c +4 -1
@@ -128,8 +128,11 @@ static bool check_crypto_errors(void)static inline const BIGNUM *get_modulus (RSA *key) {const BIGNUM *n; - +#if OPENSSL_VERSION_NUMBER >=0x10100000L RSA_get0_key (key, &n,NULL ,NULL ); +#else + n = key->n; +#endif return n; }
Signature · 1 line
2.7.4
PATCH RESEND 3/3 x86/sgx: eextend ioctl selftest
In reply to a message not in the archiveIn order to test the new eextend ioctl, the SGX selftest is modified to only partially measure the last page of segments. Most segments are larger than 4k, so the MEASURE flag for SGX_IOC_ENCLAVE_ADD_PAGE is still being tested.
--- tools/testing/selftests/sgx/defines.h | 1 + tools/testing/selftests/sgx/load.c | 55 ++++++++++++++++++++++++++++----- tools/testing/selftests/sgx/main.h | 1 + tools/testing/selftests/sgx/sigstruct.c | 38 +++++++++++------------ 4 files changed, 67 insertions(+), 28 deletions(-)
tools/testing/selftests/sgx/defines.h +1 -0
@@ -10,6 +10,7 @@#define PAGE_SIZE 4096#define PAGE_MASK (~(PAGE_SIZE - 1)) +#define SGX_EEXTEND_BLOCK_SIZE 256#define __aligned (x) __attribute__((__aligned__(x)))#define __packed __attribute__((packed))
tools/testing/selftests/sgx/load.c +47 -8
89 lines not on this page · raw message
tools/testing/selftests/sgx/main.h +1 -0
@@ -34,6 +34,7 @@ void encl_delete(struct encl *ctx);bool encl_load (const char *path,struct encl *encl);bool encl_measure (struct encl *encl);bool encl_build (struct encl *encl); +uint64_t size_fit (uint64_t size_in_bytes,uint64_t block_size);int sgx_call_vdso (void *rdi,void *rsi,long rdx,u32 function,void *r8,void *r9,struct sgx_enclave_run *run);
tools/testing/selftests/sgx/sigstruct.c +18 -20
@@ -260,28 +260,25 @@ static bool mrenclave_eextend(EVP_MD_CTX *ctx, uint64_t offset, const uint8_t *data) {struct mreextend mreextend; -int i; -for (i =0 ; i <0x1000 ; i +=0x100 ) { -memset (&mreextend,0 ,sizeof (mreextend)); - mreextend.tag =MREEXTEND ; - mreextend.offset = offset + i; +memset (&mreextend,0 ,sizeof (mreextend)); + mreextend.tag =MREEXTEND ; + mreextend.offset = offset; -if (!mrenclave_update (ctx, &mreextend)) -return false; +if (!mrenclave_update (ctx, &mreextend)) +return false; -if (!mrenclave_update (ctx, &data[i +0x00 ])) -return false; +if (!mrenclave_update (ctx, &data[0x00 ])) +return false; -if (!mrenclave_update (ctx, &data[i +0x40 ])) -return false; +if (!mrenclave_update (ctx, &data[0x40 ])) +return false; -if (!mrenclave_update (ctx, &data[i +0x80 ])) -return false; +if (!mrenclave_update (ctx, &data[0x80 ])) +return false; -if (!mrenclave_update (ctx, &data[i +0xC0 ])) -return false; - } +if (!mrenclave_update (ctx, &data[0xC0 ])) +return false;return true; }
@@ -289,12 +286,13 @@ static bool mrenclave_eextend(EVP_MD_CTX *ctx, uint64_t offset,static bool mrenclave_segment (EVP_MD_CTX *ctx,struct encl *encl,struct encl_segment *seg) { -uint64_t end = seg->offset + seg->size; +uint64_t end = seg->offset +size_fit (seg->size,SGX_EEXTEND_BLOCK_SIZE );uint64_t offset; -for (offset = seg->offset; offset < end; offset +=PAGE_SIZE ) { -if (!mrenclave_eadd (ctx, offset, seg->flags)) -return false; +for (offset = seg->offset; offset < end; offset +=SGX_EEXTEND_BLOCK_SIZE ) { +if (offset %PAGE_SIZE ==0 ) +if (!mrenclave_eadd (ctx, offset, seg->flags)) +return false;if (!mrenclave_eextend (ctx, offset, encl->src + offset))return false;
Signature · 1 line
2.7.4