diff --git a/keystone-enclave.c b/keystone-enclave.c index 2e02aa19f..61ff1ae27 100644 --- a/keystone-enclave.c +++ b/keystone-enclave.c @@ -69,6 +69,7 @@ struct enclave* create_enclave(unsigned long min_pages) enclave->close_on_pexit = 1; enclave->epm = kmalloc(sizeof(struct epm), GFP_KERNEL); + enclave->is_init = true; if (!enclave->epm) { keystone_err("failed to allocate epm\n"); diff --git a/keystone-ioctl.c b/keystone-ioctl.c index 453f50199..cddbc9925 100644 --- a/keystone-ioctl.c +++ b/keystone-ioctl.c @@ -6,6 +6,7 @@ #include "keystone-sbi-arg.h" #include "keystone_user.h" #include +#include int __keystone_destroy_enclave(unsigned int ueid); @@ -23,7 +24,7 @@ int keystone_create_enclave(struct file *filep, unsigned long arg) /* Pass base page table */ enclp->pt_ptr = __pa(enclave->epm->root_page_table); - enclp->size = enclave->epm->size; + enclp->epm_size = enclave->epm->size; /* allocate UID */ enclp->eid = enclave_idr_alloc(enclave); @@ -49,6 +50,8 @@ int keystone_finalize_enclave(unsigned long arg) return -EINVAL; } + enclave->is_init = false; + /* SBI Call */ create_args.epm_region.paddr = enclave->epm->pa; create_args.epm_region.size = enclave->epm->size; @@ -66,7 +69,15 @@ int keystone_finalize_enclave(unsigned long arg) // physical addresses for runtime, user, and freemem create_args.runtime_paddr = epm_va_to_pa(enclave->epm, enclp->runtime_vaddr); create_args.user_paddr = epm_va_to_pa(enclave->epm, enclp->user_vaddr); - create_args.free_paddr = enclp->free_ptr; + create_args.free_paddr = enclp->free_paddr; + + enclp->runtime_paddr = create_args.runtime_paddr; + enclp->user_paddr = create_args.user_paddr; + enclp->epm_paddr = create_args.epm_region.paddr; + enclp->utm_paddr = create_args.utm_region.paddr; + enclp->epm_size = create_args.epm_region.size; + enclp->utm_size = create_args.utm_region.size; + create_args.params = enclp->params; @@ -208,7 +219,8 @@ int keystone_resume_enclave(unsigned long arg) long keystone_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) { long ret; - char data[272]; + char data[512]; + size_t ioc_size; if (!arg) diff --git a/keystone.c b/keystone.c index 88322ed0d..8b17a2ce4 100644 --- a/keystone.c +++ b/keystone.c @@ -45,6 +45,7 @@ void keystone_handle_interrupts(void) int keystone_mmap(struct file* filp, struct vm_area_struct *vma) { struct utm* utm; + struct epm* epm; struct enclave* enclave; unsigned long vsize, psize; enclave = get_enclave_by_id((unsigned long) filp->private_data); @@ -52,16 +53,30 @@ int keystone_mmap(struct file* filp, struct vm_area_struct *vma) keystone_err("invalid enclave id\n"); return -EINVAL; } + utm = enclave->utm; + epm = enclave->epm; vsize = vma->vm_end - vma->vm_start; - psize = utm->size; - if (vsize > psize) - return -EINVAL; - remap_pfn_range(vma, - vma->vm_start, - __pa(utm->ptr) >> PAGE_SHIFT, - vsize, vma->vm_page_prot); + if(enclave->is_init){ + if (vsize > PAGE_SIZE) + return -EINVAL; + vaddr_t paddr = __pa(epm->root_page_table) + (vma->vm_pgoff << PAGE_SHIFT); + remap_pfn_range(vma, + vma->vm_start, + paddr >> PAGE_SHIFT, + vsize, vma->vm_page_prot); + } + else + { + psize = utm->size; + if (vsize > psize) + return -EINVAL; + remap_pfn_range(vma, + vma->vm_start, + __pa(utm->ptr) >> PAGE_SHIFT, + vsize, vma->vm_page_prot); + } return 0; } diff --git a/keystone.h b/keystone.h index 1b8b4640b..a09b94191 100644 --- a/keystone.h +++ b/keystone.h @@ -86,6 +86,7 @@ struct enclave int close_on_pexit; struct utm* utm; struct epm* epm; + bool is_init; }; diff --git a/keystone_user.h b/keystone_user.h index 9eff218df..57cf38488 100644 --- a/keystone_user.h +++ b/keystone_user.h @@ -49,9 +49,18 @@ struct keystone_ioctl_create_enclave { __u64 user_vaddr; __u64 pt_ptr; - __u64 free_ptr; __u64 utm_free_ptr; - __u64 size; + + //Used for hash + __u64 epm_paddr; + __u64 utm_paddr; + __u64 runtime_paddr; + __u64 user_paddr; + __u64 free_paddr; + + __u64 epm_size; + __u64 utm_size; + // Runtime Parameters struct runtime_params_t params; };