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

Commit 24a5ed3

Browse files
authored
[all] Update to v1.0.0 (#67)
Updates: * [all] Change to follow SM v1.0 SBI (OpenSBI) * [all] Fix compilation error for the new toolchain (RV32/RV64) * [CI] moved from TravisCI to CircleCI * [examples] Add return value checking for tests (`--retval` flag in the test runner) * [src/host] Host doesn't need to initialize Untrusted Memory Resolves #48 * [all] Fix formatting * [tests] Replace ValidMeasure test with deterministic measurement test Issues Resolved: #48
1 parent 337f8bd commit 24a5ed3

File tree

32 files changed

+205
-162
lines changed

32 files changed

+205
-162
lines changed

.circleci/config.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference
2+
version: 2.1
3+
4+
# prebuilt docker images with toolchain
5+
executors:
6+
setup-rv64gc:
7+
docker:
8+
- image: keystoneenclaveorg/keystone:init-rv64gc
9+
setup-rv32gc:
10+
docker:
11+
- image: keystoneenclaveorg/keystone:init-rv32gc
12+
13+
14+
commands:
15+
update-riscv-toolchain-path:
16+
steps:
17+
- run: echo 'export PATH=/keystone/riscv64/bin:/keystone/riscv32/bin:$PATH' >> $BASH_ENV
18+
setup-test:
19+
steps:
20+
- run:
21+
command: |
22+
/keystone/sdk/tests/scripts/setup_test.sh
23+
apt -y update
24+
apt -y install python3-pip clang-format
25+
pip3 install cpplint
26+
27+
jobs:
28+
build-install-examples-test-format-64:
29+
executor: setup-rv64gc
30+
working_directory: /keystone/sdk
31+
steps:
32+
- checkout
33+
- update-riscv-toolchain-path
34+
- setup-test
35+
- run:
36+
name: "Build, install, build examples, test, and format check (rv64)"
37+
command: |
38+
mkdir build64
39+
cd build64
40+
export KEYSTONE_SDK_DIR=$(pwd)
41+
cmake ..
42+
make
43+
make install
44+
make examples
45+
make check
46+
make uninstall
47+
make format
48+
build-install-examples-32:
49+
executor: setup-rv32gc
50+
working_directory: /keystone/sdk
51+
steps:
52+
- checkout
53+
- update-riscv-toolchain-path
54+
- run:
55+
name: "Build, install, build examples (rv32)"
56+
command: |
57+
mkdir build32
58+
cd build32
59+
export KEYSTONE_SDK_DIR=$(pwd)
60+
cmake .. -DRISCV32=y
61+
make
62+
make install
63+
make examples
64+
65+
workflows:
66+
build-and-test:
67+
jobs:
68+
- build-install-examples-test-format-64
69+
- build-install-examples-32

.travis.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/hello-native/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ target_include_directories(${host_bin}
3636

3737
set(eyrie_files_to_copy .options_log eyrie-rt)
3838
add_eyrie_runtime(${eapp_bin}-eyrie
39-
"origin/master"
39+
"v1.0.0"
4040
${eyrie_plugins}
4141
${eyrie_files_to_copy})
4242

examples/hello/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE})
2525

2626
set(eyrie_files_to_copy .options_log eyrie-rt)
2727
add_eyrie_runtime(${eapp_bin}-eyrie
28-
"origin/master"
28+
"v1.0.0"
2929
${eyrie_plugins}
3030
${eyrie_files_to_copy})
3131

examples/tests/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/add_long.S
4646
${CMAKE_CURRENT_BINARY_DIR}/add_long.S
4747
${CMAKE_CURRENT_SOURCE_DIR}/long-nop/nop.s
4848
${CMAKE_CURRENT_SOURCE_DIR}/long-nop/func_base.s
49-
${CMAKE_CURRENT_SOURCE_DIR}/long-nop/nop.h
49+
${CMAKE_CURRENT_SOURCE_DIR}/long-nop/nop.h
5050
)
5151
target_link_libraries(long-nop ${KEYSTONE_LIB_EAPP})
5252

@@ -78,7 +78,12 @@ set(test_script ${CMAKE_CURRENT_BINARY_DIR}/run-test.sh)
7878
file(WRITE ${test_script_tmp} "")
7979
foreach (test IN ITEMS ${all_test_bins})
8080
file(APPEND ${test_script_tmp} "echo 'testing ${test}'\n")
81-
file(APPEND ${test_script_tmp} "./${host_bin} ${test} eyrie-rt\n")
81+
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${test}/retval)
82+
execute_process(COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/${test}/retval OUTPUT_VARIABLE retval)
83+
file(APPEND ${test_script_tmp} "./${host_bin} ${test} eyrie-rt --retval ${retval}")
84+
else()
85+
file(APPEND ${test_script_tmp} "./${host_bin} ${test} eyrie-rt\n")
86+
endif()
8287
endforeach(test)
8388

