Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Memory Share/Mailbox Tests #60

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions examples/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ set(all_test_bins
untrusted
data-sealing)

set(complex_test_bins
message
granter
)
set(support_test_bins
receiver
grantee
)

# and (2) define the recipe of the test below:

# stack
Expand Down Expand Up @@ -58,6 +67,20 @@ target_link_libraries(attestation ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})
add_executable(untrusted untrusted/untrusted.c untrusted/edge_wrapper.c)
target_link_libraries(untrusted ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})

# mailbox
add_executable(message message/message.c message/edge_wrapper.c)
target_link_libraries(message ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})

add_executable(receiver receiver/receiver.c receiver/edge_wrapper.c)
target_link_libraries(receiver ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})

# memshare
add_executable(granter granter/granter granter/edge_wrapper.c)
target_link_libraries(granter ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})

add_executable(grantee grantee/grantee grantee/edge_wrapper.c)
target_link_libraries(grantee ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})

# data-sealing
add_executable(data-sealing data-sealing/data-sealing.c)
target_link_libraries(data-sealing ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})
Expand All @@ -72,13 +95,29 @@ foreach (test IN ITEMS ${all_test_bins})
file(APPEND ${test_script_tmp} "echo 'testing ${test}'\n")
file(APPEND ${test_script_tmp} "./${host_bin} ${test} eyrie-rt\n")
endforeach(test)

list(LENGTH complex_test_bins len1)
math(EXPR len2 "${len1} - 1")
foreach(val RANGE ${len2})
list(GET complex_test_bins ${val} val1)
list(GET support_test_bins ${val} val2)
file(APPEND ${test_script_tmp} "echo 'testing ${val1}'\n")
file(APPEND ${test_script_tmp} "./${host_bin} ${val1} eyrie-rt --eapp_two ${val2}\n")
endforeach()

file(COPY ${test_script_tmp} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/tmp)

# linker flags for all tests
set_target_properties(${all_test_bins}
PROPERTIES LINK_FLAGS "-nostdlib -static -T ${CMAKE_CURRENT_SOURCE_DIR}/app.lds")

set_target_properties(${complex_test_bins}
PROPERTIES LINK_FLAGS "-nostdlib -static -T ${CMAKE_CURRENT_SOURCE_DIR}/app.lds")

set_target_properties(${support_test_bins}
PROPERTIES LINK_FLAGS "-nostdlib -static -T ${CMAKE_CURRENT_SOURCE_DIR}/app.lds")
###############################################

