Skip to content

Commit

Permalink
Merge pull request #24 from alexthomas1/merger
Browse files Browse the repository at this point in the history
User hash and no dev/mem
  • Loading branch information
dayeol authored Jun 26, 2019
2 parents 2a747c3 + bf48d6c commit 6b24cbf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions keystone-enclave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
18 changes: 15 additions & 3 deletions keystone-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "keystone-sbi-arg.h"
#include "keystone_user.h"
#include <linux/uaccess.h>
#include <keystone_user.h>

int __keystone_destroy_enclave(unsigned int ueid);

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
29 changes: 22 additions & 7 deletions keystone.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,38 @@ 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);
if(!enclave) {
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;
}

Expand Down
1 change: 1 addition & 0 deletions keystone.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct enclave
int close_on_pexit;
struct utm* utm;
struct epm* epm;
bool is_init;
};


Expand Down
13 changes: 11 additions & 2 deletions keystone_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 6b24cbf

Please sign in to comment.