8489
file(COPY ${test_script_tmp} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
@@ -99,7 +104,7 @@ target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE} ${KE
99104

100105
set(eyrie_files_to_copy .options_log eyrie-rt)
101106
add_eyrie_runtime(test-eyrie
102-
"origin/master"
107+
"v1.0.0"
103108
${eyrie_plugins}
104109
${eyrie_files_to_copy})
105110

examples/tests/attestation/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

examples/tests/data-sealing/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

examples/tests/fibonacci/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14930352

examples/tests/long-nop/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12345

examples/tests/loop/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
54321

examples/tests/malloc/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11411

examples/tests/stack/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12345

examples/tests/test-runner.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ main(int argc, char** argv) {
5858
if (argc < 3 || argc > 8) {
5959
printf(
6060
"Usage: %s <eapp> <runtime> [--utm-size SIZE(K)] [--freemem-size "
61-
"SIZE(K)] [--time] [--load-only] [--utm-ptr 0xPTR]\n",
61+
"SIZE(K)] [--time] [--load-only] [--utm-ptr 0xPTR] [--retval EXPECTED]\n",
6262
argv[0]);
6363
return 0;
6464
}
@@ -69,13 +69,16 @@ main(int argc, char** argv) {
6969
size_t untrusted_size = 2 * 1024 * 1024;
7070
size_t freemem_size = 48 * 1024 * 1024;
7171
uintptr_t utm_ptr = (uintptr_t)DEFAULT_UNTRUSTED_PTR;
72+
bool retval_exist = false;
73+
unsigned long retval = 0;
7274

7375
static struct option long_options[] = {
7476
{"time", no_argument, &self_timing, 1},
7577
{"load-only", no_argument, &load_only, 1},
7678
{"utm-size", required_argument, 0, 'u'},
7779
{"utm-ptr", required_argument, 0, 'p'},
7880
{"freemem-size", required_argument, 0, 'f'},
81+
{"retval", required_argument, 0, 'r'},
7982
{0, 0, 0, 0}};
8083

8184
char* eapp_file = argv[1];
@@ -100,6 +103,10 @@ main(int argc, char** argv) {
100103
case 'f':
101104
freemem_size = atoi(optarg) * 1024;
102105
break;
106+
case 'r':
107+
retval_exist = true;
108+
retval = atoi(optarg);
109+
break;
103110
}
104111
}
105112

@@ -126,7 +133,12 @@ main(int argc, char** argv) {
126133
asm volatile("rdcycle %0" : "=r"(cycles3));
127134
}
128135

129-
if (!load_only) enclave.run();
136+
uintptr_t encl_ret;
137+
if (!load_only) enclave.run(&encl_ret);
138+
139+
if (retval_exist && encl_ret != retval) {
140+
printf("[FAIL] enclave returned a wrong value (%d != %d)\r\n", encl_ret, retval);
141+
}
130142

131143
if (self_timing) {
132144
asm volatile("rdcycle %0" : "=r"(cycles4));

examples/tests/untrusted/retval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
13

include/app/syscall.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616
#define SYSCALL_GET_SEALING_KEY 1004
1717
#define SYSCALL_EXIT 1101
1818

19-
#define SYSCALL(which, arg0, arg1, arg2, arg3, arg4) \
20-
({ \
21-
register uintptr_t a0 asm("a0") = (uintptr_t)(arg0); \
22-
register uintptr_t a1 asm("a1") = (uintptr_t)(arg1); \
23-
register uintptr_t a2 asm("a2") = (uintptr_t)(arg2); \
24-
register uintptr_t a3 asm("a3") = (uintptr_t)(arg3); \
25-
register uintptr_t a4 asm("a4") = (uintptr_t)(arg4); \
26-
register uintptr_t a7 asm("a7") = (uintptr_t)(which); \
27-
asm volatile( \
28-
"ecall" \
29-
: "+r"(a0) \
30-
: "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a7) \
31-
: "memory"); \
32-
a0; \
19+
#define SYSCALL(which, arg0, arg1, arg2, arg3, arg4) \
20+
({ \
21+
register uintptr_t a0 asm("a0") = (uintptr_t)(arg0); \
22+
register uintptr_t a1 asm("a1") = (uintptr_t)(arg1); \
23+
register uintptr_t a2 asm("a2") = (uintptr_t)(arg2); \
24+
register uintptr_t a3 asm("a3") = (uintptr_t)(arg3); \
25+
register uintptr_t a4 asm("a4") = (uintptr_t)(arg4); \
26+
register uintptr_t a7 asm("a7") = (uintptr_t)(which); \
27+
asm volatile("ecall" \
28+
: "+r"(a0) \
29+
: "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a7) \
30+
: "memory"); \
31+
a0; \
3332
})
3433

3534
#define SYSCALL_0(which) SYSCALL(which, 0, 0, 0, 0, 0)

include/host/Enclave.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Enclave {
6666
const char* eapppath, const char* runtimepath, Params _params,
6767
uintptr_t alternatePhysAddr);
6868
Error destroy();
69-
Error run();
69+
Error run(uintptr_t* ret = nullptr);
7070
};
7171

7272
uint64_t

include/host/KeystoneDevice.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class KeystoneDevice {
2828

2929
private:
3030
int fd;
31-
Error __run(bool resume);
31+
Error __run(bool resume, uintptr_t* ret);
3232

3333
public:
3434
virtual uintptr_t getPhysAddr() { return physAddr; }
@@ -42,8 +42,8 @@ class KeystoneDevice {
4242
uintptr_t runtimePhysAddr, uintptr_t eappPhysAddr, uintptr_t freePhysAddr,
4343
struct runtime_params_t params);
4444
virtual Error destroy();
45-
virtual Error run();
46-
virtual Error resume();
45+
virtual Error run(uintptr_t* ret);
46+
virtual Error resume(uintptr_t* ret);
4747
virtual void* map(uintptr_t addr, size_t size);
4848
};
4949

@@ -62,8 +62,8 @@ class MockKeystoneDevice : public KeystoneDevice {
6262
uintptr_t runtimePhysAddr, uintptr_t eappPhysAddr, uintptr_t freePhysAddr,
6363
struct runtime_params_t params);
6464
Error destroy();
65-
Error run();
66-
Error resume();
65+
Error run(uintptr_t* ret);
66+
Error resume(uintptr_t* ret);
6767
void* map(uintptr_t addr, size_t size);
6868
};
6969

include/host/Memory.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ namespace Keystone {
2323
/*
2424
* These are used to make use of C type-checking..
2525
*/
26-
typedef struct { uintptr_t pte; } pte;
26+
typedef struct {
27+
uintptr_t pte;
28+
} pte;
2729

2830
#define pte_val(x) ((x).pte)
2931

@@ -70,11 +72,11 @@ class Memory {
7072
Memory();
7173
~Memory() {}
7274
virtual void init(
73-
KeystoneDevice* dev, uintptr_t phys_addr, size_t min_pages) = 0;
74-
virtual uintptr_t readMem(uintptr_t src, size_t size) = 0;
75+
KeystoneDevice* dev, uintptr_t phys_addr, size_t min_pages) = 0;
76+
virtual uintptr_t readMem(uintptr_t src, size_t size) = 0;
7577
virtual void writeMem(uintptr_t src, uintptr_t dst, size_t size) = 0;
76-
virtual uintptr_t allocMem(size_t size) = 0;
77-
virtual uintptr_t allocUtm(size_t size) = 0;
78+
virtual uintptr_t allocMem(size_t size) = 0;
79+
virtual uintptr_t allocUtm(size_t size) = 0;
7880
bool allocPage(uintptr_t eva, uintptr_t src, unsigned int mode);
7981
size_t epmAllocVspace(uintptr_t addr, size_t num_pages);
8082

include/host/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/* Currently we have only one command avaiable from the enclave.
2929
* We need to move it out to other header file (e.g., keystone-sm.h) */
3030
#define KEYSTONE_ENCLAVE_DONE 0
31-
#define KEYSTONE_ENCLAVE_INTERRUPTED 2
32-
#define KEYSTONE_ENCLAVE_EDGE_CALL_HOST 11
31+
#define KEYSTONE_ENCLAVE_INTERRUPTED 100002
32+
#define KEYSTONE_ENCLAVE_EDGE_CALL_HOST 100011
3333

3434
#endif

include/host/keystone_user.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <linux/ioctl.h>
99
#include <linux/types.h>
10-
#include <stdint.h>
1110
// Linux generic TEE subsystem magic defined in <linux/tee.h>
1211
#define KEYSTONE_IOC_MAGIC 0xa4
1312

@@ -25,6 +24,12 @@
2524
#define KEYSTONE_IOC_UTM_INIT \
2625
_IOR(KEYSTONE_IOC_MAGIC, 0x07, struct keystone_ioctl_create_enclave)
2726

27+
#define RT_NOEXEC 0
28+
#define USER_NOEXEC 1
29+
#define RT_FULL 2
30+
#define USER_FULL 3
31+
#define UTM_FULL 4
32+
2833
struct runtime_params_t {
2934
uintptr_t runtime_entry;
3035
uintptr_t user_entry;
@@ -61,24 +66,8 @@ struct keystone_ioctl_create_enclave {
6166

6267
struct keystone_ioctl_run_enclave {
6368
uintptr_t eid;
64-
uintptr_t entry;
65-
uintptr_t args_ptr;
66-
uintptr_t args_size;
67-
uintptr_t ret;
68-
};
69-
70-
struct keystone_hash_enclave {
71-
uintptr_t epm_paddr;
72-
uintptr_t epm_size;
73-
uintptr_t utm_paddr;
74-
uintptr_t utm_size;
75-
76-
uintptr_t runtime_paddr;
77-
uintptr_t user_paddr;
78-
uintptr_t free_paddr;
79-
80-
uintptr_t untrusted_ptr;
81-
uintptr_t untrusted_size;
69+
uintptr_t error;
70+
uintptr_t value;
8271
};
8372

8473
#endif

0 commit comments

Comments
 (0)