# host
Expand All @@ -90,7 +129,7 @@ target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE} ${KE

set(eyrie_files_to_copy .options_log eyrie-rt)
add_eyrie_runtime(test-eyrie
"origin/master"
"origin/dev-mem-share"
${eyrie_plugins}
${eyrie_files_to_copy})

Expand All @@ -99,7 +138,7 @@ add_eyrie_runtime(test-eyrie
add_keystone_package(test-package
${package_name}
${package_script}
${test_script} ${eyrie_files_to_copy} ${all_test_bins} ${host_bin}
${test_script} ${eyrie_files_to_copy} ${all_test_bins} ${host_bin} ${complex_test_bins} ${support_test_bins}
)

add_dependencies(test-package test-eyrie)
Expand Down
38 changes: 38 additions & 0 deletions examples/tests/grantee/edge_wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#include "app/eapp_utils.h"
#include "app/string.h"
#include "app/syscall.h"
#include "edge_wrapper.h"

void edge_init(){
/* Nothing for now, will probably register buffers/callsites
later */
}

#define OCALL_PRINT_BUFFER 1
#define OCALL_PRINT_VALUE 2
#define OCALL_GET_STRING 4

void ocall_print_value(unsigned long val){

unsigned long val_ = val;
ocall(OCALL_PRINT_VALUE, &val_, sizeof(unsigned long), 0, 0);

return;
}

unsigned long ocall_print_buffer(char* data, size_t data_len){

unsigned long retval;
ocall(OCALL_PRINT_BUFFER, data, data_len, &retval ,sizeof(unsigned long));

return retval;
}

void ocall_get_string(struct edge_data* retdata){
ocall(OCALL_GET_STRING, NULL, 0, retdata, sizeof(struct edge_data));
return;
}
14 changes: 14 additions & 0 deletions examples/tests/grantee/edge_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#ifndef _EDGE_WRAPPER_H_
#define _EDGE_WRAPPER_H_
#include "edge/edge_call.h"

void edge_init();

unsigned long ocall_print_buffer(char* data, size_t data_len);
void ocall_print_value(unsigned long val);
void ocall_get_string(struct edge_data* retdata);
#endif /* _EDGE_WRAPPER_H_ */
51 changes: 51 additions & 0 deletions examples/tests/grantee/grantee.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "app/eapp_utils.h"
#include "app/syscall.h"
#include "edge_wrapper.h"
#include <string.h>

#define BUF_SIZE 256
#define EYRIE_LOAD_START 0xffffffff00000000

struct mem_share_req{
uintptr_t base_addr;
size_t enclave_size;
size_t offset;
};

void EAPP_ENTRY eapp_entry(){
char buf[BUF_SIZE];
size_t uid;
struct mem_share_req req;

get_uid(&uid);

char *ack_msg = "ACK!\n";
char *done_msg = "DONE!\n";
uintptr_t ptr = 0x700000000;
size_t *target_ptr;

edge_init();

//Listen for MEMSHARE START request from granter
while(recv_msg(uid - 1, buf, BUF_SIZE));

ocall_print_buffer("[GRANTEE] RECEIVED MEM_SHARE REQUEST\n", strlen("[GRANTEE] RECEIVED MEM_SHARE REQUEST\n") + 1);

//Sends ACK to granter
while(send_msg(uid - 1, ack_msg, strlen(ack_msg) + 1));

//Reads request from client
while(recv_msg(uid - 1, &req, sizeof(struct mem_share_req)));

//mmap req.base_addr
ptr = (uintptr_t) map(req.base_addr, req.enclave_size, ptr);

target_ptr = (size_t *) (ptr + req.offset);
*target_ptr = 1337;

mem_stop(uid - 1);

while(send_msg(uid - 1, done_msg, strlen(done_msg) + 1));

EAPP_RETURN(0);
}
38 changes: 38 additions & 0 deletions examples/tests/granter/edge_wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#include "app/eapp_utils.h"
#include "app/string.h"
#include "app/syscall.h"
#include "edge_wrapper.h"

void edge_init(){
/* Nothing for now, will probably register buffers/callsites
later */
}

#define OCALL_PRINT_BUFFER 1
#define OCALL_PRINT_VALUE 2
#define OCALL_GET_STRING 4

void ocall_print_value(unsigned long val){

unsigned long val_ = val;
ocall(OCALL_PRINT_VALUE, &val_, sizeof(unsigned long), 0, 0);

return;
}

unsigned long ocall_print_buffer(char* data, size_t data_len){

unsigned long retval;
ocall(OCALL_PRINT_BUFFER, data, data_len, &retval ,sizeof(unsigned long));

return retval;
}

void ocall_get_string(struct edge_data* retdata){
ocall(OCALL_GET_STRING, NULL, 0, retdata, sizeof(struct edge_data));
return;
}
15 changes: 15 additions & 0 deletions examples/tests/granter/edge_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#ifndef _EDGE_WRAPPER_H_
#define _EDGE_WRAPPER_H_

#include "edge/edge_call.h"

void edge_init();

unsigned long ocall_print_buffer(char* data, size_t data_len);
void ocall_print_value(unsigned long val);
void ocall_get_string(struct edge_data* retdata);
#endif /* _EDGE_WRAPPER_H_ */
56 changes: 56 additions & 0 deletions examples/tests/granter/granter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "app/eapp_utils.h"
#include "app/syscall.h"
#include "edge_wrapper.h"
#include <string.h>

#define BUF_SIZE 256

struct mem_share_req{
uintptr_t base_addr;
size_t enclave_size;
uintptr_t offset;
};

void EAPP_ENTRY eapp_entry(){
char buf[BUF_SIZE];
size_t uid;
size_t dummy_value = 5;

uintptr_t base_addr;
size_t enclave_size;

struct mem_share_req req;
req.offset = translate((uintptr_t) &dummy_value);

get_uid(&uid);

char *start_msg = "START MEMSHARE\n";

edge_init();

//Send start MEMSHARE to grantee
while(send_msg(uid + 1, start_msg, strlen(start_msg) + 1));

ocall_print_buffer("[GRANTER] MEMSHARE START\n", strlen("[GRANTER] MEMSHARE START\n") + 1);

//Receive ACK from grantee
while(recv_msg(uid + 1, buf, BUF_SIZE));

ocall_print_buffer("[GRANTER] ACK RECEIVED\n", strlen("[GRANTER] ACK RECEIVED\n"));

//Begin MEMSHARE process
mem_share(uid + 1, &base_addr, &enclave_size);

req.base_addr = base_addr;
req.enclave_size = enclave_size;
req.offset = req.offset - base_addr;

while(send_msg(uid + 1, &req, sizeof(struct mem_share_req)));

//Busy wait until grantee is finished
while(recv_msg(uid + 1, buf, BUF_SIZE));

ocall_print_value(dummy_value);

EAPP_RETURN(0);
}
39 changes: 39 additions & 0 deletions examples/tests/message/edge_wrapper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#include "app/eapp_utils.h"
#include "string.h"
#include "app/syscall.h"
#include "edge_wrapper.h"
#include "edge/edge_call.h"

void edge_init(){
/* Nothing for now, will probably register buffers/callsites
later */
}

#define OCALL_PRINT_BUFFER 1
#define OCALL_PRINT_VALUE 2
#define OCALL_GET_STRING 4

void ocall_print_value(unsigned long val){

unsigned long val_ = val;
ocall(OCALL_PRINT_VALUE, &val_, sizeof(unsigned long), 0, 0);

return;
}

unsigned long ocall_print_buffer(char* data, size_t data_len){

unsigned long retval;
ocall(OCALL_PRINT_BUFFER, data, data_len, &retval ,sizeof(unsigned long));

return retval;
}

void ocall_get_string(struct edge_data* retdata){
ocall(OCALL_GET_STRING, NULL, 0, retdata, sizeof(struct edge_data));
return;
}
14 changes: 14 additions & 0 deletions examples/tests/message/edge_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#ifndef _EDGE_WRAPPER_H_
#define _EDGE_WRAPPER_H_
#include "edge/edge_call.h"

void edge_init();

unsigned long ocall_print_buffer(char* data, size_t data_len);
void ocall_print_value(unsigned long val);
void ocall_get_string(struct edge_data* retdata);
#endif /* _EDGE_WRAPPER_H_ */
Loading